Compare commits
175
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73382bb021 | ||
|
|
69e2f6231c | ||
|
|
fb88808c97 | ||
|
|
a16797cc53 | ||
|
|
b14fb6c18b | ||
|
|
8db975b532 | ||
|
|
fcade74753 | ||
|
|
f1d8bc0ffc | ||
|
|
9d8b9330f9 | ||
|
|
3ae040d677 | ||
|
|
07d2d00b0d | ||
|
|
86d0678274 | ||
|
|
bdf6240ed8 | ||
|
|
e8b93e3bb1 | ||
|
|
9a9be92d27 | ||
|
|
414be62d61 | ||
|
|
21017a38a7 | ||
|
|
1a30fb743b | ||
|
|
db8aa21b35 | ||
|
|
c4772e61c5 | ||
|
|
9541d765a9 | ||
|
|
f9717328bc | ||
|
|
1835deb2c9 | ||
|
|
dc6b15a372 | ||
|
|
635bf931c8 | ||
|
|
d12e431b40 | ||
|
|
8f8b2e605b | ||
|
|
9b6fea461c | ||
|
|
a391c83a2f | ||
|
|
06764c3d00 | ||
|
|
b68c49ac2f | ||
|
|
96ace4b850 | ||
|
|
6782b19c3d | ||
|
|
bcadcd1eca | ||
|
|
ef1b10b601 | ||
|
|
aec378bb36 | ||
|
|
fa9bab156a | ||
|
|
de5b32b1b5 | ||
|
|
dd2171172d | ||
|
|
1155ea6b9d | ||
|
|
6918a2436a | ||
|
|
7e524c6b08 | ||
|
|
9c278d131d | ||
|
|
b1c090e28d | ||
|
|
b03e0a7db8 | ||
|
|
33071ff6c1 | ||
|
|
30a9a39248 | ||
|
|
49c9531404 | ||
|
|
c68c7e05fe | ||
|
|
534831e6e5 | ||
|
|
deab868c53 | ||
|
|
d5102a9cf6 | ||
|
|
ac75979453 | ||
|
|
712e346bd2 | ||
|
|
85e34cb335 | ||
|
|
c36c67961f | ||
|
|
025c715ab4 | ||
|
|
af728f12d9 | ||
|
|
1f1848a408 | ||
|
|
d032c842d5 | ||
|
|
d6f5199acd | ||
|
|
28aad86e4a | ||
|
|
c5c634e477 | ||
|
|
a8c339e5b4 | ||
|
|
fd916d9eae | ||
|
|
2d45f059ec | ||
|
|
e5850035dd | ||
|
|
0cfc8e230c | ||
|
|
f3a1fbdd53 | ||
|
|
ecbd404da0 | ||
|
|
2768cdd312 | ||
|
|
564595cfc3 | ||
|
|
3a3377d0e5 | ||
|
|
38861421f8 | ||
|
|
a7bb3cf336 | ||
|
|
8fa28d3d65 | ||
|
|
f8a231286a | ||
|
|
ea5b70e8fc | ||
|
|
26b0c7356d | ||
|
|
7558397877 | ||
|
|
fb7d045753 | ||
|
|
4d17553a23 | ||
|
|
40633c949e | ||
|
|
a17fa3ad5f | ||
|
|
560858ba0a | ||
|
|
ada0ce0484 | ||
|
|
461ae6a16b | ||
|
|
31456e7bae | ||
|
|
060970b7c0 | ||
|
|
0f894aaecc | ||
|
|
8367901104 | ||
|
|
7e445e0cf8 | ||
|
|
f5de4e96c3 | ||
|
|
6226c2690d | ||
|
|
3335233566 | ||
|
|
faac895509 | ||
|
|
bc9886b3e8 | ||
|
|
963177cd4c | ||
|
|
6d2f69a36f | ||
|
|
b444d284c6 | ||
|
|
f853f2a00b | ||
|
|
a8afd1621e | ||
|
|
88aad289cf | ||
|
|
de1476becf | ||
|
|
6ae869bdb3 | ||
|
|
818b00190d | ||
|
|
630260d0b1 | ||
|
|
15a137c502 | ||
|
|
438be5767a | ||
|
|
6c7f59bfb8 | ||
|
|
7220ec8943 | ||
|
|
3615ab5e55 | ||
|
|
7ba00dffcc | ||
|
|
76b73ef0c7 | ||
|
|
5424746066 | ||
|
|
b6b411847a | ||
|
|
6bda111ffa | ||
|
|
77ea5aa522 | ||
|
|
abb34bf2dc | ||
|
|
c3aeba7e17 | ||
|
|
8e52397bb4 | ||
|
|
ebc3b6a55d | ||
|
|
7b0a5ae028 | ||
|
|
13ef7571b2 | ||
|
|
b63ee94973 | ||
|
|
2ae66ad3f7 | ||
|
|
52702e2226 | ||
|
|
f827da4c61 | ||
|
|
3d2986a85c | ||
|
|
1d3e6c524b | ||
|
|
5f847fb035 | ||
|
|
6f0d34f863 | ||
|
|
41b4a3684a | ||
|
|
38d493fdd1 | ||
|
|
d33ac919d1 | ||
|
|
ec0eec8ac4 | ||
|
|
2437a06505 | ||
|
|
e90b6dfcc7 | ||
|
|
c0a12af3ae | ||
|
|
d701bab7f6 | ||
|
|
c54836bca0 | ||
|
|
322c658307 | ||
|
|
16f251b7f3 | ||
|
|
ce30f66823 | ||
|
|
3d72de1cec | ||
|
|
bad2d869f5 | ||
|
|
846f1afaab | ||
|
|
414540ec6d | ||
|
|
9159c7602d | ||
|
|
211c2884c2 | ||
|
|
74be347b9e | ||
|
|
50996a6b0d | ||
|
|
e29b47a047 | ||
|
|
38325c6d44 | ||
|
|
c84b36d76d | ||
|
|
95c75ed957 | ||
|
|
ccd1b2b84d | ||
|
|
dac2dbda61 | ||
|
|
2e58228e91 | ||
|
|
185433f2fd | ||
|
|
40f9c3f961 | ||
|
|
dd814b834b | ||
|
|
cdaf3ac682 | ||
|
|
6d169425d1 | ||
|
|
f53da5c3e5 | ||
|
|
d89334f9eb | ||
|
|
2fcc2f106e | ||
|
|
4cff2dd233 | ||
|
|
37a8c4cae1 | ||
|
|
8aaa786512 | ||
|
|
1f23a260ae | ||
|
|
e02762ab6c | ||
|
|
9a629bb545 | ||
|
|
c62c175d8b | ||
|
|
eb8f72f0d8 |
No files matched your search
+15
-4
@@ -5,14 +5,25 @@ go:
|
||||
- 1.11.x
|
||||
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
|
||||
global:
|
||||
- GO111MODULE=on
|
||||
#GITHUB_TOKEN
|
||||
- secure: "P4YMfllsq/guf5swmBl80IHGvNfUM+5X2b+0LvQQxGJpY9TD6d+PW6U1C90HIT0CDk6UZbtlHyGN+oo+shsWnwMIaM4qmbGdRgtG4TZolXY1QtYQZFW9fTWeHM0wnJeXLV8V4vpTRHnkLrvT8PctbGp5pVOEtcV4y3sEnMP1rkxnMPeHtrDbTlpBmBYEziByEpbg3pe3CE9xVaDD9DqgW7VOOZnQQl7exTtjsIeJYI7OYvdidf/04p632/8WZP2EJbmA2HunfTydWtcD51lCF8V3IvhKKqH4/7sNOKfmUwTDyhLltk9eDcFsYR/FYsy8njH4QDBBrKo/bPq3jzgKF9BY7g28/jMTDY4vDY0Na+4a3+7sDqwdsZ+eiZrgWYUbZ4MwYtpUtcvp8gUz7Avs3v7BBgYsYpgLEW47bT6uNLGO+SdfSwBCYuxT5P0IGCv6wkgYcYgfqVafk+9FiwJlayP2j3wPOdauiYh4WnYX1Rt0zNvaiP5iBhkXwIv3VvUcI1Yu9k0eLDibzZlpR8fkGw3USl+omdjCvXDfJQW1ghMONTm0d7VPG84P/MRhJ+thoh1UwMaT3S0sdPznRnNL6XDntCRT1CZW4l0jfyCPDBW2qw8dWunULYsQZTPWnv4s+BuRRDsfGjyamH5b8evh0TOF+XNOFewmNvflWBNG2y0="
|
||||
install: true
|
||||
|
||||
script:
|
||||
# Fail if a .go file hasn't been formatted with gofmt
|
||||
- test -z $(gofmt -s -l $(find . -iname '*.go' -type f | grep -v /vendor/ ))
|
||||
- test -z $(gofmt -s -l $(find . -iname '*.go' -type f))
|
||||
- make
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
email: false
|
||||
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script: ./scripts/deploy.sh
|
||||
file: bin/lbry
|
||||
on:
|
||||
repo: lbryio/lbry.go
|
||||
tags: true
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2018 LBRY Inc
|
||||
Copyright (c) 2016-2020 LBRY Inc
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package claim
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
types "github.com/lbryio/types/v1/go"
|
||||
types "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/lyoshenka/bencode"
|
||||
)
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package bits
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/lbryio/errors.go"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
)
|
||||
|
||||
// Range has a start and end
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
)
|
||||
|
||||
func TestBootstrapPing(t *testing.T) {
|
||||
|
||||
+5
-4
@@ -4,7 +4,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -65,9 +65,10 @@ func NewStandardConfig() *Config {
|
||||
return &Config{
|
||||
Address: "0.0.0.0:" + strconv.Itoa(DefaultPort),
|
||||
SeedNodes: []string{
|
||||
"lbrynet1.lbry.io:4444",
|
||||
"lbrynet2.lbry.io:4444",
|
||||
"lbrynet3.lbry.io:4444",
|
||||
"lbrynet1.lbry.com:4444",
|
||||
"lbrynet2.lbry.com:4444",
|
||||
"lbrynet3.lbry.com:4444",
|
||||
"lbrynet4.lbry.com:4444",
|
||||
},
|
||||
PeerProtocolPort: DefaultPeerPort,
|
||||
ReannounceTime: DefaultReannounceTime,
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/lyoshenka/bencode"
|
||||
)
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
)
|
||||
|
||||
func TestCompactEncoding(t *testing.T) {
|
||||
|
||||
+3
-3
@@ -6,9 +6,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
)
|
||||
|
||||
func TestNodeFinder_FindNodes(t *testing.T) {
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/lyoshenka/bencode"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lyoshenka/bencode"
|
||||
|
||||
+4
-4
@@ -7,10 +7,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/extras/util"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v2/extras/util"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lyoshenka/bencode"
|
||||
|
||||
+5
-5
@@ -4,13 +4,13 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/crypto"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/crypto"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/uber-go/atomic"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
// TODO: iterativeFindValue may be stopping early. if it gets a response with one peer, it should keep going because other nodes may know about more peers that have that blob
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lyoshenka/bencode"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
)
|
||||
|
||||
// TODO: if routing table is ever empty (aka the node is isolated), it should re-bootstrap
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
|
||||
"github.com/sebdah/goldie"
|
||||
)
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
rpc2 "github.com/gorilla/rpc/v2"
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package dht
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
)
|
||||
|
||||
// TODO: expire stored data after tExpire time
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
)
|
||||
|
||||
var testingDHTIP = "127.0.0.1"
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
)
|
||||
|
||||
// TODO: this should be moved out of dht and into node, and it should be completely hidden inside node. dht should not need to know about tokens
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v2/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v2/extras/stop"
|
||||
)
|
||||
|
||||
type tokenManager struct {
|
||||
|
||||
+54
-29
@@ -6,9 +6,9 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/util"
|
||||
"github.com/lbryio/lbry.go/extras/validator"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/util"
|
||||
"github.com/lbryio/lbry.go/v2/extras/validator"
|
||||
v "github.com/lbryio/ozzo-validation"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
@@ -20,6 +20,19 @@ var ResponseHeaders map[string]string
|
||||
// Log allows logging of events and errors
|
||||
var Log = func(*http.Request, *Response, error) {}
|
||||
|
||||
// http://choly.ca/post/go-json-marshalling/
|
||||
type ResponseInfo struct {
|
||||
Success bool `json:"success"`
|
||||
Error *string `json:"error"`
|
||||
Data interface{} `json:"data"`
|
||||
Trace []string `json:"_trace,omitempty"`
|
||||
}
|
||||
|
||||
// BuildJSONResponse allows implementers to control the json response form from the api
|
||||
var BuildJSONResponse = func(response ResponseInfo) ([]byte, error) {
|
||||
return json.MarshalIndent(&response, "", " ")
|
||||
}
|
||||
|
||||
// TraceEnabled Attaches a trace field to the JSON response when enabled.
|
||||
var TraceEnabled = false
|
||||
|
||||
@@ -113,32 +126,40 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var trace []string
|
||||
if TraceEnabled && errors.HasTrace(rsp.Error) {
|
||||
trace = strings.Split(errors.Trace(rsp.Error), "\n")
|
||||
for index, element := range trace {
|
||||
if strings.HasPrefix(element, "\t") {
|
||||
trace[index] = strings.Replace(element, "\t", " ", 1)
|
||||
}
|
||||
}
|
||||
trace = getTraceFromError(rsp.Error)
|
||||
}
|
||||
|
||||
// http://choly.ca/post/go-json-marshalling/
|
||||
jsonResponse, err := json.MarshalIndent(&struct {
|
||||
Success bool `json:"success"`
|
||||
Error *string `json:"error"`
|
||||
Data interface{} `json:"data"`
|
||||
Trace []string `json:"_trace,omitempty"`
|
||||
}{
|
||||
jsonResponse, err := BuildJSONResponse(ResponseInfo{
|
||||
Success: success,
|
||||
Error: errorString,
|
||||
Data: rsp.Data,
|
||||
Trace: trace,
|
||||
}, "", " ")
|
||||
})
|
||||
if err != nil {
|
||||
Log(r, &rsp, errors.Prefix("Error encoding JSON response: ", err))
|
||||
jsonResponse, err = BuildJSONResponse(ResponseInfo{
|
||||
Success: false,
|
||||
Error: util.PtrToString(err.Error()),
|
||||
Data: nil,
|
||||
Trace: getTraceFromError(err),
|
||||
})
|
||||
if err != nil {
|
||||
Log(r, &rsp, errors.Prefix("Error encoding JSON response: ", err))
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteHeader(rsp.Status)
|
||||
w.Write(jsonResponse)
|
||||
_, _ = w.Write(jsonResponse)
|
||||
}
|
||||
|
||||
func getTraceFromError(err error) []string {
|
||||
trace := strings.Split(errors.Trace(err), "\n")
|
||||
for index, element := range trace {
|
||||
if strings.HasPrefix(element, "\t") {
|
||||
trace[index] = strings.Replace(element, "\t", " ", 1)
|
||||
}
|
||||
}
|
||||
return trace
|
||||
}
|
||||
|
||||
// IgnoredFormFields are ignored by FormValues() when checking for extraneous fields
|
||||
@@ -154,21 +175,25 @@ func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldR
|
||||
structValue := ref.Elem()
|
||||
fields := map[string]bool{}
|
||||
for i := 0; i < structType.NumField(); i++ {
|
||||
name := structType.Field(i).Name
|
||||
underscoredName := util.Underscore(name)
|
||||
value := strings.TrimSpace(r.FormValue(underscoredName))
|
||||
fieldName := structType.Field(i).Name
|
||||
formattedName := util.Underscore(fieldName)
|
||||
jsonName, ok := structType.Field(i).Tag.Lookup("json")
|
||||
if ok {
|
||||
formattedName = jsonName
|
||||
}
|
||||
value := strings.TrimSpace(r.FormValue(formattedName))
|
||||
|
||||
// if param is not set at all, continue
|
||||
// comes after call to r.FormValue so form values get parsed internally (if they arent already)
|
||||
if len(r.Form[underscoredName]) == 0 {
|
||||
if len(r.Form[formattedName]) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
fields[underscoredName] = true
|
||||
fields[formattedName] = true
|
||||
isPtr := false
|
||||
var finalValue reflect.Value
|
||||
|
||||
structField := structValue.FieldByName(name)
|
||||
structField := structValue.FieldByName(fieldName)
|
||||
structFieldKind := structField.Kind()
|
||||
if structFieldKind == reflect.Ptr {
|
||||
isPtr = true
|
||||
@@ -184,7 +209,7 @@ func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldR
|
||||
}
|
||||
castVal, err := cast.ToInt64E(value)
|
||||
if err != nil {
|
||||
return errors.Err("%s: must be an integer", underscoredName)
|
||||
return errors.Err("%s: must be an integer", formattedName)
|
||||
}
|
||||
switch structFieldKind {
|
||||
case reflect.Int:
|
||||
@@ -204,7 +229,7 @@ func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldR
|
||||
}
|
||||
castVal, err := cast.ToUint64E(value)
|
||||
if err != nil {
|
||||
return errors.Err("%s: must be an unsigned integer", underscoredName)
|
||||
return errors.Err("%s: must be an unsigned integer", formattedName)
|
||||
}
|
||||
switch structFieldKind {
|
||||
case reflect.Uint:
|
||||
@@ -224,7 +249,7 @@ func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldR
|
||||
}
|
||||
if !validator.IsBoolString(value) {
|
||||
return errors.Err("%s: must be one of the following values: %s",
|
||||
underscoredName, strings.Join(validator.GetBoolStringValues(), ", "))
|
||||
formattedName, strings.Join(validator.GetBoolStringValues(), ", "))
|
||||
}
|
||||
finalValue = reflect.ValueOf(validator.IsTruthy(value))
|
||||
|
||||
@@ -234,7 +259,7 @@ func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldR
|
||||
}
|
||||
castVal, err := cast.ToFloat64E(value)
|
||||
if err != nil {
|
||||
return errors.Err("%s: must be a floating point number", underscoredName)
|
||||
return errors.Err("%s: must be a floating point number", formattedName)
|
||||
}
|
||||
switch structFieldKind {
|
||||
case reflect.Float32:
|
||||
@@ -243,7 +268,7 @@ func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldR
|
||||
finalValue = reflect.ValueOf(float64(castVal))
|
||||
}
|
||||
default:
|
||||
return errors.Err("field %s is an unsupported type", name)
|
||||
return errors.Err("field %s is an unsupported type", fieldName)
|
||||
}
|
||||
|
||||
if isPtr {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
+537
-303
@@ -10,8 +10,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/shopspring/decimal"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -41,7 +41,7 @@ func NewClient(address string) *Client {
|
||||
func NewClientAndWait(address string) *Client {
|
||||
d := NewClient(address)
|
||||
for {
|
||||
_, err := d.WalletBalance()
|
||||
_, err := d.AccountBalance(nil)
|
||||
if err == nil {
|
||||
return d
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func NewClientAndWait(address string) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
func decode(data interface{}, targetStruct interface{}) error {
|
||||
func Decode(data interface{}, targetStruct interface{}) error {
|
||||
config := &mapstructure.DecoderConfig{
|
||||
Metadata: nil,
|
||||
Result: targetStruct,
|
||||
@@ -125,7 +125,7 @@ func (d *Client) call(response interface{}, command string, params map[string]in
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return decode(result, response)
|
||||
return Decode(result, response)
|
||||
}
|
||||
|
||||
func (d *Client) SetRPCTimeout(timeout time.Duration) {
|
||||
@@ -134,9 +134,338 @@ func (d *Client) SetRPCTimeout(timeout time.Duration) {
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) Commands() (*CommandsResponse, error) {
|
||||
response := new(CommandsResponse)
|
||||
return response, d.call(response, "commands", map[string]interface{}{})
|
||||
//============================================
|
||||
// NEW SDK
|
||||
//============================================
|
||||
|
||||
func (d *Client) AccountList(page uint64, pageSize uint64) (*AccountListResponse, error) {
|
||||
response := new(AccountListResponse)
|
||||
return response, d.call(response, "account_list", map[string]interface{}{
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) AccountListForWallet(walletID string) (*AccountListResponse, error) {
|
||||
response := new(AccountListResponse)
|
||||
return response, d.call(response, "account_list", map[string]interface{}{"wallet_id": walletID})
|
||||
}
|
||||
|
||||
func (d *Client) SingleAccountList(accountID string) (*AccountListResponse, error) {
|
||||
response := new(AccountListResponse)
|
||||
return response, d.call(response, "account_list", map[string]interface{}{"account_id": accountID})
|
||||
}
|
||||
|
||||
type AccountSettings struct {
|
||||
Default *bool `json:"default,omitempty"`
|
||||
NewName *string `json:"new_name,omitempty"`
|
||||
ReceivingGap *int `json:"receiving_gap,omitempty"`
|
||||
ReceivingMaxUses *int `json:"receiving_max_uses,omitempty"`
|
||||
ChangeGap *int `json:"change_gap,omitempty"`
|
||||
ChangeMaxUses *int `json:"change_max_uses,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Client) AccountSet(accountID string, settings AccountSettings) (*Account, error) {
|
||||
response := new(Account)
|
||||
args := struct {
|
||||
AccountID string `json:"account_id"`
|
||||
AccountSettings `json:",flatten"`
|
||||
}{
|
||||
AccountID: accountID,
|
||||
AccountSettings: settings,
|
||||
}
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "account_set", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) AccountBalance(account *string) (*AccountBalanceResponse, error) {
|
||||
response := new(AccountBalanceResponse)
|
||||
return response, d.call(response, "account_balance", map[string]interface{}{
|
||||
"account_id": account,
|
||||
})
|
||||
}
|
||||
|
||||
// funds an account. If everything is true then amount is ignored
|
||||
func (d *Client) AccountFund(fromAccount string, toAccount string, amount string, outputs uint64, everything bool) (*AccountFundResponse, error) {
|
||||
response := new(AccountFundResponse)
|
||||
return response, d.call(response, "account_fund", map[string]interface{}{
|
||||
"from_account": fromAccount,
|
||||
"to_account": toAccount,
|
||||
"amount": amount,
|
||||
"outputs": outputs,
|
||||
"everything": everything,
|
||||
"broadcast": true,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) AccountCreate(accountName string, singleKey bool) (*Account, error) {
|
||||
response := new(Account)
|
||||
return response, d.call(response, "account_create", map[string]interface{}{
|
||||
"account_name": accountName,
|
||||
"single_key": singleKey,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) AccountRemove(accountID string) (*Account, error) {
|
||||
response := new(Account)
|
||||
return response, d.call(response, "account_remove", map[string]interface{}{
|
||||
"account_id": accountID,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) AddressUnused(account *string) (*AddressUnusedResponse, error) {
|
||||
response := new(AddressUnusedResponse)
|
||||
return response, d.call(response, "address_unused", map[string]interface{}{
|
||||
"account_id": account,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ChannelList(account *string, page uint64, pageSize uint64, wid *string) (*ChannelListResponse, error) {
|
||||
if page == 0 {
|
||||
return nil, errors.Err("pages start from 1")
|
||||
}
|
||||
response := new(ChannelListResponse)
|
||||
return response, d.call(response, "channel_list", map[string]interface{}{
|
||||
"account_id": account,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
"include_protobuf": true,
|
||||
"wallet_id": wid,
|
||||
})
|
||||
}
|
||||
|
||||
type streamType string
|
||||
|
||||
var (
|
||||
StreamTypeVideo = streamType("video")
|
||||
StreamTypeAudio = streamType("audio")
|
||||
StreamTypeImage = streamType("image")
|
||||
)
|
||||
|
||||
type Location struct {
|
||||
Country *string `json:"country,omitempty"`
|
||||
State *string `json:"state,omitempty"`
|
||||
City *string `json:"city,omitempty"`
|
||||
PostalCode *string `json:"code,omitempty"`
|
||||
Latitude *string `json:"latitude,omitempty"`
|
||||
Longitude *string `json:"longitude,omitempty"`
|
||||
}
|
||||
type ClaimCreateOptions struct {
|
||||
Title *string `json:"title,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Languages []string `json:"languages,omitempty"`
|
||||
Locations []Location `json:"locations,omitempty"`
|
||||
ThumbnailURL *string `json:"thumbnail_url,omitempty"`
|
||||
AccountID *string `json:"account_id,omitempty"`
|
||||
ClaimAddress *string `json:"claim_address,omitempty"`
|
||||
Preview *bool `json:"preview,omitempty"`
|
||||
FundingAccountIDs []string `json:"funding_account_ids,omitempty"`
|
||||
}
|
||||
|
||||
type ChannelCreateOptions struct {
|
||||
ClaimCreateOptions `json:",flatten"`
|
||||
Email *string `json:"email,omitempty"`
|
||||
WebsiteURL *string `json:"website_url,omitempty"`
|
||||
CoverURL *string `json:"cover_url,omitempty"`
|
||||
Featured []string `json:"featured,omitempty"`
|
||||
AccountID *string `json:"account_id,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Client) ChannelCreate(name string, bid float64, options ChannelCreateOptions) (*TransactionSummary, error) {
|
||||
response := new(TransactionSummary)
|
||||
args := struct {
|
||||
Name string `json:"name"`
|
||||
Bid string `json:"bid"`
|
||||
FilePath string `json:"file_path,omitempty"`
|
||||
IncludeProtoBuf bool `json:"include_protobuf"`
|
||||
ChannelCreateOptions `json:",flatten"`
|
||||
Blocking bool `json:"blocking"`
|
||||
}{
|
||||
Name: name,
|
||||
Bid: fmt.Sprintf("%.6f", bid),
|
||||
IncludeProtoBuf: true,
|
||||
ChannelCreateOptions: options,
|
||||
Blocking: true,
|
||||
}
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "channel_create", structs.Map(args))
|
||||
}
|
||||
|
||||
type ChannelUpdateOptions struct {
|
||||
ChannelCreateOptions `json:",flatten"`
|
||||
NewSigningKey *bool `json:"new_signing_key,omitempty"`
|
||||
ClearFeatured *bool `json:"clear_featured,omitempty"`
|
||||
ClearTags *bool `json:"clear_tags,omitempty"`
|
||||
ClearLanguages *bool `json:"clear_languages,omitempty"`
|
||||
ClearLocations *bool `json:"clear_locations,omitempty"`
|
||||
Bid *string `json:"bid,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Client) ChannelUpdate(claimID string, options ChannelUpdateOptions) (*TransactionSummary, error) {
|
||||
response := new(TransactionSummary)
|
||||
args := struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
IncludeProtoBuf bool `json:"include_protobuf"`
|
||||
*ChannelUpdateOptions `json:",flatten"`
|
||||
Blocking bool `json:"blocking"`
|
||||
}{
|
||||
ClaimID: claimID,
|
||||
IncludeProtoBuf: true,
|
||||
ChannelUpdateOptions: &options,
|
||||
Blocking: true,
|
||||
}
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "channel_update", structs.Map(args))
|
||||
}
|
||||
|
||||
type StreamCreateOptions struct {
|
||||
ClaimCreateOptions `json:",flatten"`
|
||||
Fee *Fee `json:",omitempty,flatten"`
|
||||
Author *string `json:"author,omitempty"`
|
||||
License *string `json:"license,omitempty"`
|
||||
LicenseURL *string `json:"license_url,omitempty"`
|
||||
StreamType *streamType `json:"stream_type,omitempty"`
|
||||
ReleaseTime *int64 `json:"release_time,omitempty"`
|
||||
Duration *uint64 `json:"duration,omitempty"`
|
||||
Width *uint `json:"width,omitempty"`
|
||||
Height *uint `json:"height,omitempty"`
|
||||
Preview *string `json:"preview,omitempty"`
|
||||
AllowDuplicateName *bool `json:"allow_duplicate_name,omitempty"`
|
||||
ChannelName *string `json:"channel_name,omitempty"`
|
||||
ChannelID *string `json:"channel_id,omitempty"`
|
||||
ChannelAccountID *string `json:"channel_account_id,omitempty"`
|
||||
AccountID *string `json:"account_id,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Client) StreamCreate(name, filePath string, bid float64, options StreamCreateOptions) (*TransactionSummary, error) {
|
||||
response := new(TransactionSummary)
|
||||
args := struct {
|
||||
Name string `json:"name"`
|
||||
Bid string `json:"bid"`
|
||||
FilePath string `json:"file_path,omitempty"`
|
||||
FileSize *string `json:"file_size,omitempty"`
|
||||
IncludeProtoBuf bool `json:"include_protobuf"`
|
||||
Blocking bool `json:"blocking"`
|
||||
*StreamCreateOptions `json:",flatten"`
|
||||
}{
|
||||
Name: name,
|
||||
FilePath: filePath,
|
||||
Bid: fmt.Sprintf("%.6f", bid),
|
||||
IncludeProtoBuf: true,
|
||||
Blocking: true,
|
||||
StreamCreateOptions: &options,
|
||||
}
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "stream_create", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) StreamAbandon(txID string, nOut uint64, accountID *string, blocking bool) (*ClaimAbandonResponse, error) {
|
||||
response := new(ClaimAbandonResponse)
|
||||
err := d.call(response, "stream_abandon", map[string]interface{}{
|
||||
"txid": txID,
|
||||
"nout": nOut,
|
||||
"account_id": accountID,
|
||||
"include_protobuf": true,
|
||||
"blocking": true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
type StreamUpdateOptions struct {
|
||||
ClearTags *bool `json:"clear_tags,omitempty"`
|
||||
ClearLanguages *bool `json:"clear_languages,omitempty"`
|
||||
ClearLocations *bool `json:"clear_locations,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
FilePath *string `json:"file_path,omitempty"`
|
||||
FileSize *uint64 `json:"file_size,omitempty"`
|
||||
Bid *string `json:"bid,omitempty"`
|
||||
*StreamCreateOptions `json:",flatten"`
|
||||
}
|
||||
|
||||
func (d *Client) StreamUpdate(claimID string, options StreamUpdateOptions) (*TransactionSummary, error) {
|
||||
response := new(TransactionSummary)
|
||||
args := struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
IncludeProtoBuf bool `json:"include_protobuf"`
|
||||
*StreamUpdateOptions `json:",flatten"`
|
||||
Blocking bool `json:"blocking"`
|
||||
}{
|
||||
ClaimID: claimID,
|
||||
IncludeProtoBuf: true,
|
||||
StreamUpdateOptions: &options,
|
||||
Blocking: true,
|
||||
}
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "stream_update", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) ChannelAbandon(txID string, nOut uint64, accountID *string, blocking bool) (*TransactionSummary, error) {
|
||||
response := new(TransactionSummary)
|
||||
err := d.call(response, "channel_abandon", map[string]interface{}{
|
||||
"txid": txID,
|
||||
"nout": nOut,
|
||||
"account_id": accountID,
|
||||
"include_protobuf": true,
|
||||
"blocking": true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (d *Client) AddressList(account *string, address *string, page uint64, pageSize uint64) (*AddressListResponse, error) {
|
||||
response := new(AddressListResponse)
|
||||
|
||||
args := struct {
|
||||
AccountID *string `json:"account_id,omitempty"`
|
||||
Address *string `json:"address,omitempty"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
}{
|
||||
AccountID: account,
|
||||
Address: address,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
}
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "address_list", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) StreamList(account *string, page uint64, pageSize uint64) (*StreamListResponse, error) {
|
||||
response := new(StreamListResponse)
|
||||
err := d.call(response, "stream_list", map[string]interface{}{
|
||||
"account_id": account,
|
||||
"include_protobuf": true,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (d *Client) ClaimList(account *string, page uint64, pageSize uint64) (*ClaimListResponse, error) {
|
||||
if page == 0 {
|
||||
return nil, errors.Err("pages start from 1")
|
||||
}
|
||||
response := new(ClaimListResponse)
|
||||
err := d.call(response, "claim_list", map[string]interface{}{
|
||||
"account_id": account,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
"include_protobuf": true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (d *Client) Status() (*StatusResponse, error) {
|
||||
@@ -144,29 +473,47 @@ func (d *Client) Status() (*StatusResponse, error) {
|
||||
return response, d.call(response, "status", map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (d *Client) WalletBalance() (*WalletBalanceResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("wallet_balance", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dec, err := decodeNumber(rawResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := WalletBalanceResponse(dec)
|
||||
return &response, nil
|
||||
func (d *Client) TransactionList(account *string, wallet *string, page uint64, pageSize uint64) (*TransactionListResponse, error) {
|
||||
response := new(TransactionListResponse)
|
||||
return response, d.call(response, "transaction_list", map[string]interface{}{
|
||||
"account_id": account,
|
||||
"wallet_id": wallet,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) WalletList() (*WalletListResponse, error) {
|
||||
response := new(WalletListResponse)
|
||||
return response, d.call(response, "wallet_list", map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (d *Client) UTXOList() (*UTXOListResponse, error) {
|
||||
func (d *Client) UTXOList(account *string, page uint64, pageSize uint64) (*UTXOListResponse, error) {
|
||||
response := new(UTXOListResponse)
|
||||
return response, d.call(response, "utxo_list", map[string]interface{}{})
|
||||
return response, d.call(response, "utxo_list", map[string]interface{}{
|
||||
"account_id": account,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) UTXORelease(account *string) (*UTXOReleaseResponse, error) {
|
||||
response := new(UTXOReleaseResponse)
|
||||
return response, d.call(response, "utxo_release", map[string]interface{}{
|
||||
"account_id": account,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) Get(uri string) (*GetResponse, error) {
|
||||
response := new(GetResponse)
|
||||
return response, d.call(response, "get", map[string]interface{}{
|
||||
"uri": uri,
|
||||
"include_protobuf": true,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) FileList(page uint64, pageSize uint64) (*FileListResponse, error) {
|
||||
response := new(FileListResponse)
|
||||
return response, d.call(response, "file_list", map[string]interface{}{
|
||||
"include_protobuf": true,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) Version() (*VersionResponse, error) {
|
||||
@@ -174,312 +521,199 @@ func (d *Client) Version() (*VersionResponse, error) {
|
||||
return response, d.call(response, "version", map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (d *Client) Get(url string, filename *string, timeout *uint) (*GetResponse, error) {
|
||||
response := new(GetResponse)
|
||||
return response, d.call(response, "get", map[string]interface{}{
|
||||
"uri": url,
|
||||
"file_name": filename,
|
||||
"timeout": timeout,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ClaimList(name string) (*ClaimListResponse, error) {
|
||||
response := new(ClaimListResponse)
|
||||
return response, d.call(response, "claim_list", map[string]interface{}{
|
||||
"name": name,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ClaimShow(claimID *string, txid *string, nout *uint) (*ClaimShowResponse, error) {
|
||||
response := new(ClaimShowResponse)
|
||||
return response, d.call(response, "claim_show", map[string]interface{}{
|
||||
"claim_id": claimID,
|
||||
"txid": txid,
|
||||
"nout": nout,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) PeerList(blobHash string, timeout *uint) (*PeerListResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("peer_list", map[string]interface{}{
|
||||
"blob_hash": blobHash,
|
||||
"timeout": timeout,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
castResponse, ok := rawResponse.([]interface{})
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid peer_list response")
|
||||
}
|
||||
|
||||
peers := []PeerListResponsePeer{}
|
||||
for _, peer := range castResponse {
|
||||
t, ok := peer.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid peer_list response")
|
||||
}
|
||||
|
||||
if len(t) != 3 {
|
||||
return nil, errors.Err("invalid triplet in peer_list response")
|
||||
}
|
||||
|
||||
ip, ok := t["host"].(string)
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid ip in peer_list response")
|
||||
}
|
||||
port, ok := t["port"].(json.Number)
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid port in peer_list response")
|
||||
}
|
||||
nodeid, ok := t["node_id"].(string)
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid nodeid in peer_list response")
|
||||
}
|
||||
|
||||
portNum, err := port.Int64()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, 0)
|
||||
} else if portNum < 0 {
|
||||
return nil, errors.Err("invalid port in peer_list response")
|
||||
}
|
||||
|
||||
peers = append(peers, PeerListResponsePeer{
|
||||
IP: ip,
|
||||
Port: uint(portNum),
|
||||
NodeId: nodeid,
|
||||
})
|
||||
}
|
||||
|
||||
response := PeerListResponse(peers)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (d *Client) BlobGet(blobHash string, encoding *string, timeout *uint) (*BlobGetResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("blob_get", map[string]interface{}{
|
||||
"blob_hash": blobHash,
|
||||
"timeout": timeout,
|
||||
"encoding": encoding,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, ok := rawResponse.(string); ok {
|
||||
return nil, nil // blob was downloaded, nothing to return
|
||||
}
|
||||
|
||||
response := new(BlobGetResponse)
|
||||
return response, decode(rawResponse, response)
|
||||
}
|
||||
|
||||
func (d *Client) StreamAvailability(url string, search_timeout *uint64, blob_timeout *uint64) (*StreamAvailabilityResponse, error) {
|
||||
response := new(StreamAvailabilityResponse)
|
||||
return response, d.call(response, "stream_availability", map[string]interface{}{
|
||||
"uri": url,
|
||||
"search_timeout": search_timeout,
|
||||
"blob_timeout": blob_timeout,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) StreamCostEstimate(url string, size *uint64) (*StreamCostEstimateResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("stream_cost_estimate", map[string]interface{}{
|
||||
"uri": url,
|
||||
"size": size,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dec, err := decodeNumber(rawResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := StreamCostEstimateResponse(dec)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
type FileListOptions struct {
|
||||
SDHash *string
|
||||
StreamHash *string
|
||||
FileName *string
|
||||
ClaimID *string
|
||||
Outpoint *string
|
||||
RowID *string
|
||||
Name *string
|
||||
}
|
||||
|
||||
func (d *Client) FileList(options FileListOptions) (*FileListResponse, error) {
|
||||
response := new(FileListResponse)
|
||||
return response, d.call(response, "file_list", map[string]interface{}{
|
||||
"sd_hash": options.SDHash,
|
||||
"stream_hash": options.StreamHash,
|
||||
"file_name": options.FileName,
|
||||
"claim_id": options.ClaimID,
|
||||
"outpoint": options.Outpoint,
|
||||
"rowid": options.RowID,
|
||||
"name": options.Name,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) Resolve(url string) (*ResolveResponse, error) {
|
||||
func (d *Client) Resolve(urls string) (*ResolveResponse, error) {
|
||||
response := new(ResolveResponse)
|
||||
return response, d.call(response, "resolve", map[string]interface{}{
|
||||
"uri": url,
|
||||
"urls": urls,
|
||||
"include_protobuf": true,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ChannelNew(name string, amount float64) (*ChannelNewResponse, error) {
|
||||
response := new(ChannelNewResponse)
|
||||
return response, d.call(response, "channel_new", map[string]interface{}{
|
||||
"channel_name": name,
|
||||
"amount": amount,
|
||||
func (d *Client) ClaimSearch(claimName, claimID, txid *string, nout *uint, page uint64, pageSize uint64) (*ClaimSearchResponse, error) {
|
||||
response := new(ClaimSearchResponse)
|
||||
args := struct {
|
||||
ClaimID *string `json:"claim_id,omitempty"`
|
||||
TXID *string `json:"txid,omitempty"`
|
||||
Nout *uint `json:"nout,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
IncludeProtobuf bool `json:"include_protobuf"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
}{
|
||||
ClaimID: claimID,
|
||||
TXID: txid,
|
||||
Nout: nout,
|
||||
Name: claimName,
|
||||
IncludeProtobuf: true,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
}
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "claim_search", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) ChannelExport(channelClaimID string, channelName, accountID *string) (*ChannelExportResponse, error) {
|
||||
response := new(ChannelExportResponse)
|
||||
return response, d.call(response, "channel_export", map[string]interface{}{
|
||||
"channel_id": channelClaimID,
|
||||
"channel_name": channelName,
|
||||
"account_id": accountID,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ChannelList() (*ChannelListResponse, error) {
|
||||
response := new(ChannelListResponse)
|
||||
return response, d.call(response, "channel_list", map[string]interface{}{})
|
||||
}
|
||||
|
||||
type PublishOptions struct {
|
||||
Fee *Fee
|
||||
Title *string
|
||||
Description *string
|
||||
Author *string
|
||||
Language *string
|
||||
License *string
|
||||
LicenseURL *string
|
||||
Thumbnail *string
|
||||
Preview *string
|
||||
NSFW *bool
|
||||
ChannelName *string
|
||||
ChannelID *string
|
||||
ClaimAddress *string
|
||||
ChangeAddress *string
|
||||
}
|
||||
|
||||
func (d *Client) Publish(name, filePath string, bid float64, options PublishOptions) (*PublishResponse, error) {
|
||||
response := new(PublishResponse)
|
||||
return response, d.call(response, "publish", map[string]interface{}{
|
||||
"name": name,
|
||||
"file_path": filePath,
|
||||
"bid": bid,
|
||||
"fee": options.Fee,
|
||||
"title": options.Title,
|
||||
"description": options.Description,
|
||||
"author": options.Author,
|
||||
"language": options.Language,
|
||||
"license": options.License,
|
||||
"license_url": options.LicenseURL,
|
||||
"thumbnail": options.Thumbnail,
|
||||
"preview": options.Preview,
|
||||
"nsfw": options.NSFW,
|
||||
"channel_name": options.ChannelName,
|
||||
"channel_id": options.ChannelID,
|
||||
"claim_address": options.ClaimAddress,
|
||||
"change_address": options.ChangeAddress,
|
||||
func (d *Client) ChannelImport(key string, walletID *string) (*ChannelImportResponse, error) {
|
||||
response := new(ChannelImportResponse)
|
||||
return response, d.call(response, "channel_import", map[string]interface{}{
|
||||
"channel_data": key,
|
||||
"wallet_id": walletID,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) BlobAnnounce(blobHash, sdHash, streamHash *string) (*BlobAnnounceResponse, error) {
|
||||
response := new(BlobAnnounceResponse)
|
||||
return response, d.call(response, "blob_announce", map[string]interface{}{
|
||||
"blob_hash": blobHash,
|
||||
"stream_hash": streamHash,
|
||||
"sd_hash": sdHash,
|
||||
func (d *Client) SupportList(accountID *string, page uint64, pageSize uint64) (*SupportListResponse, error) {
|
||||
response := new(SupportListResponse)
|
||||
return response, d.call(response, "support_list", map[string]interface{}{
|
||||
"account_id": accountID,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) WalletPrefillAddresses(numAddresses int, amount decimal.Decimal, broadcast bool) (*WalletPrefillAddressesResponse, error) {
|
||||
if numAddresses < 1 {
|
||||
return nil, errors.Err("must create at least 1 address")
|
||||
func (d *Client) SupportCreate(claimID string, amount string, tip *bool, accountID *string, fundingAccountIDs []string, walletID *string) (*TransactionSummary, error) {
|
||||
response := new(TransactionSummary)
|
||||
args := struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
Amount string `json:"amount"`
|
||||
Tip *bool `json:"tip,omitempty"`
|
||||
AccountID *string `json:"account_id,omitempty"`
|
||||
FundingAccountIDs []string `json:"funding_account_ids,omitempty"`
|
||||
Preview bool `json:"preview,omitempty"`
|
||||
Blocking bool `json:"blocking,omitempty"`
|
||||
WalletID *string `json:"wallet_id,omitempty"`
|
||||
}{
|
||||
ClaimID: claimID,
|
||||
AccountID: accountID,
|
||||
Blocking: true,
|
||||
Amount: amount,
|
||||
FundingAccountIDs: fundingAccountIDs,
|
||||
Preview: false,
|
||||
Tip: tip,
|
||||
}
|
||||
response := new(WalletPrefillAddressesResponse)
|
||||
return response, d.call(response, "wallet_prefill_addresses", map[string]interface{}{
|
||||
"num_addresses": numAddresses,
|
||||
"amount": amount,
|
||||
"no_broadcast": !broadcast,
|
||||
})
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "support_create", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) WalletNewAddress() (*WalletNewAddressResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("wallet_new_address", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func (d *Client) SupportAbandon(claimID *string, txid *string, nout *uint, keep *string, accountID *string) (*TransactionSummary, error) {
|
||||
if claimID == nil && (txid == nil || nout == nil) {
|
||||
return nil, errors.Err("either claimID or txid+nout must be supplied")
|
||||
}
|
||||
|
||||
address, ok := rawResponse.(string)
|
||||
if !ok {
|
||||
return nil, errors.Err("unexpected response")
|
||||
response := new(TransactionSummary)
|
||||
args := struct {
|
||||
ClaimID *string `json:"claim_id,omitempty"`
|
||||
TxID *string `json:"claim_id,omitempty"`
|
||||
Nout *uint `json:"nout,omitempty"`
|
||||
AccountID *string `json:"account_id,omitempty"`
|
||||
Preview bool `json:"preview,omitempty"`
|
||||
Blocking bool `json:"blocking,omitempty"`
|
||||
}{
|
||||
ClaimID: claimID,
|
||||
AccountID: accountID,
|
||||
Nout: nout,
|
||||
TxID: txid,
|
||||
Blocking: true,
|
||||
Preview: false,
|
||||
}
|
||||
|
||||
response := WalletNewAddressResponse(address)
|
||||
return &response, nil
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "support_abandon", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) WalletUnusedAddress() (*WalletUnusedAddressResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("wallet_unused_address", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func (d *Client) TxoSpend(txoType, claimID, txid, channelID, name, accountID *string) (*[]TransactionSummary, error) {
|
||||
if txoType == nil && claimID == nil && txid == nil && channelID == nil && name == nil {
|
||||
return nil, errors.Err("either txoType or claimID or channelID or name or txid must be supplied")
|
||||
}
|
||||
|
||||
address, ok := rawResponse.(string)
|
||||
if !ok {
|
||||
return nil, errors.Err("unexpected response")
|
||||
response := new([]TransactionSummary)
|
||||
args := struct {
|
||||
ClaimID *string `json:"claim_id,omitempty"`
|
||||
ChannelID *string `json:"channel_id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
TxID *string `json:"claim_id,omitempty"`
|
||||
Type *string `json:"type,omitempty"`
|
||||
AccountID *string `json:"account_id,omitempty"`
|
||||
Preview bool `json:"preview,omitempty"`
|
||||
Blocking bool `json:"blocking,omitempty"`
|
||||
IncludeFullTx bool `json:"include_full_tx,omitempty"`
|
||||
}{
|
||||
ClaimID: claimID,
|
||||
ChannelID: channelID,
|
||||
Name: name,
|
||||
Type: txoType,
|
||||
AccountID: accountID,
|
||||
TxID: txid,
|
||||
Blocking: true,
|
||||
Preview: false,
|
||||
IncludeFullTx: true,
|
||||
}
|
||||
|
||||
response := WalletUnusedAddressResponse(address)
|
||||
return &response, nil
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "txo_spend", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) NumClaimsInChannel(url string) (uint64, error) {
|
||||
response := new(NumClaimsInChannelResponse)
|
||||
err := d.call(response, "claim_list_by_channel", map[string]interface{}{
|
||||
"uri": url,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else if response == nil {
|
||||
return 0, errors.Err("no response")
|
||||
}
|
||||
func (d *Client) AccountAdd(accountName string, seed *string, privateKey *string, publicKey *string, singleKey *bool, walletID *string) (*Account, error) {
|
||||
response := new(Account)
|
||||
|
||||
channel, ok := (*response)[url]
|
||||
if !ok {
|
||||
return 0, errors.Err("url not in response")
|
||||
args := struct {
|
||||
AccountName string `json:"account_name"`
|
||||
Seed *string `json:"seed,omitempty"`
|
||||
PrivateKey *string `json:"private_key,omitempty"`
|
||||
PublicKey *string `json:"public_key,omitempty"`
|
||||
SingleKey *bool `json:"single_key,omitempty"`
|
||||
WalletID *string `json:"wallet_id,omitempty"`
|
||||
}{
|
||||
AccountName: accountName,
|
||||
Seed: seed,
|
||||
PrivateKey: privateKey,
|
||||
PublicKey: publicKey,
|
||||
SingleKey: singleKey,
|
||||
WalletID: walletID,
|
||||
}
|
||||
if channel.Error != "" {
|
||||
if strings.Contains(channel.Error, "cannot be resolved") {
|
||||
return 0, nil
|
||||
}
|
||||
return 0, errors.Err(channel.Error)
|
||||
}
|
||||
return channel.ClaimsInChannel, nil
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "account_add", structs.Map(args))
|
||||
}
|
||||
|
||||
func (d *Client) ClaimListMine() (*ClaimListMineResponse, error) {
|
||||
response := new(ClaimListMineResponse)
|
||||
err := d.call(response, "claim_list_mine", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if response == nil {
|
||||
return nil, errors.Err("no response")
|
||||
}
|
||||
|
||||
return response, nil
|
||||
type WalletCreateOpts struct {
|
||||
ID string `json:"wallet_id"`
|
||||
SkipOnStartup bool `json:"skip_on_startup,omitempty"`
|
||||
CreateAccount bool `json:"create_account,omitempty"`
|
||||
SingleKey bool `json:"single_key,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Client) ClaimAbandon(txID string, nOut int) (*ClaimAbandonResponse, error) {
|
||||
response := new(ClaimAbandonResponse)
|
||||
err := d.call(response, "claim_abandon", map[string]interface{}{
|
||||
"txid": txID,
|
||||
"nout": nOut,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if response == nil {
|
||||
return nil, errors.Err("no response")
|
||||
func (d *Client) WalletCreate(id string, opts *WalletCreateOpts) (*Wallet, error) {
|
||||
response := new(Wallet)
|
||||
if opts == nil {
|
||||
opts = &WalletCreateOpts{}
|
||||
}
|
||||
opts.ID = id
|
||||
structs.DefaultTagName = "json"
|
||||
return response, d.call(response, "wallet_create", structs.Map(opts))
|
||||
}
|
||||
|
||||
return response, nil
|
||||
func (d *Client) WalletAdd(id string) (*Wallet, error) {
|
||||
response := new(Wallet)
|
||||
return response, d.call(response, "wallet_add", map[string]interface{}{"wallet_id": id})
|
||||
}
|
||||
|
||||
func (d *Client) WalletList(id string, page uint64, pageSize uint64) (*WalletList, error) {
|
||||
response := new(WalletList)
|
||||
params := map[string]interface {
|
||||
}{
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
}
|
||||
if id != "" {
|
||||
params["wallet_id"] = id
|
||||
}
|
||||
return response, d.call(response, "wallet_list", params)
|
||||
}
|
||||
|
||||
func (d *Client) WalletRemove(id string) (*Wallet, error) {
|
||||
response := new(Wallet)
|
||||
return response, d.call(response, "wallet_remove", map[string]interface{}{"wallet_id": id})
|
||||
}
|
||||
@@ -1,8 +1,793 @@
|
||||
package jsonrpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/util"
|
||||
)
|
||||
|
||||
func TestStatus(t *testing.T) {
|
||||
func prettyPrint(i interface{}) {
|
||||
s, _ := json.MarshalIndent(i, "", "\t")
|
||||
fmt.Println(string(s))
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
code := m.Run()
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func TestClient_AccountFund(t *testing.T) {
|
||||
d := NewClient("")
|
||||
accounts, err := d.AccountList(1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
account := (accounts.Items)[0].ID
|
||||
balanceString, err := d.AccountBalance(&account)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
balance, err := strconv.ParseFloat(balanceString.Available.String(), 64)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
got, err := d.AccountFund(account, account, fmt.Sprintf("%f", balance/2.0), 40, false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_AccountList(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.AccountList(1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_SingleAccountList(t *testing.T) {
|
||||
d := NewClient("")
|
||||
name := "test" + fmt.Sprintf("%d", rand.Int()) + "@lbry.com"
|
||||
createdAccount, err := d.AccountCreate(name, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
account, err := d.SingleAccountList(createdAccount.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
prettyPrint(*createdAccount)
|
||||
prettyPrint(*account)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if account.Items[0].Name != name {
|
||||
t.Fatalf("account name mismatch: %v != %v", account.Items[0].Name, name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_AccountBalance(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.AccountBalance(nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_AddressUnused(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.AddressUnused(nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_ChannelList(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.ChannelList(nil, 1, 50, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
var channelID string
|
||||
|
||||
func TestClient_ChannelCreate(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 1.337, ChannelCreateOptions{
|
||||
ClaimCreateOptions: ClaimCreateOptions{
|
||||
Title: util.PtrToString("Mess with the channels"),
|
||||
Description: util.PtrToString("And you'll get what you deserve"),
|
||||
Tags: []string{"we", "got", "tags"},
|
||||
Languages: []string{"en-US"},
|
||||
Locations: []Location{{
|
||||
Country: util.PtrToString("CH"),
|
||||
State: util.PtrToString("Ticino"),
|
||||
City: util.PtrToString("Lugano"),
|
||||
}},
|
||||
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
},
|
||||
Email: util.PtrToString("niko@lbry.com"),
|
||||
WebsiteURL: util.PtrToString("https://lbry.com"),
|
||||
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
channelID = got.Outputs[0].ClaimID
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_StreamCreate(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
addressResponse, err := d.AddressUnused(nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
address := string(*addressResponse)
|
||||
f, e := os.OpenFile("/tmp/test.txt", os.O_RDONLY|os.O_CREATE, 0666)
|
||||
if e != nil {
|
||||
t.Error(e)
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = f.WriteString("test")
|
||||
got, err := d.StreamCreate("test"+fmt.Sprintf("%d", time.Now().Unix()), "/tmp/test.txt", 1.437, StreamCreateOptions{
|
||||
ClaimCreateOptions: ClaimCreateOptions{
|
||||
Title: util.PtrToString("This is a Test Title" + fmt.Sprintf("%d", time.Now().Unix())),
|
||||
Description: util.PtrToString("My Special Description"),
|
||||
Tags: []string{"nsfw", "test"},
|
||||
Languages: []string{"en-US", "fr-CH"},
|
||||
Locations: []Location{{
|
||||
Country: util.PtrToString("CH"),
|
||||
State: util.PtrToString("Ticino"),
|
||||
City: util.PtrToString("Lugano"),
|
||||
PostalCode: util.PtrToString("6900"),
|
||||
Latitude: nil,
|
||||
Longitude: nil,
|
||||
}},
|
||||
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-01-18_16-37-39-098537783.png"),
|
||||
AccountID: nil,
|
||||
ClaimAddress: &address,
|
||||
Preview: nil,
|
||||
},
|
||||
|
||||
Fee: &Fee{
|
||||
FeeCurrency: "LBC",
|
||||
FeeAmount: decimal.NewFromFloat(1.0),
|
||||
FeeAddress: &address,
|
||||
},
|
||||
Author: util.PtrToString("Niko"),
|
||||
License: util.PtrToString("FREE"),
|
||||
LicenseURL: nil,
|
||||
ReleaseTime: nil,
|
||||
Duration: nil,
|
||||
Preview: nil,
|
||||
AllowDuplicateName: nil,
|
||||
ChannelName: nil,
|
||||
ChannelID: util.PtrToString(channelID),
|
||||
ChannelAccountID: nil,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_ChannelUpdate(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.ChannelUpdate(channelID, ChannelUpdateOptions{
|
||||
Bid: util.PtrToString("0.01"),
|
||||
ClearLanguages: util.PtrToBool(true),
|
||||
ClearLocations: util.PtrToBool(true),
|
||||
ClearTags: util.PtrToBool(true),
|
||||
ChannelCreateOptions: ChannelCreateOptions{
|
||||
ClaimCreateOptions: ClaimCreateOptions{
|
||||
Title: util.PtrToString("Mess with the channels"),
|
||||
Description: util.PtrToString("And you'll get what you deserve"),
|
||||
Tags: []string{"we", "got", "more", "tags"},
|
||||
Languages: []string{"en-US"},
|
||||
Locations: []Location{{
|
||||
Country: util.PtrToString("CH"),
|
||||
State: util.PtrToString("Ticino"),
|
||||
City: util.PtrToString("Lugano"),
|
||||
}},
|
||||
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
},
|
||||
Email: util.PtrToString("niko@lbry.com"),
|
||||
WebsiteURL: util.PtrToString("https://lbry.com"),
|
||||
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
}})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_ChannelAbandon(t *testing.T) {
|
||||
d := NewClient("")
|
||||
channelName := "@TestToDelete" + fmt.Sprintf("%d", time.Now().Unix())
|
||||
channelResponse, err := d.ChannelCreate(channelName, 13.37, ChannelCreateOptions{
|
||||
ClaimCreateOptions: ClaimCreateOptions{
|
||||
Title: util.PtrToString("Mess with the channels"),
|
||||
Description: util.PtrToString("And you'll get what you deserve"),
|
||||
Tags: []string{"we", "got", "tags"},
|
||||
Languages: []string{"en-US"},
|
||||
Locations: []Location{{
|
||||
Country: util.PtrToString("CH"),
|
||||
State: util.PtrToString("Ticino"),
|
||||
City: util.PtrToString("Lugano"),
|
||||
}},
|
||||
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
},
|
||||
Email: util.PtrToString("niko@lbry.com"),
|
||||
WebsiteURL: util.PtrToString("https://lbry.com"),
|
||||
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
txID := channelResponse.Outputs[0].Txid
|
||||
nout := channelResponse.Outputs[0].Nout
|
||||
time.Sleep(10 * time.Second)
|
||||
got, err := d.ChannelAbandon(txID, nout, nil, false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_AddressList(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.AddressList(nil, nil, 1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_ClaimList(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
got, err := d.ClaimList(nil, 1, 10)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_StreamList(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
got, err := d.StreamList(nil, 1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_TransactionList(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
got, err := d.TransactionList(nil, nil, 1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_SupportTest(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
|
||||
ClaimCreateOptions: ClaimCreateOptions{
|
||||
Title: util.PtrToString("Mess with the channels"),
|
||||
Description: util.PtrToString("And you'll get what you deserve"),
|
||||
Tags: []string{"we", "got", "tags"},
|
||||
Languages: []string{"en-US"},
|
||||
Locations: []Location{{
|
||||
Country: util.PtrToString("CH"),
|
||||
State: util.PtrToString("Ticino"),
|
||||
City: util.PtrToString("Lugano"),
|
||||
}},
|
||||
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
},
|
||||
Email: util.PtrToString("niko@lbry.com"),
|
||||
WebsiteURL: util.PtrToString("https://lbry.com"),
|
||||
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
time.Sleep(10 * time.Second)
|
||||
got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got2)
|
||||
|
||||
got3, err := d.SupportList(nil, 1, 10)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
found := false
|
||||
for _, support := range got3.Items {
|
||||
if support.ClaimID == got.Outputs[0].ClaimID {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Error(errors.Err("support not found"))
|
||||
return
|
||||
}
|
||||
prettyPrint(*got3)
|
||||
got4, err := d.SupportAbandon(util.PtrToString(got.Outputs[0].ClaimID), nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got4)
|
||||
}
|
||||
|
||||
func TestClient_TxoSpendTest(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
|
||||
ClaimCreateOptions: ClaimCreateOptions{
|
||||
Title: util.PtrToString("Mess with the channels"),
|
||||
Description: util.PtrToString("And you'll get what you deserve"),
|
||||
Tags: []string{"we", "got", "tags"},
|
||||
Languages: []string{"en-US"},
|
||||
Locations: []Location{{
|
||||
Country: util.PtrToString("CH"),
|
||||
State: util.PtrToString("Ticino"),
|
||||
City: util.PtrToString("Lugano"),
|
||||
}},
|
||||
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
},
|
||||
Email: util.PtrToString("niko@lbry.com"),
|
||||
WebsiteURL: util.PtrToString("https://lbry.com"),
|
||||
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
time.Sleep(10 * time.Second)
|
||||
got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got2)
|
||||
|
||||
got3, err := d.SupportList(nil, 1, 10)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
found := false
|
||||
for _, support := range got3.Items {
|
||||
if support.ClaimID == got.Outputs[0].ClaimID {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Error(errors.Err("support not found"))
|
||||
return
|
||||
}
|
||||
prettyPrint(*got3)
|
||||
got4, err := d.TxoSpend(util.PtrToString("support"), util.PtrToString(got.Outputs[0].ClaimID), nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got4)
|
||||
time.Sleep(10 * time.Second)
|
||||
got3, err = d.SupportList(nil, 1, 10)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
found = false
|
||||
for _, support := range got3.Items {
|
||||
if support.ClaimID == got.Outputs[0].ClaimID {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
t.Error(errors.Err("support found even though it should have been abandoned"))
|
||||
return
|
||||
}
|
||||
prettyPrint(*got3)
|
||||
got4, err = d.TxoSpend(util.PtrToString("channel"), util.PtrToString(got.Outputs[0].ClaimID), nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got4)
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
got5, err := d.ClaimList(nil, 1, 50)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
for _, claim := range got5.Claims {
|
||||
if claim.ClaimID == got.Outputs[0].ClaimID {
|
||||
t.Error(errors.Err("claim found even though it should have been abandoned"))
|
||||
return
|
||||
}
|
||||
}
|
||||
prettyPrint(*got5)
|
||||
}
|
||||
|
||||
func TestClient_ClaimSearch(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.ClaimSearch(nil, util.PtrToString(channelID), nil, nil, 1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_Status(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.Status()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_UTXOList(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.UTXOList(nil, 1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_Version(t *testing.T) {
|
||||
d := NewClient("")
|
||||
got, err := d.Version()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_GetFile(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
got, err := d.Get("lbry://test1559058649")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_FileList(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
got, err := d.FileList(1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_Resolve(t *testing.T) {
|
||||
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
||||
d := NewClient("")
|
||||
got, err := d.Resolve("test1559058649")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_AccountSet(t *testing.T) {
|
||||
d := NewClient("")
|
||||
accounts, err := d.AccountList(1, 20)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
account := (accounts.Items)[0].ID
|
||||
|
||||
got, err := d.AccountSet(account, AccountSettings{ChangeMaxUses: util.PtrToInt(10000)})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
prettyPrint(*got)
|
||||
}
|
||||
|
||||
func TestClient_AccountCreate(t *testing.T) {
|
||||
d := NewClient("")
|
||||
name := "lbry#user#id:" + fmt.Sprintf("%d", rand.Int())
|
||||
account, err := d.AccountCreate(name, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
if account.Name != name {
|
||||
t.Errorf("account name mismatch, expected %q, got %q", name, account.Name)
|
||||
return
|
||||
}
|
||||
prettyPrint(*account)
|
||||
}
|
||||
|
||||
func TestClient_AccountAdd(t *testing.T) {
|
||||
d := NewClient("")
|
||||
name := "test" + fmt.Sprintf("%d", time.Now().Unix()) + "@lbry.com"
|
||||
pubKey := "tpubDA9GDAntyJu4hD3wU7175p7CuV6DWbYXfyb2HedBA3yuBp9HZ4n3QE4Ex6RHCSiEuVp2nKAL1Lzf2ZLo9ApaFgNaJjG6Xo1wB3iEeVbrDZp"
|
||||
account, err := d.AccountAdd(name, nil, nil, &pubKey, util.PtrToBool(true), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
if account.Name != name {
|
||||
t.Errorf("account name mismatch, expected %q, got %q", name, account.Name)
|
||||
return
|
||||
}
|
||||
if account.PublicKey != pubKey {
|
||||
t.Errorf("public key mismatch, expected %q, got %q", name, account.Name)
|
||||
return
|
||||
}
|
||||
prettyPrint(*account)
|
||||
}
|
||||
|
||||
func TestClient_AccountRemove(t *testing.T) {
|
||||
d := NewClient("")
|
||||
name := "lbry#user#id:" + fmt.Sprintf("%d", rand.Int())
|
||||
createdAccount, err := d.AccountCreate(name, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
removedAccount, err := d.AccountRemove(createdAccount.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if removedAccount.ID != createdAccount.ID {
|
||||
t.Error("accounts IDs mismatch")
|
||||
}
|
||||
|
||||
account, err := d.SingleAccountList(createdAccount.ID)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "Couldn't find account:") {
|
||||
prettyPrint(*removedAccount)
|
||||
return
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Error("account was not removed")
|
||||
prettyPrint(*account)
|
||||
}
|
||||
|
||||
func TestClient_ChannelExport(t *testing.T) {
|
||||
d := NewClient("")
|
||||
response, err := d.ChannelExport(channelID, nil, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if response == nil || len(*response) == 0 {
|
||||
t.Error("nothing returned!")
|
||||
}
|
||||
t.Log("Export:", *response)
|
||||
}
|
||||
|
||||
func TestClient_ChannelImport(t *testing.T) {
|
||||
d := NewClient("")
|
||||
|
||||
// A channel created just for automated testing purposes
|
||||
channelName := "@LbryAutomatedTestChannel"
|
||||
channelkey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" +
|
||||
"oKkfb99PgGK5efrZeYqaxg4X5XRJMJ6gKC8hqKcnwhYkmKDXmoBDNgd2ccZ9jhP8z" +
|
||||
"HG3NJorAN9Hh4XMyBc5goBLZYYvC9MYvBmT3Fcteb5saqMvmQxFURv74NqXLQZC1t" +
|
||||
"p6iRZKfTj77Pd5gsBsCYAbVmCqzbm5m1hHkUmfFEZVGcQNTYCDwZn543xSMYvSPnJ" +
|
||||
"zt8tRYCJWaPdj713uENZZMo3gxuAMb1NwSnx8tbwETp7WPkpFLL6HZ9jKpB8BURHM" +
|
||||
"F1RFD1PRyqbC6YezPyPQ2oninKKHdBduvXZG5KF2G2Q3ixsuE2ntifBBo1f5PotRk" +
|
||||
"UanXKEafWxvXAayJjpsmZ4bFt7n6Xg4438WZXBiZKCPobLJAiHfe72n618kE6PCNU" +
|
||||
"77cyU5Rk8J3CuY6QzZPzwuiXz2GLfkUMCYd9jGT6g53XbE6SwCsmGnd9NJkBAaJf5" +
|
||||
"1FAYRURrhHnp79PAoHftEWtZEuU8MCPMdSRjzxYMRS4ScUzg5viDMTAkE8frsfCVZ" +
|
||||
"hxsFwGUyNNno8eiqrrYmpbJGEwwK3S4437JboAUEFPdMNn8zNQWZcLLVrK9KyQeKM" +
|
||||
"XpKkf4zJV6sZJ7gBMpzvPL18ULEgXTy7VsNBKmsfC1rM4WVG9ri1UixEcLDS79foC" +
|
||||
"Jb3FnSr1T4MRKESeN3W"
|
||||
response, err := d.ChannelImport(channelkey, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
channels, err := d.ChannelList(nil, 1, 50, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
seen := false
|
||||
for _, c := range channels.Items {
|
||||
if c.Name == channelName {
|
||||
seen = true
|
||||
}
|
||||
}
|
||||
if !seen {
|
||||
t.Error("couldn't find imported channel")
|
||||
}
|
||||
t.Log("Response:", *response)
|
||||
}
|
||||
|
||||
func TestClient_ChannelImportWithWalletID(t *testing.T) {
|
||||
d := NewClient("")
|
||||
|
||||
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
||||
wallet, err := d.WalletCreate(id, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
// A channel created just for automated testing purposes
|
||||
channelName := "@LbryAutomatedTestChannel"
|
||||
channelKey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" +
|
||||
"oKkfb99PgGK5efrZeYqaxg4X5XRJMJ6gKC8hqKcnwhYkmKDXmoBDNgd2ccZ9jhP8z" +
|
||||
"HG3NJorAN9Hh4XMyBc5goBLZYYvC9MYvBmT3Fcteb5saqMvmQxFURv74NqXLQZC1t" +
|
||||
"p6iRZKfTj77Pd5gsBsCYAbVmCqzbm5m1hHkUmfFEZVGcQNTYCDwZn543xSMYvSPnJ" +
|
||||
"zt8tRYCJWaPdj713uENZZMo3gxuAMb1NwSnx8tbwETp7WPkpFLL6HZ9jKpB8BURHM" +
|
||||
"F1RFD1PRyqbC6YezPyPQ2oninKKHdBduvXZG5KF2G2Q3ixsuE2ntifBBo1f5PotRk" +
|
||||
"UanXKEafWxvXAayJjpsmZ4bFt7n6Xg4438WZXBiZKCPobLJAiHfe72n618kE6PCNU" +
|
||||
"77cyU5Rk8J3CuY6QzZPzwuiXz2GLfkUMCYd9jGT6g53XbE6SwCsmGnd9NJkBAaJf5" +
|
||||
"1FAYRURrhHnp79PAoHftEWtZEuU8MCPMdSRjzxYMRS4ScUzg5viDMTAkE8frsfCVZ" +
|
||||
"hxsFwGUyNNno8eiqrrYmpbJGEwwK3S4437JboAUEFPdMNn8zNQWZcLLVrK9KyQeKM" +
|
||||
"XpKkf4zJV6sZJ7gBMpzvPL18ULEgXTy7VsNBKmsfC1rM4WVG9ri1UixEcLDS79foC" +
|
||||
"Jb3FnSr1T4MRKESeN3W"
|
||||
response, err := d.ChannelImport(channelKey, &wallet.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
channels, err := d.ChannelList(nil, 1, 50, &wallet.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
seen := false
|
||||
for _, c := range channels.Items {
|
||||
if c.Name == channelName {
|
||||
seen = true
|
||||
}
|
||||
}
|
||||
if !seen {
|
||||
t.Error("couldn't find imported channel")
|
||||
}
|
||||
t.Log("Response:", *response)
|
||||
}
|
||||
|
||||
func TestClient_WalletCreate(t *testing.T) {
|
||||
d := NewClient("")
|
||||
|
||||
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
||||
wallet, err := d.WalletCreate(id, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if wallet.ID != id {
|
||||
prettyPrint(*wallet)
|
||||
t.Fatalf("wallet ID mismatch, expected %q, got %q", id, wallet.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_WalletCreateWithOpts(t *testing.T) {
|
||||
d := NewClient("")
|
||||
|
||||
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
||||
wallet, err := d.WalletCreate(id, &WalletCreateOpts{CreateAccount: true, SingleKey: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
accounts, err := d.AccountListForWallet(id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prettyPrint(wallet)
|
||||
prettyPrint(accounts)
|
||||
if accounts.Items[0].Name == "" {
|
||||
t.Fatalf("account name is empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_WalletList(t *testing.T) {
|
||||
d := NewClient("")
|
||||
|
||||
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
||||
wList, err := d.WalletList(id, 1, 20)
|
||||
if err == nil {
|
||||
t.Fatalf("wallet %v was unexpectedly found", id)
|
||||
}
|
||||
if !strings.Contains(err.Error(), fmt.Sprintf("Couldn't find wallet: %v.", id)) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = d.WalletCreate(id, &WalletCreateOpts{CreateAccount: true, SingleKey: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
wList, err = d.WalletList(id, 1, 20)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(wList.Items) < 1 {
|
||||
t.Fatal("wallet list is empty")
|
||||
}
|
||||
if (wList.Items)[0].ID != id {
|
||||
t.Fatalf("wallet ID mismatch, expected %q, got %q", id, (wList.Items)[0].ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_WalletRemoveWalletAdd(t *testing.T) {
|
||||
d := NewClient("")
|
||||
|
||||
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
||||
wallet, err := d.WalletCreate(id, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = d.WalletRemove(id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
addedWallet, err := d.WalletAdd(id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if addedWallet.ID != wallet.ID {
|
||||
prettyPrint(*addedWallet)
|
||||
t.Fatalf("wallet ID mismatch, expected %q, got %q", wallet.ID, addedWallet.Name)
|
||||
}
|
||||
}
|
||||
+494
-229
@@ -1,11 +1,18 @@
|
||||
package jsonrpc
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
lbryschema "github.com/lbryio/types/v1/go"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/stream"
|
||||
|
||||
schema "github.com/lbryio/lbry.go/v2/schema/claim"
|
||||
lbryschema "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
@@ -19,69 +26,49 @@ const (
|
||||
)
|
||||
|
||||
type Fee struct {
|
||||
Currency Currency `json:"currency"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
Address *string `json:"address"`
|
||||
}
|
||||
|
||||
type Support struct {
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
Nout int `json:"nout"`
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
|
||||
type Claim struct {
|
||||
Address string `json:"address"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
BlocksToExpiration int `json:"blocks_to_expiration"`
|
||||
Category string `json:"category"`
|
||||
ClaimID string `json:"claim_id"`
|
||||
ClaimSequence int `json:"claim_sequence"`
|
||||
Confirmations int `json:"confirmations"`
|
||||
DecodedClaim bool `json:"decoded_claim"`
|
||||
Depth int `json:"depth"`
|
||||
EffectiveAmount decimal.Decimal `json:"effective_amount"`
|
||||
ExpirationHeight int `json:"expiration_height"`
|
||||
Expired bool `json:"expired"`
|
||||
Height int `json:"height"`
|
||||
Hex string `json:"hex"`
|
||||
IsSpent bool `json:"is_spent"`
|
||||
Name string `json:"name"`
|
||||
Nout int `json:"nout"`
|
||||
PermanentUrl string `json:"permanent_url"`
|
||||
Supports []Support `json:"supports"`
|
||||
Txid string `json:"txid"`
|
||||
ValidAtHeight int `json:"valid_at_height"`
|
||||
Value lbryschema.Claim `json:"value"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
ChannelName *string `json:"channel_name,omitempty"`
|
||||
HasSignature *bool `json:"has_signature,omitempty"`
|
||||
SignatureIsValid *bool `json:"signature_is_valid,omitempty"`
|
||||
FeeCurrency Currency `json:"fee_currency"`
|
||||
FeeAmount decimal.Decimal `json:"fee_amount"`
|
||||
FeeAddress *string `json:"fee_address"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
Completed bool `json:"completed"`
|
||||
DownloadDirectory string `json:"download_directory"`
|
||||
DownloadPath string `json:"download_path"`
|
||||
FileName string `json:"file_name"`
|
||||
Key string `json:"key"`
|
||||
Message string `json:"message"`
|
||||
Metadata *lbryschema.Claim `json:"metadata"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Name string `json:"name"`
|
||||
Outpoint string `json:"outpoint"`
|
||||
PointsPaid decimal.Decimal `json:"points_paid"`
|
||||
SdHash string `json:"sd_hash"`
|
||||
Stopped bool `json:"stopped"`
|
||||
StreamHash string `json:"stream_hash"`
|
||||
StreamName string `json:"stream_name"`
|
||||
SuggestedFileName string `json:"suggested_file_name"`
|
||||
TotalBytes uint64 `json:"total_bytes"`
|
||||
WrittenBytes uint64 `json:"written_bytes"`
|
||||
ChannelName *string `json:"channel_name,omitempty"`
|
||||
HasSignature *bool `json:"has_signature,omitempty"`
|
||||
SignatureIsValid *bool `json:"signature_is_valid,omitempty"`
|
||||
AddedOn int64 `json:"added_on"`
|
||||
BlobsCompleted uint64 `json:"blobs_completed"`
|
||||
BlobsInStream uint64 `json:"blobs_in_stream"`
|
||||
BlobsRemaining uint64 `json:"blobs_remaining"`
|
||||
ChannelClaimID string `json:"channel_claim_id"`
|
||||
ChannelName string `json:"channel_name"`
|
||||
ClaimID string `json:"claim_id"`
|
||||
ClaimName string `json:"claim_name"`
|
||||
Completed bool `json:"completed"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
ContentFee *Fee `json:"content_fee"`
|
||||
DownloadDirectory string `json:"download_directory"`
|
||||
DownloadPath string `json:"download_path"`
|
||||
FileName string `json:"file_name"`
|
||||
Height int `json:"height"`
|
||||
IsFullyReflected bool `json:"is_fully_reflected"`
|
||||
Key string `json:"key"`
|
||||
Metadata *lbryschema.Claim `json:"protobuf"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Nout int `json:"nout"`
|
||||
Outpoint string `json:"outpoint"`
|
||||
Protobuf string `json:"protobuf"`
|
||||
PurchaseReceipt interface{} `json:"purchase_receipt"`
|
||||
ReflectorProgress int `json:"reflector_progress"`
|
||||
SdHash string `json:"sd_hash"`
|
||||
Status string `json:"status"`
|
||||
Stopped bool `json:"stopped"`
|
||||
StreamHash string `json:"stream_hash"`
|
||||
StreamName string `json:"stream_name"`
|
||||
StreamingURL string `json:"streaming_url"`
|
||||
SuggestedFileName string `json:"suggested_file_name"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
TotalBytes uint64 `json:"total_bytes"`
|
||||
TotalBytesLowerBound uint64 `json:"total_bytes_lower_bound"`
|
||||
Txid string `json:"txid"`
|
||||
UploadingToReflector bool `json:"uploading_to_reflector"`
|
||||
WrittenBytes uint64 `json:"written_bytes"`
|
||||
}
|
||||
|
||||
func getEnumVal(enum map[string]int32, data interface{}) (int32, error) {
|
||||
@@ -128,126 +115,27 @@ func fixDecodeProto(src, dest reflect.Type, data interface{}) (interface{}, erro
|
||||
return d, nil
|
||||
}
|
||||
|
||||
case reflect.TypeOf(lbryschema.Metadata_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Metadata_Version_value, data)
|
||||
return lbryschema.Metadata_Version(val), err
|
||||
case reflect.TypeOf(lbryschema.Metadata_Language(0)):
|
||||
val, err := getEnumVal(lbryschema.Metadata_Language_value, data)
|
||||
return lbryschema.Metadata_Language(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Stream_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Stream_Version_value, data)
|
||||
return lbryschema.Stream_Version(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Claim_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Claim_Version_value, data)
|
||||
return lbryschema.Claim_Version(val), err
|
||||
case reflect.TypeOf(lbryschema.Claim_ClaimType(0)):
|
||||
val, err := getEnumVal(lbryschema.Claim_ClaimType_value, data)
|
||||
return lbryschema.Claim_ClaimType(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Fee_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Fee_Version_value, data)
|
||||
return lbryschema.Fee_Version(val), err
|
||||
case reflect.TypeOf(lbryschema.Fee_Currency(0)):
|
||||
val, err := getEnumVal(lbryschema.Fee_Currency_value, data)
|
||||
return lbryschema.Fee_Currency(val), err
|
||||
case reflect.TypeOf(lbryschema.Claim{}):
|
||||
blockChainName := os.Getenv("BLOCKCHAIN_NAME")
|
||||
if blockChainName == "" {
|
||||
blockChainName = "lbrycrd_main"
|
||||
}
|
||||
|
||||
case reflect.TypeOf(lbryschema.Source_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Source_Version_value, data)
|
||||
return lbryschema.Source_Version(val), err
|
||||
case reflect.TypeOf(lbryschema.Source_SourceTypes(0)):
|
||||
val, err := getEnumVal(lbryschema.Source_SourceTypes_value, data)
|
||||
return lbryschema.Source_SourceTypes(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.KeyType(0)):
|
||||
val, err := getEnumVal(lbryschema.KeyType_value, data)
|
||||
return lbryschema.KeyType(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Signature_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Signature_Version_value, data)
|
||||
return lbryschema.Signature_Version(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Certificate_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Certificate_Version_value, data)
|
||||
return lbryschema.Certificate_Version(val), err
|
||||
claim, err := schema.DecodeClaimHex(data.(string), blockChainName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return claim.Claim, nil
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
type CommandsResponse []string
|
||||
|
||||
type WalletBalanceResponse decimal.Decimal
|
||||
|
||||
type VersionResponse struct {
|
||||
Build string `json:"build"`
|
||||
LbrynetVersion string `json:"lbrynet_version"`
|
||||
LbryschemaVersion string `json:"lbryschema_version"`
|
||||
LbryumVersion string `json:"lbryum_version"`
|
||||
OsRelease string `json:"os_release"`
|
||||
OsSystem string `json:"os_system"`
|
||||
Platform string `json:"platform"`
|
||||
Processor string `json:"processor"`
|
||||
PythonVersion string `json:"python_version"`
|
||||
}
|
||||
type StatusResponse struct {
|
||||
BlobManager struct {
|
||||
FinishedBlobs int `json:"finished_blobs"`
|
||||
} `json:"blob_manager"`
|
||||
ConnectionStatus struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"connection_status"`
|
||||
Dht struct {
|
||||
NodeID string `json:"node_id"`
|
||||
PeersInRoutingTable int `json:"peers_in_routing_table"`
|
||||
} `json:"dht"`
|
||||
FileManager struct {
|
||||
ManagedFiles int `json:"managed_files"`
|
||||
} `json:"file_manager"`
|
||||
HashAnnouncer struct {
|
||||
AnnounceQueueSize int `json:"announce_queue_size"`
|
||||
} `json:"hash_announcer"`
|
||||
InstallationID string `json:"installation_id"`
|
||||
IsFirstRun bool `json:"is_first_run"`
|
||||
IsRunning bool `json:"is_running"`
|
||||
SkippedComponents []string `json:"skipped_components"`
|
||||
StartupStatus struct {
|
||||
BlobManager bool `json:"blob_manager"`
|
||||
BlockchainHeaders bool `json:"blockchain_headers"`
|
||||
Database bool `json:"database"`
|
||||
Dht bool `json:"dht"`
|
||||
ExchangeRateManager bool `json:"exchange_rate_manager"`
|
||||
FileManager bool `json:"file_manager"`
|
||||
HashAnnouncer bool `json:"hash_announcer"`
|
||||
PaymentRateManager bool `json:"payment_rate_manager"`
|
||||
PeerProtocolServer bool `json:"peer_protocol_server"`
|
||||
RateLimiter bool `json:"rate_limiter"`
|
||||
StreamIdentifier bool `json:"stream_identifier"`
|
||||
Upnp bool `json:"upnp"`
|
||||
Wallet bool `json:"wallet"`
|
||||
} `json:"startup_status"`
|
||||
Wallet struct {
|
||||
BestBlockchain string `json:"best_blockchain"`
|
||||
Blocks int `json:"blocks"`
|
||||
BlocksBehind int `json:"blocks_behind"`
|
||||
IsEncrypted bool `json:"is_encrypted"`
|
||||
} `json:"wallet"`
|
||||
}
|
||||
|
||||
type ClaimListResponse struct {
|
||||
Claims []Claim `json:"claims"`
|
||||
LastTakeoverHeight int `json:"last_takeover_height"`
|
||||
SupportsWithoutClaims []Support `json:"supports_without_claims"`
|
||||
}
|
||||
type ClaimListMineResponse []Claim
|
||||
type ClaimShowResponse Claim
|
||||
type ClaimAbandonResponse struct {
|
||||
Txid string `json:"txid"`
|
||||
Fee float64 `json:"fee"`
|
||||
}
|
||||
|
||||
type PeerListResponsePeer struct {
|
||||
IP string `json:"host"`
|
||||
Port uint `json:"port"`
|
||||
@@ -293,84 +181,461 @@ type StreamAvailabilityResponse struct {
|
||||
}
|
||||
|
||||
type GetResponse File
|
||||
type FileListResponse []File
|
||||
|
||||
type ResolveResponse map[string]ResolveResponseItem
|
||||
type ResolveResponseItem struct {
|
||||
Certificate *Claim `json:"certificate,omitempty"`
|
||||
Claim *Claim `json:"claim,omitempty"`
|
||||
ClaimsInChannel *uint64 `json:"claims_in_channel,omitempty"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
type FileListResponse struct {
|
||||
Items []File `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
|
||||
type ChannelNewResponse struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
Fee decimal.Decimal `json:"fee"`
|
||||
Nout int `json:"nout"`
|
||||
Success bool `json:"success"`
|
||||
Tx string `json:"tx"`
|
||||
Txid string `json:"txid"`
|
||||
type Account struct {
|
||||
AddressGenerator struct {
|
||||
Change struct {
|
||||
Gap uint64 `json:"gap"`
|
||||
MaximumUsesPerAddress uint64 `json:"maximum_uses_per_address"`
|
||||
} `json:"change"`
|
||||
Name string `json:"name"`
|
||||
Receiving struct {
|
||||
Gap uint64 `json:"gap"`
|
||||
MaximumUsesPerAddress uint64 `json:"maximum_uses_per_address"`
|
||||
} `json:"receiving"`
|
||||
} `json:"address_generator"`
|
||||
Certificates uint64 `json:"certificates"`
|
||||
Coins float64 `json:"coins"`
|
||||
Encrypted bool `json:"encrypted"`
|
||||
ID string `json:"id"`
|
||||
IsDefault bool `json:"is_default"`
|
||||
Ledger *string `json:"ledger,omitempty"`
|
||||
ModifiedOn *float64 `json:"modified_on,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Preferences *struct {
|
||||
Theme string `json:"theme"`
|
||||
} `json:"preferences,omitempty"`
|
||||
PrivateKey *string `json:"private_key,omitempty"`
|
||||
PublicKey string `json:"public_key"`
|
||||
Seed *string `json:"seed,omitempty"`
|
||||
Satoshis uint64 `json:"satoshis"`
|
||||
}
|
||||
|
||||
type ChannelListSingleResponse struct {
|
||||
type AccountListResponse struct {
|
||||
Items []Account `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
|
||||
type AccountBalanceResponse struct {
|
||||
Available decimal.Decimal `json:"available"`
|
||||
Reserved decimal.Decimal `json:"reserved"`
|
||||
ReservedSubtotals struct {
|
||||
Claims decimal.Decimal `json:"claims"`
|
||||
Supports decimal.Decimal `json:"supports"`
|
||||
Tips decimal.Decimal `json:"tips"`
|
||||
} `json:"reserved_subtotals"`
|
||||
Total decimal.Decimal `json:"total"`
|
||||
}
|
||||
|
||||
type Transaction struct {
|
||||
Address string `json:"address"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
BlocksToExpiration int `json:"blocks_to_expiration"`
|
||||
CanSign bool `json:"can_sign"`
|
||||
Category string `json:"category"`
|
||||
Amount string `json:"amount"`
|
||||
ClaimID string `json:"claim_id"`
|
||||
ClaimOp string `json:"claim_op"`
|
||||
Confirmations int `json:"confirmations"`
|
||||
DecodedClaim bool `json:"decoded_claim"`
|
||||
ExpirationHeight int `json:"expiration_height"`
|
||||
Expired bool `json:"expired"`
|
||||
HasSignature bool `json:"has_signature"`
|
||||
HasSigningKey bool `json:"has_signing_key"`
|
||||
Height int `json:"height"`
|
||||
Hex string `json:"hex"`
|
||||
IsPending bool `json:"is_pending"`
|
||||
IsInternalTransfer bool `json:"is_internal_transfer"`
|
||||
IsMyInput bool `json:"is_my_input"`
|
||||
IsMyOutput bool `json:"is_my_output"`
|
||||
IsSpent bool `json:"is_spent"`
|
||||
Name string `json:"name"`
|
||||
Nout int `json:"nout"`
|
||||
NormalizedName string `json:"normalized_name"`
|
||||
Nout uint64 `json:"nout"`
|
||||
PermanentUrl string `json:"permanent_url"`
|
||||
TimeStamp uint64 `json:"time_stamp"`
|
||||
Protobuf string `json:"protobuf,omitempty"`
|
||||
Txid string `json:"txid"`
|
||||
Value *lbryschema.Claim `json:"value"`
|
||||
Type string `json:"type"`
|
||||
Value *lbryschema.Claim `json:"protobuf"`
|
||||
}
|
||||
|
||||
type ChannelListResponse []ChannelListSingleResponse
|
||||
|
||||
type WalletListResponse []string
|
||||
|
||||
type PublishResponse struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
Fee decimal.Decimal `json:"fee"`
|
||||
Nout int `json:"nout"`
|
||||
Tx string `json:"tx"`
|
||||
Txid string `json:"txid"`
|
||||
type TransactionSummary struct {
|
||||
Height int `json:"height"`
|
||||
Hex string `json:"hex"`
|
||||
Inputs []Transaction `json:"inputs"`
|
||||
Outputs []Transaction `json:"outputs"`
|
||||
TotalFee string `json:"total_fee"`
|
||||
TotalOutput string `json:"total_output"`
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
|
||||
type BlobAnnounceResponse bool
|
||||
type AccountFundResponse TransactionSummary
|
||||
|
||||
type WalletPrefillAddressesResponse struct {
|
||||
Broadcast bool `json:"broadcast"`
|
||||
Complete bool `json:"complete"`
|
||||
Hex string `json:"hex"`
|
||||
type Address string
|
||||
type AddressUnusedResponse Address
|
||||
type AddressListResponse struct {
|
||||
Items []struct {
|
||||
Account string `json:"account"`
|
||||
Address Address `json:"address"`
|
||||
Pubkey string `json:"pubkey"`
|
||||
UsedTimes uint64 `json:"used_times"`
|
||||
} `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
|
||||
type UTXOListResponse []struct {
|
||||
Address string `json:"address"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
Height int `json:"height"`
|
||||
IsClaim bool `json:"is_claim"`
|
||||
IsCoinbase bool `json:"is_coinbase"`
|
||||
IsSupport bool `json:"is_support"`
|
||||
IsUpdate bool `json:"is_update"`
|
||||
Nout int `json:"nout"`
|
||||
Txid string `json:"txid"`
|
||||
type ChannelExportResponse string
|
||||
type ChannelImportResponse string
|
||||
|
||||
type ChannelListResponse struct {
|
||||
Items []Transaction `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
|
||||
type WalletNewAddressResponse string
|
||||
type ClaimAbandonResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Tx TransactionSummary `json:"tx"`
|
||||
}
|
||||
type Support struct {
|
||||
Amount string `json:"amount"`
|
||||
Nout uint64 `json:"nout"`
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
|
||||
type WalletUnusedAddressResponse string
|
||||
type PurchaseReceipt struct {
|
||||
Address string `json:"file_name"`
|
||||
Amount string `json:"amount"`
|
||||
ClaimID string `json:"claim_id"`
|
||||
Confirmations int `json:"confirmations"`
|
||||
Height int `json:"height"`
|
||||
Nout uint64 `json:"nout"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
Txid string `json:"txid"`
|
||||
Type string `json:"purchase"`
|
||||
}
|
||||
|
||||
type NumClaimsInChannelResponse map[string]struct {
|
||||
ClaimsInChannel uint64 `json:"claims_in_channel,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
type Claim struct {
|
||||
Address string `json:"address"`
|
||||
Amount string `json:"amount"`
|
||||
CanonicalURL string `json:"canonical_url"`
|
||||
ClaimID string `json:"claim_id"`
|
||||
ClaimOp string `json:"claim_op,omitempty"`
|
||||
Confirmations int `json:"confirmations"`
|
||||
Height int `json:"height"`
|
||||
IsChange bool `json:"is_change,omitempty"`
|
||||
IsChannelSignatureValid bool `json:"is_channel_signature_valid,omitempty"`
|
||||
IsInternalTransfer bool `json:"is_internal_transfer"`
|
||||
IsMyInput bool `json:"is_my_input"`
|
||||
IsMyOutput bool `json:"is_my_output"`
|
||||
IsSpent bool `json:"is_spent"`
|
||||
Meta Meta `json:"meta,omitempty"`
|
||||
Name string `json:"name"`
|
||||
NormalizedName string `json:"normalized_name"`
|
||||
Nout uint64 `json:"nout"`
|
||||
PermanentURL string `json:"permanent_url"`
|
||||
PurchaseReceipt *PurchaseReceipt `json:"purchase_receipt,omitempty"`
|
||||
ShortURL string `json:"short_url"`
|
||||
SigningChannel *Claim `json:"signing_channel,omitempty"`
|
||||
Timestamp int `json:"timestamp"`
|
||||
Txid string `json:"txid"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Value lbryschema.Claim `json:"protobuf,omitempty"`
|
||||
ValueType string `json:"value_type,omitempty"`
|
||||
AbsoluteChannelPosition int `json:"absolute_channel_position,omitempty"`
|
||||
ChannelName string `json:"channel_name,omitempty"`
|
||||
ClaimSequence int64 `json:"claim_sequence,omitempty"`
|
||||
DecodedClaim bool `json:"decoded_claim,omitempty"`
|
||||
EffectiveAmount string `json:"effective_amount,omitempty"`
|
||||
HasSignature *bool `json:"has_signature,omitempty"`
|
||||
SignatureIsValid *bool `json:"signature_is_valid,omitempty"`
|
||||
Supports []Support `json:"supports,omitempty"`
|
||||
ValidAtHeight int `json:"valid_at_height,omitempty"`
|
||||
}
|
||||
|
||||
type Meta struct {
|
||||
ActivationHeight int64 `json:"activation_height,omitempty"`
|
||||
CreationHeight int64 `json:"creation_height,omitempty"`
|
||||
CreationTimestamp int `json:"creation_timestamp,omitempty"`
|
||||
EffectiveAmount string `json:"effective_amount,omitempty"`
|
||||
ExpirationHeight int64 `json:"expiration_height,omitempty"`
|
||||
IsControlling bool `json:"is_controlling,omitempty"`
|
||||
SupportAmount string `json:"support_amount,omitempty"`
|
||||
TrendingGlobal float64 `json:"trending_global,omitempty"`
|
||||
TrendingGroup float64 `json:"trending_group,omitempty"`
|
||||
TrendingLocal float64 `json:"trending_local,omitempty"`
|
||||
TrendingMixed float64 `json:"trending_mixed,omitempty"`
|
||||
}
|
||||
|
||||
const reflectorURL = "http://blobs.lbry.io/"
|
||||
|
||||
// GetStreamSizeByMagic uses "magic" to not just estimate, but actually return the exact size of a stream
|
||||
// It does so by fetching the sd blob and the last blob from our S3 bucket, decrypting and unpadding the last blob
|
||||
// adding up all full blobs that have a known size and finally adding the real last blob size too.
|
||||
// This will only work if we host at least the sd blob and the last blob on S3, if not, this will error.
|
||||
func (c *Claim) GetStreamSizeByMagic() (streamSize uint64, e error) {
|
||||
if c.Value.GetStream() == nil {
|
||||
return 0, errors.Err("this claim is not a stream")
|
||||
}
|
||||
resp, err := http.Get(reflectorURL + hex.EncodeToString(c.Value.GetStream().Source.SdHash))
|
||||
if err != nil {
|
||||
return 0, errors.Err(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return 0, errors.Err(err)
|
||||
}
|
||||
sdb := &stream.SDBlob{}
|
||||
err = sdb.UnmarshalJSON(body)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
lastBlobIndex := len(sdb.BlobInfos) - 2
|
||||
lastBlobHash := sdb.BlobInfos[lastBlobIndex].BlobHash
|
||||
|
||||
if len(sdb.BlobInfos) > 2 {
|
||||
streamSize = uint64(stream.MaxBlobSize-1) * uint64(len(sdb.BlobInfos)-2)
|
||||
}
|
||||
|
||||
resp2, err := http.Get(reflectorURL + hex.EncodeToString(lastBlobHash))
|
||||
if err != nil {
|
||||
return 0, errors.Err(err)
|
||||
}
|
||||
defer resp2.Body.Close()
|
||||
|
||||
body2, err := ioutil.ReadAll(resp2.Body)
|
||||
if err != nil {
|
||||
return 0, errors.Err(err)
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
e = errors.Err("recovered from DecryptBlob panic for blob %s", lastBlobHash)
|
||||
}
|
||||
}()
|
||||
lastBlob, err := stream.DecryptBlob(body2, sdb.Key, sdb.BlobInfos[lastBlobIndex].IV)
|
||||
if err != nil {
|
||||
return 0, errors.Err(err)
|
||||
}
|
||||
|
||||
streamSize += uint64(len(lastBlob))
|
||||
return streamSize, nil
|
||||
}
|
||||
|
||||
type StreamListResponse struct {
|
||||
Items []Claim `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
|
||||
type ClaimListResponse struct {
|
||||
Claims []Claim `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
type ClaimSearchResponse ClaimListResponse
|
||||
|
||||
type SupportListResponse struct {
|
||||
Items []Claim
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
|
||||
type StatusResponse struct {
|
||||
BlobManager struct {
|
||||
Connections struct {
|
||||
MaxIncomingMbs float64 `json:"max_incoming_mbs"`
|
||||
MaxOutgoingMbs float64 `json:"max_outgoing_mbs"`
|
||||
TotalIncomingMbs float64 `json:"total_incoming_mbs"`
|
||||
TotalOutgoingMbs float64 `json:"total_outgoing_mbs"`
|
||||
TotalReceived int64 `json:"total_received"`
|
||||
TotalSent int64 `json:"total_sent"`
|
||||
} `json:"connections"`
|
||||
FinishedBlobs int64 `json:"finished_blobs"`
|
||||
} `json:"blob_manager"`
|
||||
ConnectionStatus struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"connection_status"`
|
||||
Dht struct {
|
||||
NodeID string `json:"node_id"`
|
||||
PeersInRoutingTable uint64 `json:"peers_in_routing_table"`
|
||||
} `json:"dht"`
|
||||
FfmpegStatus struct {
|
||||
AnalyzeAudioVolume bool `json:"analyze_audio_volume"`
|
||||
Available bool `json:"available"`
|
||||
Which string `json:"which"`
|
||||
} `json:"ffmpeg_status"`
|
||||
FileManager struct {
|
||||
ManagedFiles int64 `json:"managed_files"`
|
||||
} `json:"file_manager"`
|
||||
HashAnnouncer struct {
|
||||
AnnounceQueueSize uint64 `json:"announce_queue_size"`
|
||||
} `json:"hash_announcer"`
|
||||
InstallationID string `json:"installation_id"`
|
||||
IsRunning bool `json:"is_running"`
|
||||
SkippedComponents []string `json:"skipped_components"`
|
||||
StartupStatus struct {
|
||||
BlobManager bool `json:"blob_manager"`
|
||||
Database bool `json:"database"`
|
||||
Dht bool `json:"dht"`
|
||||
ExchangeRateManager bool `json:"exchange_rate_manager"`
|
||||
FileManager bool `json:"file_manager"`
|
||||
HashAnnouncer bool `json:"hash_announcer"`
|
||||
LibtorrentComponent bool `json:"libtorrent_component"`
|
||||
PeerProtocolServer bool `json:"peer_protocol_server"`
|
||||
Upnp bool `json:"upnp"`
|
||||
Wallet bool `json:"wallet"`
|
||||
WalletServerPayments bool `json:"wallet_server_payments"`
|
||||
} `json:"startup_status"`
|
||||
Upnp struct {
|
||||
AioupnpVersion string `json:"aioupnp_version"`
|
||||
DhtRedirectSet bool `json:"dht_redirect_set"`
|
||||
ExternalIp string `json:"external_ip"`
|
||||
Gateway string `json:"gateway"`
|
||||
PeerRedirectSet bool `json:"peer_redirect_set"`
|
||||
Redirects struct{} `json:"redirects"`
|
||||
} `json:"upnp"`
|
||||
Wallet struct {
|
||||
AvailableServers int `json:"available_servers"`
|
||||
BestBlockhash string `json:"best_blockhash"`
|
||||
Blocks int `json:"blocks"`
|
||||
BlocksBehind int `json:"blocks_behind"`
|
||||
Connected string `json:"connected"`
|
||||
ConnectedFeatures struct {
|
||||
DailyFee string `json:"daily_fee"`
|
||||
Description string `json:"description"`
|
||||
DonationAddress string `json:"donation_address"`
|
||||
GenesisHash string `json:"genesis_hash"`
|
||||
HashFunction string `json:"hash_function"`
|
||||
Hosts struct {
|
||||
} `json:"hosts"`
|
||||
PaymentAddress string `json:"payment_address"`
|
||||
ProtocolMax string `json:"protocol_max"`
|
||||
ProtocolMin string `json:"protocol_min"`
|
||||
Pruning interface{} `json:"pruning"`
|
||||
ServerVersion string `json:"server_version"`
|
||||
TrendingAlgorithm string `json:"trending_algorithm"`
|
||||
} `json:"connected_features"`
|
||||
HeadersSynchronizationProgress int `json:"headers_synchronization_progress"`
|
||||
KnownServers int `json:"known_servers"`
|
||||
Servers []struct {
|
||||
Availability bool `json:"availability"`
|
||||
Host string `json:"host"`
|
||||
Latency float64 `json:"latency"`
|
||||
Port int `json:"port"`
|
||||
} `json:"servers"`
|
||||
} `json:"wallet"`
|
||||
WalletServerPayments struct {
|
||||
MaxFee string `json:"max_fee"`
|
||||
Running bool `json:"running"`
|
||||
} `json:"wallet_server_payments"`
|
||||
}
|
||||
|
||||
type UTXOListResponse struct {
|
||||
Items []struct {
|
||||
Address string `json:"address"`
|
||||
Amount string `json:"amount"`
|
||||
Confirmations int `json:"confirmations"`
|
||||
Height int `json:"height"`
|
||||
IsInternalTransfer bool `json:"is_internal_transfer"`
|
||||
IsMyInput bool `json:"is_my_input"`
|
||||
IsMyOutput bool `json:"is_my_output"`
|
||||
IsSpent bool `json:"is_spent"`
|
||||
Nout int `json:"nout"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Txid string `json:"txid"`
|
||||
Type string `json:"type"`
|
||||
} `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
|
||||
type UTXOReleaseResponse *string
|
||||
|
||||
type transactionListBlob struct {
|
||||
Address string `json:"address"`
|
||||
Amount string `json:"amount"`
|
||||
BalanceDelta string `json:"balance_delta"`
|
||||
ClaimId string `json:"claim_id"`
|
||||
ClaimName string `json:"claim_name"`
|
||||
IsSpent bool `json:"is_spent"`
|
||||
Nout int `json:"nout"`
|
||||
}
|
||||
|
||||
//TODO: this repeats all the fields from transactionListBlob which doesn't make sense
|
||||
// but if i extend the type with transactionListBlob it doesn't fill the fields. does our unmarshaller crap out on these?
|
||||
type supportBlob struct {
|
||||
Address string `json:"address"`
|
||||
Amount string `json:"amount"`
|
||||
BalanceDelta string `json:"balance_delta"`
|
||||
ClaimId string `json:"claim_id"`
|
||||
ClaimName string `json:"claim_name"`
|
||||
IsSpent bool `json:"is_spent"`
|
||||
IsTip bool `json:"is_tip"`
|
||||
Nout int `json:"nout"`
|
||||
}
|
||||
|
||||
type TransactionListResponse struct {
|
||||
Items []struct {
|
||||
AbandonInfo []transactionListBlob `json:"abandon_info"`
|
||||
ClaimInfo []transactionListBlob `json:"claim_info"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
Date string `json:"date"`
|
||||
Fee string `json:"fee"`
|
||||
SupportInfo []supportBlob `json:"support_info"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Txid string `json:"txid"`
|
||||
UpdateInfo []transactionListBlob `json:"update_info"`
|
||||
Value string `json:"value"`
|
||||
} `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
|
||||
type VersionResponse struct {
|
||||
Build string `json:"build"`
|
||||
Desktop string `json:"desktop"`
|
||||
Distro struct {
|
||||
Codename string `json:"codename"`
|
||||
ID string `json:"id"`
|
||||
Like string `json:"like"`
|
||||
Version string `json:"version"`
|
||||
VersionParts struct {
|
||||
BuildNumber string `json:"build_number"`
|
||||
Major string `json:"major"`
|
||||
Minor string `json:"minor"`
|
||||
} `json:"version_parts"`
|
||||
} `json:"distro"`
|
||||
LbrynetVersion string `json:"lbrynet_version"`
|
||||
OsRelease string `json:"os_release"`
|
||||
OsSystem string `json:"os_system"`
|
||||
Platform string `json:"platform"`
|
||||
Processor string `json:"processor"`
|
||||
PythonVersion string `json:"python_version"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type ResolveResponse map[string]Claim
|
||||
|
||||
type ClaimShowResponse *Claim
|
||||
|
||||
type Wallet struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type WalletList struct {
|
||||
Items []Wallet `json:"items"`
|
||||
Page uint64 `json:"page"`
|
||||
PageSize uint64 `json:"page_size"`
|
||||
TotalPages uint64 `json:"total_pages"`
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package lbryinc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultServerAddress = "https://api.lbry.com"
|
||||
timeout = 5 * time.Second
|
||||
headerForwardedFor = "X-Forwarded-For"
|
||||
|
||||
userObjectPath = "user"
|
||||
userMeMethod = "me"
|
||||
userHasVerifiedEmailMethod = "has_verified_email"
|
||||
)
|
||||
|
||||
// Client stores data about internal-apis call it is about to make.
|
||||
type Client struct {
|
||||
AuthToken string
|
||||
Logger *log.Logger
|
||||
serverAddress string
|
||||
extraHeaders map[string]string
|
||||
}
|
||||
|
||||
// ClientOpts allow to provide extra parameters to NewClient:
|
||||
// - ServerAddress
|
||||
// - RemoteIP — to forward the IP of a frontend client making the request
|
||||
type ClientOpts struct {
|
||||
ServerAddress string
|
||||
RemoteIP string
|
||||
}
|
||||
|
||||
// APIResponse reflects internal-apis JSON response format.
|
||||
type APIResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Error *string `json:"error"`
|
||||
Data *ResponseData `json:"data"`
|
||||
}
|
||||
|
||||
// ResponseData is a map containing parsed json response.
|
||||
type ResponseData map[string]interface{}
|
||||
|
||||
func makeMethodPath(obj, method string) string {
|
||||
return fmt.Sprintf("/%s/%s", obj, method)
|
||||
}
|
||||
|
||||
// NewClient returns a client instance for internal-apis. It requires authToken to be provided
|
||||
// for authentication.
|
||||
func NewClient(authToken string, opts *ClientOpts) Client {
|
||||
c := Client{
|
||||
serverAddress: defaultServerAddress,
|
||||
extraHeaders: make(map[string]string),
|
||||
AuthToken: authToken,
|
||||
Logger: log.StandardLogger(),
|
||||
}
|
||||
if opts != nil {
|
||||
if opts.ServerAddress != "" {
|
||||
c.serverAddress = opts.ServerAddress
|
||||
}
|
||||
if opts.RemoteIP != "" {
|
||||
c.extraHeaders[headerForwardedFor] = opts.RemoteIP
|
||||
}
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Client) getEndpointURL(object, method string) string {
|
||||
return fmt.Sprintf("%s%s", c.serverAddress, makeMethodPath(object, method))
|
||||
}
|
||||
|
||||
func (c Client) prepareParams(params map[string]interface{}) (string, error) {
|
||||
form := url.Values{}
|
||||
form.Add("auth_token", c.AuthToken)
|
||||
for k, v := range params {
|
||||
if k == "auth_token" {
|
||||
return "", errors.New("extra auth_token supplied in request params")
|
||||
}
|
||||
form.Add(k, fmt.Sprintf("%v", v))
|
||||
}
|
||||
return form.Encode(), nil
|
||||
}
|
||||
|
||||
func (c Client) doCall(url string, payload string) ([]byte, error) {
|
||||
var body []byte
|
||||
c.Logger.Debugf("sending payload: %s", payload)
|
||||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer([]byte(payload)))
|
||||
if err != nil {
|
||||
return body, err
|
||||
}
|
||||
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
for k, v := range c.extraHeaders {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
|
||||
client := &http.Client{Timeout: timeout}
|
||||
r, err := client.Do(req)
|
||||
if err != nil {
|
||||
return body, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
return ioutil.ReadAll(r.Body)
|
||||
}
|
||||
|
||||
// Call calls a remote internal-apis server, returning a response,
|
||||
// wrapped into standardized API Response struct.
|
||||
func (c Client) Call(object, method string, params map[string]interface{}) (ResponseData, error) {
|
||||
var rd ResponseData
|
||||
payload, err := c.prepareParams(params)
|
||||
if err != nil {
|
||||
return rd, err
|
||||
}
|
||||
|
||||
body, err := c.doCall(c.getEndpointURL(object, method), payload)
|
||||
if err != nil {
|
||||
return rd, err
|
||||
}
|
||||
var ar APIResponse
|
||||
err = json.Unmarshal(body, &ar)
|
||||
if err != nil {
|
||||
return rd, err
|
||||
}
|
||||
if !ar.Success {
|
||||
return rd, errors.New(*ar.Error)
|
||||
}
|
||||
return *ar.Data, err
|
||||
}
|
||||
|
||||
// UserMe returns user details for the user associated with the current auth_token
|
||||
func (c Client) UserMe() (ResponseData, error) {
|
||||
return c.Call(userObjectPath, userMeMethod, map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (c Client) UserHasVerifiedEmail() (ResponseData, error) {
|
||||
return c.Call(userObjectPath, userHasVerifiedEmailMethod, map[string]interface{}{})
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package lbryinc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUserMeWrongToken(t *testing.T) {
|
||||
c := NewClient("abc", nil)
|
||||
r, err := c.UserMe()
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "could not authenticate user", err.Error())
|
||||
assert.Nil(t, r)
|
||||
}
|
||||
|
||||
func TestUserHasVerifiedEmailWrongToken(t *testing.T) {
|
||||
c := NewClient("abc", nil)
|
||||
r, err := c.UserHasVerifiedEmail()
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "could not authenticate user", err.Error())
|
||||
assert.Nil(t, r)
|
||||
}
|
||||
|
||||
func launchDummyServer(lastReq **http.Request, path, response string) *httptest.Server {
|
||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
*lastReq = &*r
|
||||
if r.URL.Path != path {
|
||||
fmt.Printf("path doesn't match: %v != %v", r.URL.Path, path)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
} else {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(response))
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
func TestUserMe(t *testing.T) {
|
||||
var req *http.Request
|
||||
ts := launchDummyServer(&req, makeMethodPath(userObjectPath, userMeMethod), userMeResponse)
|
||||
defer ts.Close()
|
||||
|
||||
c := NewClient("realToken", &ClientOpts{ServerAddress: ts.URL})
|
||||
r, err := c.UserMe()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "user@lbry.tv", r["primary_email"])
|
||||
}
|
||||
|
||||
func TestUserHasVerifiedEmail(t *testing.T) {
|
||||
var req *http.Request
|
||||
ts := launchDummyServer(&req, makeMethodPath(userObjectPath, userHasVerifiedEmailMethod), userHasVerifiedEmailResponse)
|
||||
defer ts.Close()
|
||||
|
||||
c := NewClient("realToken", &ClientOpts{ServerAddress: ts.URL})
|
||||
r, err := c.UserHasVerifiedEmail()
|
||||
assert.Nil(t, err)
|
||||
assert.EqualValues(t, 12345, r["user_id"])
|
||||
assert.Equal(t, true, r["has_verified_email"])
|
||||
}
|
||||
|
||||
func TestRemoteIP(t *testing.T) {
|
||||
var req *http.Request
|
||||
ts := launchDummyServer(&req, makeMethodPath(userObjectPath, userMeMethod), userMeResponse)
|
||||
defer ts.Close()
|
||||
|
||||
c := NewClient("realToken", &ClientOpts{ServerAddress: ts.URL, RemoteIP: "8.8.8.8"})
|
||||
_, err := c.UserMe()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"8.8.8.8"}, req.Header["X-Forwarded-For"])
|
||||
}
|
||||
|
||||
const userMeResponse = `{
|
||||
"success": true,
|
||||
"error": null,
|
||||
"data": {
|
||||
"id": 12345,
|
||||
"language": "en",
|
||||
"given_name": null,
|
||||
"family_name": null,
|
||||
"created_at": "2019-01-17T12:13:06Z",
|
||||
"updated_at": "2019-05-02T13:57:59Z",
|
||||
"invited_by_id": null,
|
||||
"invited_at": null,
|
||||
"invites_remaining": 0,
|
||||
"invite_reward_claimed": false,
|
||||
"is_email_enabled": true,
|
||||
"manual_approval_user_id": 654,
|
||||
"reward_status_change_trigger": "manual",
|
||||
"primary_email": "user@lbry.tv",
|
||||
"has_verified_email": true,
|
||||
"is_identity_verified": false,
|
||||
"is_reward_approved": true,
|
||||
"groups": []
|
||||
}
|
||||
}`
|
||||
|
||||
const userHasVerifiedEmailResponse = `{
|
||||
"success": true,
|
||||
"error": null,
|
||||
"data": {
|
||||
"user_id": 12345,
|
||||
"has_verified_email": true
|
||||
}
|
||||
}`
|
||||
@@ -0,0 +1,301 @@
|
||||
package orderedmap
|
||||
|
||||
// mostly from https://github.com/iancoleman/orderedmap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
)
|
||||
|
||||
type keyIndex struct {
|
||||
Key string
|
||||
Index int
|
||||
}
|
||||
|
||||
type byIndex []keyIndex
|
||||
|
||||
func (a byIndex) Len() int { return len(a) }
|
||||
func (a byIndex) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a byIndex) Less(i, j int) bool { return a[i].Index < a[j].Index }
|
||||
|
||||
type Map struct {
|
||||
l sync.RWMutex
|
||||
keys []string
|
||||
values map[string]interface{}
|
||||
}
|
||||
|
||||
func New() *Map {
|
||||
o := Map{}
|
||||
o.l = sync.RWMutex{}
|
||||
o.keys = []string{}
|
||||
o.values = map[string]interface{}{}
|
||||
return &o
|
||||
}
|
||||
|
||||
func (o *Map) Get(key string) (interface{}, bool) {
|
||||
o.l.RLock()
|
||||
defer o.l.RUnlock()
|
||||
val, exists := o.values[key]
|
||||
return val, exists
|
||||
}
|
||||
|
||||
func (o *Map) Set(key string, value interface{}) {
|
||||
o.l.Lock()
|
||||
defer o.l.Unlock()
|
||||
_, exists := o.values[key]
|
||||
if !exists {
|
||||
o.keys = append(o.keys, key)
|
||||
}
|
||||
o.values[key] = value
|
||||
}
|
||||
|
||||
const outOfRange = "position value %d is outside of the range %d - %d"
|
||||
|
||||
//InsertAt This is a zero based position index: 0,1,2,3..n(from left) OR -1,-2,-3...-n(from right) where -1 is the last place.
|
||||
func (o *Map) InsertAt(key string, value interface{}, position int) error {
|
||||
o.l.Lock()
|
||||
defer o.l.Unlock()
|
||||
var index = position
|
||||
if position < 0 {
|
||||
// support indexing from the back: -1 = last in array.
|
||||
index += len(o.keys) + 1
|
||||
if index < 0 || index > len(o.keys) {
|
||||
return errors.Err(fmt.Sprintf(outOfRange, position, len(o.keys), len(o.keys)-1))
|
||||
}
|
||||
} else if index > len(o.keys) {
|
||||
return errors.Err(fmt.Sprintf(outOfRange, position, len(o.keys), len(o.keys)-1))
|
||||
}
|
||||
_, exists := o.values[key]
|
||||
if !exists {
|
||||
// left + key + right
|
||||
o.keys = append(o.keys[0:index], append([]string{key}, o.keys[index:]...)...)
|
||||
}
|
||||
o.values[key] = value
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Map) Prepend(key string, value interface{}) {
|
||||
o.l.Lock()
|
||||
defer o.l.Unlock()
|
||||
_, exists := o.values[key]
|
||||
if !exists {
|
||||
o.keys = append([]string{key}, o.keys...)
|
||||
}
|
||||
o.values[key] = value
|
||||
}
|
||||
|
||||
func (o *Map) Delete(key string) {
|
||||
o.l.Lock()
|
||||
defer o.l.Unlock()
|
||||
// check key is in use
|
||||
_, ok := o.values[key]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
// remove from keys
|
||||
for i, k := range o.keys {
|
||||
if k == key {
|
||||
o.keys = append(o.keys[:i], o.keys[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
// remove from values
|
||||
delete(o.values, key)
|
||||
}
|
||||
|
||||
func (o *Map) Keys() []string {
|
||||
o.l.RLock()
|
||||
defer o.l.RUnlock()
|
||||
return o.keys
|
||||
}
|
||||
|
||||
func (o *Map) UnmarshalJSON(b []byte) error {
|
||||
o.l.Lock()
|
||||
defer o.l.Unlock()
|
||||
m := map[string]interface{}{}
|
||||
if err := json.Unmarshal(b, &m); err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
s := string(b)
|
||||
mapToOrderedMap(o, s, m)
|
||||
return nil
|
||||
}
|
||||
|
||||
func mapToOrderedMap(o *Map, s string, m map[string]interface{}) {
|
||||
// Get the order of the keys
|
||||
orderedKeys := []keyIndex{}
|
||||
for k := range m {
|
||||
kEscaped := strings.Replace(k, `"`, `\"`, -1)
|
||||
kQuoted := `"` + kEscaped + `"`
|
||||
// Find how much content exists before this key.
|
||||
// If all content from this key and after is replaced with a close
|
||||
// brace, it should still form a valid json string.
|
||||
sTrimmed := s
|
||||
for len(sTrimmed) > 0 {
|
||||
lastIndex := strings.LastIndex(sTrimmed, kQuoted)
|
||||
if lastIndex == -1 {
|
||||
break
|
||||
}
|
||||
sTrimmed = sTrimmed[0:lastIndex]
|
||||
sTrimmed = strings.TrimSpace(sTrimmed)
|
||||
if len(sTrimmed) > 0 && sTrimmed[len(sTrimmed)-1] == ',' {
|
||||
sTrimmed = sTrimmed[0 : len(sTrimmed)-1]
|
||||
}
|
||||
maybeValidJson := sTrimmed + "}"
|
||||
testMap := map[string]interface{}{}
|
||||
err := json.Unmarshal([]byte(maybeValidJson), &testMap)
|
||||
if err == nil {
|
||||
// record the position of this key in s
|
||||
ki := keyIndex{
|
||||
Key: k,
|
||||
Index: len(sTrimmed),
|
||||
}
|
||||
orderedKeys = append(orderedKeys, ki)
|
||||
// shorten the string to get the next key
|
||||
startOfValueIndex := lastIndex + len(kQuoted)
|
||||
valueStr := s[startOfValueIndex : len(s)-1]
|
||||
valueStr = strings.TrimSpace(valueStr)
|
||||
if len(valueStr) > 0 && valueStr[0] == ':' {
|
||||
valueStr = valueStr[1:]
|
||||
}
|
||||
valueStr = strings.TrimSpace(valueStr)
|
||||
if valueStr[0] == '{' {
|
||||
// if the value for this key is a map, convert it to an orderedmap.
|
||||
// find end of valueStr by removing everything after last }
|
||||
// until it forms valid json
|
||||
hasValidJson := false
|
||||
i := 1
|
||||
for i < len(valueStr) && !hasValidJson {
|
||||
if valueStr[i] != '}' {
|
||||
i = i + 1
|
||||
continue
|
||||
}
|
||||
subTestMap := map[string]interface{}{}
|
||||
testValue := valueStr[0 : i+1]
|
||||
err = json.Unmarshal([]byte(testValue), &subTestMap)
|
||||
if err == nil {
|
||||
hasValidJson = true
|
||||
valueStr = testValue
|
||||
break
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
// convert to orderedmap
|
||||
if hasValidJson {
|
||||
mkTyped := m[k].(map[string]interface{})
|
||||
oo := &Map{}
|
||||
mapToOrderedMap(oo, valueStr, mkTyped)
|
||||
m[k] = oo
|
||||
}
|
||||
} else if valueStr[0] == '[' {
|
||||
// if the value for this key is a []interface, convert any map items to an orderedmap.
|
||||
// find end of valueStr by removing everything after last ]
|
||||
// until it forms valid json
|
||||
hasValidJson := false
|
||||
i := 1
|
||||
for i < len(valueStr) && !hasValidJson {
|
||||
if valueStr[i] != ']' {
|
||||
i = i + 1
|
||||
continue
|
||||
}
|
||||
subTestSlice := []interface{}{}
|
||||
testValue := valueStr[0 : i+1]
|
||||
err = json.Unmarshal([]byte(testValue), &subTestSlice)
|
||||
if err == nil {
|
||||
hasValidJson = true
|
||||
valueStr = testValue
|
||||
break
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
if hasValidJson {
|
||||
itemsStr := valueStr[1 : len(valueStr)-1]
|
||||
// get next item in the slice
|
||||
itemIndex := 0
|
||||
startItem := 0
|
||||
endItem := 0
|
||||
for endItem < len(itemsStr) {
|
||||
if itemsStr[endItem] != ',' && endItem < len(itemsStr)-1 {
|
||||
endItem = endItem + 1
|
||||
continue
|
||||
}
|
||||
// if this substring compiles to json, it's the next item
|
||||
possibleItemStr := strings.TrimSpace(itemsStr[startItem:endItem])
|
||||
var possibleItem interface{}
|
||||
err = json.Unmarshal([]byte(possibleItemStr), &possibleItem)
|
||||
if err != nil {
|
||||
endItem = endItem + 1
|
||||
continue
|
||||
}
|
||||
// if item is map, convert to orderedmap
|
||||
if possibleItemStr[0] == '{' {
|
||||
mkTyped := m[k].([]interface{})
|
||||
mkiTyped := mkTyped[itemIndex].(map[string]interface{})
|
||||
oo := &Map{}
|
||||
mapToOrderedMap(oo, possibleItemStr, mkiTyped)
|
||||
// replace original map with orderedmap
|
||||
mkTyped[itemIndex] = oo
|
||||
m[k] = mkTyped
|
||||
}
|
||||
// remove this item from itemsStr
|
||||
startItem = endItem + 1
|
||||
endItem = endItem + 1
|
||||
itemIndex = itemIndex + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sort the keys
|
||||
sort.Sort(byIndex(orderedKeys))
|
||||
// Convert sorted keys to string slice
|
||||
k := []string{}
|
||||
for _, ki := range orderedKeys {
|
||||
k = append(k, ki.Key)
|
||||
}
|
||||
// Set the Map values
|
||||
o.values = m
|
||||
o.keys = k
|
||||
}
|
||||
|
||||
func (o *Map) Copy() *Map {
|
||||
new := New()
|
||||
|
||||
for _, k := range o.keys {
|
||||
v, _ := o.Get(k)
|
||||
new.Set(k, v)
|
||||
}
|
||||
|
||||
return new
|
||||
}
|
||||
|
||||
func (o *Map) MarshalJSON() ([]byte, error) {
|
||||
o.l.RLock()
|
||||
defer o.l.RUnlock()
|
||||
s := "{"
|
||||
for _, k := range o.keys {
|
||||
// add key
|
||||
kEscaped := strings.Replace(k, `"`, `\"`, -1)
|
||||
s = s + `"` + kEscaped + `":`
|
||||
// add value
|
||||
v := o.values[k]
|
||||
vBytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return []byte{}, errors.Err(err)
|
||||
}
|
||||
s = s + string(vBytes) + ","
|
||||
}
|
||||
if len(o.keys) > 0 {
|
||||
s = s[0 : len(s)-1]
|
||||
}
|
||||
s = s + "}"
|
||||
return []byte(s), nil
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
package orderedmap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func TestOrderedMap(t *testing.T) {
|
||||
o := New()
|
||||
// number
|
||||
o.Set("number", 3)
|
||||
v, _ := o.Get("number")
|
||||
if v.(int) != 3 {
|
||||
t.Error("Set number")
|
||||
}
|
||||
// string
|
||||
o.Set("string", "x")
|
||||
v, _ = o.Get("string")
|
||||
if v.(string) != "x" {
|
||||
t.Error("Set string")
|
||||
}
|
||||
// string slice
|
||||
o.Set("strings", []string{
|
||||
"t",
|
||||
"u",
|
||||
})
|
||||
v, _ = o.Get("strings")
|
||||
if v.([]string)[0] != "t" {
|
||||
t.Error("Set strings first index")
|
||||
}
|
||||
if v.([]string)[1] != "u" {
|
||||
t.Error("Set strings second index")
|
||||
}
|
||||
// mixed slice
|
||||
o.Set("mixed", []interface{}{
|
||||
1,
|
||||
"1",
|
||||
})
|
||||
v, _ = o.Get("mixed")
|
||||
if v.([]interface{})[0].(int) != 1 {
|
||||
t.Error("Set mixed int")
|
||||
}
|
||||
if v.([]interface{})[1].(string) != "1" {
|
||||
t.Error("Set mixed string")
|
||||
}
|
||||
// overriding existing key
|
||||
o.Set("number", 4)
|
||||
v, _ = o.Get("number")
|
||||
if v.(int) != 4 {
|
||||
t.Error("Override existing key")
|
||||
}
|
||||
// Keys method
|
||||
keys := o.Keys()
|
||||
expectedKeys := []string{
|
||||
"number",
|
||||
"string",
|
||||
"strings",
|
||||
"mixed",
|
||||
}
|
||||
for i := range keys {
|
||||
if keys[i] != expectedKeys[i] {
|
||||
t.Error("Keys method", keys[i], "!=", expectedKeys[i])
|
||||
}
|
||||
}
|
||||
for i := range expectedKeys {
|
||||
if keys[i] != expectedKeys[i] {
|
||||
t.Error("Keys method", keys[i], "!=", expectedKeys[i])
|
||||
}
|
||||
}
|
||||
// delete
|
||||
o.Delete("strings")
|
||||
o.Delete("not a key being used")
|
||||
if len(o.Keys()) != 3 {
|
||||
t.Error("Delete method")
|
||||
}
|
||||
_, ok := o.Get("strings")
|
||||
if ok {
|
||||
t.Error("Delete did not remove 'strings' key")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlankMarshalJSON(t *testing.T) {
|
||||
o := New()
|
||||
// blank map
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
t.Error("Marshalling blank map to json", err)
|
||||
}
|
||||
s := string(b)
|
||||
// check json is correctly ordered
|
||||
if s != `{}` {
|
||||
t.Error("JSON Marshaling blank map value is incorrect", s)
|
||||
}
|
||||
// convert to indented json
|
||||
bi, err := json.MarshalIndent(o, "", " ")
|
||||
if err != nil {
|
||||
t.Error("Marshalling indented json for blank map", err)
|
||||
}
|
||||
si := string(bi)
|
||||
ei := `{}`
|
||||
if si != ei {
|
||||
fmt.Println(ei)
|
||||
fmt.Println(si)
|
||||
t.Error("JSON MarshalIndent blank map value is incorrect", si)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalJSON(t *testing.T) {
|
||||
o := New()
|
||||
// number
|
||||
o.Set("number", 3)
|
||||
// string
|
||||
o.Set("string", "x")
|
||||
// new value keeps key in old position
|
||||
o.Set("number", 4)
|
||||
// keys not sorted alphabetically
|
||||
o.Set("z", 1)
|
||||
o.Set("a", 2)
|
||||
o.Set("b", 3)
|
||||
// slice
|
||||
o.Set("slice", []interface{}{
|
||||
"1",
|
||||
1,
|
||||
})
|
||||
// orderedmap
|
||||
v := New()
|
||||
v.Set("e", 1)
|
||||
v.Set("a", 2)
|
||||
o.Set("orderedmap", v)
|
||||
// double quote in key
|
||||
o.Set(`test"ing`, 9)
|
||||
// convert to json
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
t.Error("Marshalling json", err)
|
||||
}
|
||||
s := string(b)
|
||||
// check json is correctly ordered
|
||||
if s != `{"number":4,"string":"x","z":1,"a":2,"b":3,"slice":["1",1],"orderedmap":{"e":1,"a":2},"test\"ing":9}` {
|
||||
t.Error("JSON Marshal value is incorrect", s)
|
||||
}
|
||||
// convert to indented json
|
||||
bi, err := json.MarshalIndent(o, "", " ")
|
||||
if err != nil {
|
||||
t.Error("Marshalling indented json", err)
|
||||
}
|
||||
si := string(bi)
|
||||
ei := `{
|
||||
"number": 4,
|
||||
"string": "x",
|
||||
"z": 1,
|
||||
"a": 2,
|
||||
"b": 3,
|
||||
"slice": [
|
||||
"1",
|
||||
1
|
||||
],
|
||||
"orderedmap": {
|
||||
"e": 1,
|
||||
"a": 2
|
||||
},
|
||||
"test\"ing": 9
|
||||
}`
|
||||
if si != ei {
|
||||
fmt.Println(ei)
|
||||
fmt.Println(si)
|
||||
t.Error("JSON MarshalIndent value is incorrect", si)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalJSON(t *testing.T) {
|
||||
s := `{
|
||||
"number": 4,
|
||||
"string": "x",
|
||||
"z": 1,
|
||||
"a": "should not break with unclosed { character in value",
|
||||
"b": 3,
|
||||
"slice": [
|
||||
"1",
|
||||
1
|
||||
],
|
||||
"orderedmap": {
|
||||
"e": 1,
|
||||
"a { nested key with brace": "with a }}}} }} {{{ brace value",
|
||||
"after": {
|
||||
"link": "test {{{ with even deeper nested braces }"
|
||||
}
|
||||
},
|
||||
"test\"ing": 9,
|
||||
"after": 1,
|
||||
"multitype_array": [
|
||||
"test",
|
||||
1,
|
||||
{ "map": "obj", "it" : 5, ":colon in key": "colon: in value" }
|
||||
],
|
||||
"should not break with { character in key": 1
|
||||
}`
|
||||
o := New()
|
||||
err := json.Unmarshal([]byte(s), &o)
|
||||
if err != nil {
|
||||
t.Error("JSON Unmarshal error", err)
|
||||
}
|
||||
// Check the root keys
|
||||
expectedKeys := []string{
|
||||
"number",
|
||||
"string",
|
||||
"z",
|
||||
"a",
|
||||
"b",
|
||||
"slice",
|
||||
"orderedmap",
|
||||
"test\"ing",
|
||||
"after",
|
||||
"multitype_array",
|
||||
"should not break with { character in key",
|
||||
}
|
||||
k := o.Keys()
|
||||
for i := range k {
|
||||
if k[i] != expectedKeys[i] {
|
||||
t.Error("Unmarshal root key order", i, k[i], "!=", expectedKeys[i])
|
||||
}
|
||||
}
|
||||
// Check nested maps are converted to orderedmaps
|
||||
// nested 1 level deep
|
||||
expectedKeys = []string{
|
||||
"e",
|
||||
"a { nested key with brace",
|
||||
"after",
|
||||
}
|
||||
vi, ok := o.Get("orderedmap")
|
||||
if !ok {
|
||||
t.Error("Missing key for nested map 1 deep")
|
||||
}
|
||||
v := vi.(*Map)
|
||||
k = v.Keys()
|
||||
for i := range k {
|
||||
if k[i] != expectedKeys[i] {
|
||||
t.Error("Key order for nested map 1 deep ", i, k[i], "!=", expectedKeys[i])
|
||||
}
|
||||
}
|
||||
// nested 2 levels deep
|
||||
expectedKeys = []string{
|
||||
"link",
|
||||
}
|
||||
vi, ok = v.Get("after")
|
||||
if !ok {
|
||||
t.Error("Missing key for nested map 2 deep")
|
||||
}
|
||||
v = vi.(*Map)
|
||||
k = v.Keys()
|
||||
for i := range k {
|
||||
if k[i] != expectedKeys[i] {
|
||||
t.Error("Key order for nested map 2 deep", i, k[i], "!=", expectedKeys[i])
|
||||
}
|
||||
}
|
||||
// multitype array
|
||||
expectedKeys = []string{
|
||||
"map",
|
||||
"it",
|
||||
":colon in key",
|
||||
}
|
||||
vislice, ok := o.Get("multitype_array")
|
||||
if !ok {
|
||||
t.Error("Missing key for multitype array")
|
||||
}
|
||||
vslice := vislice.([]interface{})
|
||||
vmap := vslice[2].(*Map)
|
||||
k = vmap.Keys()
|
||||
for i := range k {
|
||||
if k[i] != expectedKeys[i] {
|
||||
t.Error("Key order for nested map 2 deep", i, k[i], "!=", expectedKeys[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalJSONSpecialChars(t *testing.T) {
|
||||
s := `{ " \\\\\\\\\\\\ " : { "\\\\\\" : "\\\\\"\\" }, "\\": " \\\\ test " }`
|
||||
o := New()
|
||||
err := json.Unmarshal([]byte(s), &o)
|
||||
if err != nil {
|
||||
t.Error("JSON Unmarshal error with special chars", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalJSONArrayOfMaps(t *testing.T) {
|
||||
s := `
|
||||
{
|
||||
"name": "test",
|
||||
"percent": 6,
|
||||
"breakdown": [
|
||||
{
|
||||
"name": "a",
|
||||
"percent": 0.9
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"percent": 0.9
|
||||
},
|
||||
{
|
||||
"name": "d",
|
||||
"percent": 0.4
|
||||
},
|
||||
{
|
||||
"name": "e",
|
||||
"percent": 2.7
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
o := New()
|
||||
err := json.Unmarshal([]byte(s), &o)
|
||||
if err != nil {
|
||||
t.Error("JSON Unmarshal error", err)
|
||||
}
|
||||
// Check the root keys
|
||||
expectedKeys := []string{
|
||||
"name",
|
||||
"percent",
|
||||
"breakdown",
|
||||
}
|
||||
k := o.Keys()
|
||||
for i := range k {
|
||||
if k[i] != expectedKeys[i] {
|
||||
t.Error("Unmarshal root key order", i, k[i], "!=", expectedKeys[i])
|
||||
}
|
||||
}
|
||||
// Check nested maps are converted to orderedmaps
|
||||
// nested 1 level deep
|
||||
expectedKeys = []string{
|
||||
"name",
|
||||
"percent",
|
||||
}
|
||||
vi, ok := o.Get("breakdown")
|
||||
if !ok {
|
||||
t.Error("Missing key for nested map 1 deep")
|
||||
}
|
||||
vs := vi.([]interface{})
|
||||
for _, vInterface := range vs {
|
||||
v := vInterface.(*Map)
|
||||
k = v.Keys()
|
||||
for i := range k {
|
||||
if k[i] != expectedKeys[i] {
|
||||
t.Error("Key order for nested map 1 deep ", i, k[i], "!=", expectedKeys[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInsertAt(t *testing.T) {
|
||||
om := New()
|
||||
om.Set("zero", 0)
|
||||
om.Set("one", 1)
|
||||
om.Set("two", 2)
|
||||
|
||||
err := om.InsertAt("TEST", 10000, 4) //3 is this added one in size of map
|
||||
if err == nil {
|
||||
t.Error("expected insert at greater position than size of map to produce error")
|
||||
}
|
||||
|
||||
err = om.InsertAt("A", 100, 2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
// Test it's at end
|
||||
if om.values[om.keys[2]] != 100 {
|
||||
t.Error("expected entry A to be at position 2", om.keys)
|
||||
}
|
||||
if om.values[om.keys[3]] != 2 {
|
||||
t.Error("expected two to be in position 1", om.keys)
|
||||
}
|
||||
|
||||
err = om.InsertAt("B", 200, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if om.values[om.keys[0]] != 200 {
|
||||
t.Error("expected B to be position 0", om.keys)
|
||||
}
|
||||
|
||||
err = om.InsertAt("C", 300, -1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// Should show up at the end
|
||||
if om.values[om.keys[len(om.keys)-1]] != 300 {
|
||||
t.Error(fmt.Sprintf("expected C to be in position %d", len(om.keys)-1), om.keys)
|
||||
}
|
||||
|
||||
err = om.InsertAt("D", 400, 1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if om.values[om.keys[1]] != 400 {
|
||||
t.Error("expceted D to be position 1", om.keys)
|
||||
}
|
||||
|
||||
err = om.InsertAt("F", 600, -8)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if om.values[om.keys[0]] != 600 {
|
||||
t.Error("expected F to be in position 0", om.keys)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcurrency(t *testing.T) {
|
||||
wg := sync.WaitGroup{}
|
||||
type concurrency struct {
|
||||
a string
|
||||
b int
|
||||
c time.Time
|
||||
d bool
|
||||
}
|
||||
|
||||
//Starting Map
|
||||
m := New()
|
||||
m.Set("A", concurrency{"string", 10, time.Now(), true})
|
||||
m.Set("B", concurrency{"string", 10, time.Now(), true})
|
||||
m.Set("C", concurrency{"string", 10, time.Now(), true})
|
||||
m.Set("D", concurrency{"string", 10, time.Now(), true})
|
||||
m.Set("E", concurrency{"string", 10, time.Now(), true})
|
||||
m.Set("F", concurrency{"string", 10, time.Now(), true})
|
||||
m.Set("G", concurrency{"string", 10, time.Now(), true})
|
||||
m.Set("H", concurrency{"string", 10, time.Now(), true})
|
||||
//Inserts
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for i := 0; i < 50; i++ {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
m.Set("New"+strconv.Itoa(index), concurrency{"string", index, time.Now(), cast.ToBool(index % 2)})
|
||||
}(i)
|
||||
}
|
||||
}()
|
||||
//Reads
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for i := 0; i < 50; i++ {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
_, _ = m.Get("New" + strconv.Itoa(rand.Intn(99)))
|
||||
}(i)
|
||||
}
|
||||
}()
|
||||
//Marshalling like endpoint
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
_, err := m.MarshalJSON()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/null"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/null"
|
||||
)
|
||||
|
||||
func InterpolateParams(query string, args ...interface{}) (string, error) {
|
||||
@@ -87,11 +87,11 @@ func InterpolateParams(query string, args ...interface{}) (string, error) {
|
||||
|
||||
// Qs is a shortcut for one group of positional placeholders
|
||||
func Qs(count int) string {
|
||||
return placeholders(false, count, 1, 1)
|
||||
return Placeholders(false, count, 1, 1)
|
||||
}
|
||||
|
||||
// placeholders creates indexed or positional placeholders, in groups, with different starts
|
||||
func placeholders(indexPlaceholders bool, count int, start int, group int) string {
|
||||
func Placeholders(indexPlaceholders bool, count int, start int, group int) string {
|
||||
buf := bytes.Buffer{}
|
||||
|
||||
if start == 0 || group == 0 {
|
||||
|
||||
+8
-3
@@ -101,8 +101,6 @@ func (s *Group) DoneNamed(name string) {
|
||||
|
||||
if s.waitingOn != nil {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if current, ok := s.waitingOn[name]; ok {
|
||||
if current <= 1 {
|
||||
delete(s.waitingOn, name)
|
||||
@@ -112,9 +110,16 @@ func (s *Group) DoneNamed(name string) {
|
||||
} else {
|
||||
log.Printf("%s is not recorded in stop group map", name)
|
||||
}
|
||||
s.mu.Unlock()
|
||||
s.listWaitingOn()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Group) listWaitingOn() {
|
||||
if s.waitingOn != nil {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
log.Printf("-->> LIST ROUTINES WAITING ON")
|
||||
|
||||
for k, v := range s.waitingOn {
|
||||
if v > 0 {
|
||||
log.Printf("waiting on %d %s routines...", v, k)
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"encoding/pem"
|
||||
"net/http"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
)
|
||||
|
||||
func publicKey(isPrivateRepo bool) (*rsa.PublicKey, error) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// mostly copied from github.com/AlekSi/pointer
|
||||
// Provides helpers to get pointers to values of build-in types.
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/null"
|
||||
)
|
||||
|
||||
func PtrToBool(b bool) *bool { return &b }
|
||||
func PtrToByte(b byte) *byte { return &b }
|
||||
func PtrToComplex128(c complex128) *complex128 { return &c }
|
||||
func PtrToComplex64(c complex64) *complex64 { return &c }
|
||||
func PtrToError(e error) *error { return &e }
|
||||
func PtrToFloat32(f float32) *float32 { return &f }
|
||||
func PtrToFloat64(f float64) *float64 { return &f }
|
||||
func PtrToInt(i int) *int { return &i }
|
||||
func PtrToInt16(i int16) *int16 { return &i }
|
||||
func PtrToInt32(i int32) *int32 { return &i }
|
||||
func PtrToInt64(i int64) *int64 { return &i }
|
||||
func PtrToInt8(i int8) *int8 { return &i }
|
||||
func PtrToRune(r rune) *rune { return &r }
|
||||
func PtrToString(s string) *string { return &s }
|
||||
func PtrToTime(t time.Time) *time.Time { return &t }
|
||||
func PtrToUint(u uint) *uint { return &u }
|
||||
func PtrToUint16(u uint16) *uint16 { return &u }
|
||||
func PtrToUint32(u uint32) *uint32 { return &u }
|
||||
func PtrToUint64(u uint64) *uint64 { return &u }
|
||||
func PtrToUint8(u uint8) *uint8 { return &u }
|
||||
func PtrToUintptr(u uintptr) *uintptr { return &u }
|
||||
|
||||
func PtrToNullString(s string) *null.String { n := null.StringFrom(s); return &n }
|
||||
func PtrToNullUint64(u uint64) *null.Uint64 { n := null.Uint64From(u); return &n }
|
||||
func PtrToNullTime(t time.Time) *null.Time { n := null.TimeFrom(t); return &n }
|
||||
func PtrToNullFloat64(f float64) *null.Float64 { n := null.Float64From(f); return &n }
|
||||
func PtrToNullFloat32(f float32) *null.Float32 { n := null.Float32From(f); return &n }
|
||||
|
||||
func StrFromPtr(ptr *string) string {
|
||||
if ptr == nil {
|
||||
return ""
|
||||
}
|
||||
return *ptr
|
||||
}
|
||||
|
||||
func StrFromNull(str null.String) string {
|
||||
if !str.Valid {
|
||||
return ""
|
||||
}
|
||||
return str.String
|
||||
}
|
||||
|
||||
func NullStringFrom(s string) null.String {
|
||||
if s == "" {
|
||||
return null.String{}
|
||||
}
|
||||
return null.StringFrom(s)
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/nlopes/slack"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
@@ -1,51 +1,54 @@
|
||||
module github.com/lbryio/lbry.go
|
||||
module github.com/lbryio/lbry.go/v2
|
||||
|
||||
replace github.com/btcsuite/btcd => github.com/lbryio/lbrycrd.go v0.0.0-20200203050410-e1076f12bf19
|
||||
|
||||
require (
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf // indirect
|
||||
github.com/btcsuite/btcd v0.0.0-20180531025944-86fed781132a
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
|
||||
github.com/btcsuite/btcutil v0.0.0-20180524032703-d4cc87b86016
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
|
||||
github.com/davecgh/go-spew v1.1.0
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
|
||||
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/go-errors/errors v1.0.1
|
||||
github.com/go-ini/ini v1.38.2
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible // indirect
|
||||
github.com/golang/protobuf v1.3.0
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
|
||||
github.com/gorilla/context v1.1.1 // indirect
|
||||
github.com/gorilla/mux v1.6.2
|
||||
github.com/gorilla/rpc v1.1.0
|
||||
github.com/gorilla/websocket v1.2.0 // indirect
|
||||
github.com/jtolds/gls v4.2.1+incompatible // indirect
|
||||
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c
|
||||
github.com/go-ini/ini v1.48.0
|
||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible // indirect
|
||||
github.com/golang/protobuf v1.3.2
|
||||
github.com/google/go-cmp v0.3.1 // indirect
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f // indirect
|
||||
github.com/gorilla/mux v1.7.3
|
||||
github.com/gorilla/rpc v1.2.0
|
||||
github.com/gorilla/websocket v1.4.1 // indirect
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04
|
||||
github.com/lbryio/types v0.0.0-20190304154608-a6f2fd6d5f38
|
||||
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 // indirect
|
||||
github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6 // indirect
|
||||
github.com/lbryio/types v0.0.0-20191009145016-1bb8107e04f8
|
||||
github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5
|
||||
github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675
|
||||
github.com/nlopes/slack v0.5.0
|
||||
github.com/onsi/gomega v1.4.3 // indirect
|
||||
github.com/mitchellh/mapstructure v1.1.2
|
||||
github.com/nlopes/slack v0.6.0
|
||||
github.com/onsi/ginkgo v1.10.2 // indirect
|
||||
github.com/onsi/gomega v1.7.0 // indirect
|
||||
github.com/pkg/errors v0.8.1 // indirect
|
||||
github.com/sebdah/goldie v0.0.0-20180424091453-8784dd1ab561
|
||||
github.com/sebdah/goldie v0.0.0-20190531093107-d313ffb52c77
|
||||
github.com/sergi/go-diff v1.0.0
|
||||
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930
|
||||
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
|
||||
github.com/spf13/cast v1.2.0
|
||||
github.com/stretchr/testify v1.3.0 // indirect
|
||||
github.com/uber-go/atomic v1.3.2
|
||||
github.com/shopspring/decimal v0.0.0-20191009025716-f1972eb1d1f5
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
github.com/smartystreets/assertions v1.0.1 // indirect
|
||||
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
|
||||
github.com/spf13/cast v1.3.0
|
||||
github.com/stretchr/testify v1.4.0
|
||||
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d
|
||||
go.uber.org/atomic v1.3.2 // indirect
|
||||
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
|
||||
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f // indirect
|
||||
google.golang.org/grpc v1.17.0
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
|
||||
gopkg.in/ini.v1 v1.41.0 // indirect
|
||||
go.uber.org/atomic v1.4.0
|
||||
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc
|
||||
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb
|
||||
golang.org/x/sys v0.0.0-20191009170203-06d7bd2c5f4f // indirect
|
||||
golang.org/x/text v0.3.2 // indirect
|
||||
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0
|
||||
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 // indirect
|
||||
google.golang.org/grpc v1.24.0
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/ini.v1 v1.48.0 // indirect
|
||||
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79
|
||||
gopkg.in/yaml.v2 v2.2.4 // indirect
|
||||
gotest.tools v2.2.0+incompatible
|
||||
)
|
||||
|
||||
go 1.13
|
||||
@@ -1,136 +1,179 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/btcsuite/btcd v0.0.0-20180531025944-86fed781132a h1:fuEu3WaOzatbWFGlCa2e/TL/GR397Da8QSKNKrDRa3s=
|
||||
github.com/btcsuite/btcd v0.0.0-20180531025944-86fed781132a/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||
github.com/btcsuite/btcutil v0.0.0-20180524032703-d4cc87b86016 h1:BsZAJgCuMsoFZMZNyj7Lyt6sS8anDhedVrAMCOyPMIo=
|
||||
github.com/btcsuite/btcutil v0.0.0-20180524032703-d4cc87b86016/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
||||
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
|
||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||
github.com/go-ini/ini v1.38.2 h1:6Hl/z3p3iFkA0dlDfzYxuFuUGD+kaweypF6btsR2/Q4=
|
||||
github.com/go-ini/ini v1.38.2/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible h1:sUy/in/P6askYr16XJgTKq/0SZhiWsdg4WZGaLsGQkM=
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
|
||||
github.com/go-ini/ini v1.48.0 h1:TvO60hO/2xgaaTWp2P0wUe4CFxwdMzfbkv3+343Xzqw=
|
||||
github.com/go-ini/ini v1.48.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible h1:msy24VGS42fKO9K1vLz82/GeYW1cILu7Nuuj1N3BBkE=
|
||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk=
|
||||
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
|
||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/rpc v1.1.0 h1:marKfvVP0Gpd/jHlVBKCQ8RAoUPdX7K1Nuh6l1BNh7A=
|
||||
github.com/gorilla/rpc v1.1.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
|
||||
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
|
||||
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f h1:TyqzGm2z1h3AGhjOoRYyeLcW4WlW81MDQkWa+rx/000=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk=
|
||||
github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
|
||||
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
|
||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
|
||||
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c h1:BhdcWGsuKif/XoSZnqVGNqJ1iEmH0czWR5upj+AuR8M=
|
||||
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c/go.mod h1:muH7wpUqE8hRA3OrYYosw9+Sl681BF9cwcjzE+OCNK8=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lbryio/lbrycrd.go v0.0.0-20200203050410-e1076f12bf19 h1:/zWD8dVIl7bV1TdJWqPqy9tpqixzX2Qxgit48h3hQcY=
|
||||
github.com/lbryio/lbrycrd.go v0.0.0-20200203050410-e1076f12bf19/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04 h1:Nze+C2HbeKvhjI/kVn+9Poj/UuEW5sOQxcsxqO7L3GI=
|
||||
github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04/go.mod h1:fbG/dzobG8r95KzMwckXiLMHfFjZaBRQqC9hPs2XAQ4=
|
||||
github.com/lbryio/types v0.0.0-20190304154608-a6f2fd6d5f38 h1:78rErXiBhMjs7vh4Ke3ZMqQjf+pnQeNrkXYmQ8L6aKE=
|
||||
github.com/lbryio/types v0.0.0-20190304154608-a6f2fd6d5f38/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE=
|
||||
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 h1:AsEBgzv3DhuYHI/GiQh2HxvTP71HCCE9E/tzGUzGdtU=
|
||||
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5/go.mod h1:c2mYKRyMb1BPkO5St0c/ps62L4S0W2NAkaTXj9qEI+0=
|
||||
github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6 h1:iOAVXzZyXtW408TMYejlUPo6BIn92HmOacWtIfNyYns=
|
||||
github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6/go.mod h1:sFlOUpQL1YcjhFVXhg1CG8ZASEs/Mf1oVb6H75JL/zg=
|
||||
github.com/lbryio/types v0.0.0-20191009145016-1bb8107e04f8 h1:jSNW/rK6DQsz7Zh+iv1zR384PeQdHt0gS4hKY17tkuM=
|
||||
github.com/lbryio/types v0.0.0-20191009145016-1bb8107e04f8/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE=
|
||||
github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5 h1:mG83tLXWSRdcXMWfkoumVwhcCbf3jHF9QKv/m37BkM0=
|
||||
github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5/go.mod h1:H0aPCWffGOaDcjkw1iB7W9DVLp6GXmfcJY/7YZCWPA4=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675 h1:/rdJjIiKG5rRdwG5yxHmSE/7ZREjpyC0kL7GxGT/qJw=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/nlopes/slack v0.5.0 h1:NbIae8Kd0NpqaEI3iUrsuS0KbcEDhzhc939jLW5fNm0=
|
||||
github.com/nlopes/slack v0.5.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM=
|
||||
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
|
||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA=
|
||||
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.2 h1:uqH7bpe+ERSiDa34FDOF7RikN6RzXgduUF8yarlZp94=
|
||||
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sebdah/goldie v0.0.0-20180424091453-8784dd1ab561 h1:IY+sDBJR/wRtsxq+626xJnt4Tw7/ROA9cDIR8MMhWyg=
|
||||
github.com/sebdah/goldie v0.0.0-20180424091453-8784dd1ab561/go.mod h1:lvjGftC8oe7XPtyrOidaMi0rp5B9+XY/ZRUynGnuaxQ=
|
||||
github.com/sebdah/goldie v0.0.0-20190531093107-d313ffb52c77 h1:Msb6XRY62jQOueNNlB5LGin1rljK7c49NLniGwJG2bg=
|
||||
github.com/sebdah/goldie v0.0.0-20190531093107-d313ffb52c77/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930 h1:pSgp2x9zCkCjb8rxXFNpGE8hDIrt+UXW7jUQ5fbTlzM=
|
||||
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973 h1:3AJZYTzw3gm3TNTt30x0CCKD7GOn2sdd50Hn35fQkGY=
|
||||
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/shopspring/decimal v0.0.0-20191009025716-f1972eb1d1f5 h1:Gojs/hac/DoYEM7WEICT45+hNWczIeuL5D21e5/HPAw=
|
||||
github.com/shopspring/decimal v0.0.0-20191009025716-f1972eb1d1f5/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w=
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
|
||||
github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg=
|
||||
github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
|
||||
github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w=
|
||||
github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/uber-go/atomic v1.3.2 h1:Azu9lPBWRNKzYXSIwRfgRuDuS0YKsK4NFhiQv98gkxo=
|
||||
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d h1:tQo6hjclyv3RHUgZOl6iWb2Y44A/sN9bf9LAYfuioEg=
|
||||
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE=
|
||||
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4 h1:wviDUSmtheHRBfoY8B9U8ELl2USoXi2YFwdGdpIIkzI=
|
||||
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc h1:c0o/qxkaO2LF5t6fQrT4b5hzyggAkLLlCUjqfRxd8Q4=
|
||||
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb h1:TR699M2v0qoKTOHxeLgp6zPqaQNs74f01a/ob9W0qko=
|
||||
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191009170203-06d7bd2c5f4f h1:hjzMYz/7Ea1mNKfOnFOfktR0mlA5jqhvywClCMHM/qw=
|
||||
golang.org/x/sys v0.0.0-20191009170203-06d7bd2c5f4f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w=
|
||||
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f h1:FU37niK8AQ59mHcskRyQL7H0ErSeNh650vdcj8HqdSI=
|
||||
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 h1:4HYDjxeNXAOTv3o1N2tjo8UUSlhQgAD52FVkwxnWgM8=
|
||||
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s=
|
||||
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNjB2u4i700xBkIT4e0=
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
|
||||
gopkg.in/ini.v1 v1.41.0 h1:Ka3ViY6gNYSKiVy71zXBEqKplnV35ImDLVG+8uoIklE=
|
||||
gopkg.in/ini.v1 v1.41.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.48.0 h1:URjZc+8ugRY5mL5uUeQH/a63JcHwdX9xZaWvmNWD7z8=
|
||||
gopkg.in/ini.v1 v1.48.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79 h1:FpCr9V8wuOei4BAen+93HtVJ+XSi+KPbaPKm0Vj5R64=
|
||||
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79/go.mod h1:gWkaRU7CoXpezCBWfWjm3999QqS+1pYPXGbqQCTMzo8=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
+2
-2
@@ -3,7 +3,7 @@ package lbrycrd
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcutil"
|
||||
@@ -34,7 +34,7 @@ func DecodeAddress(addr string, defaultNet *chaincfg.Params) (btcutil.Address, e
|
||||
if err == base58.ErrChecksum {
|
||||
return nil, btcutil.ErrChecksumMismatch
|
||||
}
|
||||
return nil, errors.Err("decoded address is of unknown format")
|
||||
return nil, errors.Err("decoded address[%s] is of unknown format even with default chainparams[%s]", addr, defaultNet.Name)
|
||||
}
|
||||
|
||||
switch len(decoded) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package lbrycrd
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDecodeAddress(t *testing.T) {
|
||||
addr := "bMUxfQVUeDi7ActVeZJZHzHKBceai7kHha"
|
||||
btcAddr, err := DecodeAddress(addr, &MainNetParams)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
println(btcAddr.EncodeAddress())
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package lbrycrd_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/lbrycrd"
|
||||
"github.com/lbryio/lbry.go/v2/lbrycrd"
|
||||
)
|
||||
|
||||
var claimIdTests = []struct {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
c "github.com/lbryio/lbry.go/v2/schema/claim"
|
||||
pb "github.com/lbryio/types/v2/go"
|
||||
)
|
||||
|
||||
func NewChannel() (*c.ClaimHelper, *btcec.PrivateKey, error) {
|
||||
claimChannel := new(pb.Claim_Channel)
|
||||
channel := new(pb.Channel)
|
||||
claimChannel.Channel = channel
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = claimChannel
|
||||
|
||||
privateKey, err := btcec.NewPrivateKey(btcec.S256())
|
||||
if err != nil {
|
||||
return nil, nil, errors.Err(err)
|
||||
}
|
||||
pubkeyBytes, err := c.PublicKeyToDER(privateKey.PubKey())
|
||||
if err != nil {
|
||||
return nil, nil, errors.Err(err)
|
||||
}
|
||||
|
||||
helper := c.ClaimHelper{Claim: pbClaim}
|
||||
helper.Version = c.NoSig
|
||||
helper.GetChannel().PublicKey = pubkeyBytes
|
||||
helper.Tags = []string{}
|
||||
coverSrc := new(pb.Source)
|
||||
helper.GetChannel().Cover = coverSrc
|
||||
helper.Languages = []*pb.Language{}
|
||||
thumbnailSrc := new(pb.Source)
|
||||
helper.Thumbnail = thumbnailSrc
|
||||
helper.Locations = []*pb.Location{}
|
||||
|
||||
return &helper, privateKey, nil
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
c "github.com/lbryio/lbry.go/v2/schema/claim"
|
||||
pb "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
)
|
||||
|
||||
func NewImageStreamClaim() (*c.ClaimHelper, error) {
|
||||
streamClaim := new(pb.Claim_Stream)
|
||||
stream := new(pb.Stream)
|
||||
image := new(pb.Stream_Image)
|
||||
image.Image = new(pb.Image)
|
||||
stream.Type = image
|
||||
|
||||
streamClaim.Stream = stream
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = streamClaim
|
||||
|
||||
helper := c.ClaimHelper{Claim: pbClaim}
|
||||
|
||||
return &helper, nil
|
||||
}
|
||||
|
||||
func NewVideoStreamClaim() (*c.ClaimHelper, error) {
|
||||
streamClaim := new(pb.Claim_Stream)
|
||||
stream := new(pb.Stream)
|
||||
video := new(pb.Stream_Video)
|
||||
video.Video = new(pb.Video)
|
||||
stream.Type = video
|
||||
streamClaim.Stream = stream
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = streamClaim
|
||||
|
||||
helper := c.ClaimHelper{Claim: pbClaim}
|
||||
|
||||
return &helper, nil
|
||||
}
|
||||
|
||||
func NewStreamClaim(title, description string) (*c.ClaimHelper, error) {
|
||||
streamClaim := new(pb.Claim_Stream)
|
||||
stream := new(pb.Stream)
|
||||
streamClaim.Stream = stream
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = streamClaim
|
||||
|
||||
helper := c.ClaimHelper{Claim: pbClaim}
|
||||
helper.Title = title
|
||||
helper.Description = description
|
||||
|
||||
return &helper, nil
|
||||
}
|
||||
|
||||
func SignClaim(rawTx *wire.MsgTx, privKey btcec.PrivateKey, claim, channel *c.ClaimHelper, channelClaimID string) error {
|
||||
claimIDHexBytes, err := hex.DecodeString(channelClaimID)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
claim.Version = c.WithSig
|
||||
claim.ClaimID = rev(claimIDHexBytes)
|
||||
hash, err := c.GetOutpointHash(rawTx.TxIn[0].PreviousOutPoint.Hash.String(), rawTx.TxIn[0].PreviousOutPoint.Index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sig, err := c.Sign(privKey, *channel, *claim, hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lbrySig, err := sig.LBRYSDKEncode()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
claim.Signature = lbrySig
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
+238
-32
@@ -1,15 +1,20 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
c "github.com/lbryio/lbry.go/v2/schema/claim"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/go-ini/ini"
|
||||
)
|
||||
@@ -28,10 +33,53 @@ var MainNetParams = chaincfg.Params{
|
||||
PubKeyHashAddrID: 0x55,
|
||||
ScriptHashAddrID: 0x7a,
|
||||
PrivateKeyID: 0x1c,
|
||||
Bech32HRPSegwit: "not-used", // we don't have this (yet)
|
||||
GenesisHash: &GenesisHash,
|
||||
Bech32HRPSegwit: "lbc",
|
||||
//WitnessPubKeyHashAddrID: , // i cant find these in bitcoin codebase either
|
||||
//WitnessScriptHashAddrID:,
|
||||
GenesisHash: &GenesisHash,
|
||||
Name: "mainnet",
|
||||
Net: wire.BitcoinNet(0xfae4aaf1),
|
||||
DefaultPort: "9246",
|
||||
BIP0034Height: 1,
|
||||
BIP0065Height: 200000,
|
||||
BIP0066Height: 200000,
|
||||
}
|
||||
|
||||
const (
|
||||
lbrycrdMainPubkeyPrefix = byte(85)
|
||||
lbrycrdMainScriptPrefix = byte(122)
|
||||
lbrycrdTestnetPubkeyPrefix = byte(111)
|
||||
lbrycrdTestnetScriptPrefix = byte(196)
|
||||
lbrycrdRegtestPubkeyPrefix = byte(111)
|
||||
lbrycrdRegtestScriptPrefix = byte(196)
|
||||
|
||||
LbrycrdMain = "lbrycrd_main"
|
||||
LbrycrdTestnet = "lbrycrd_testnet"
|
||||
LbrycrdRegtest = "lbrycrd_regtest"
|
||||
)
|
||||
|
||||
var mainNetParams = chaincfg.Params{
|
||||
PubKeyHashAddrID: lbrycrdMainPubkeyPrefix,
|
||||
ScriptHashAddrID: lbrycrdMainScriptPrefix,
|
||||
PrivateKeyID: 0x1c,
|
||||
}
|
||||
|
||||
var testNetParams = chaincfg.Params{
|
||||
PubKeyHashAddrID: lbrycrdTestnetPubkeyPrefix,
|
||||
ScriptHashAddrID: lbrycrdTestnetScriptPrefix,
|
||||
PrivateKeyID: 0x1c,
|
||||
Bech32HRPSegwit: "tlbc",
|
||||
}
|
||||
|
||||
var regTestNetParams = chaincfg.Params{
|
||||
PubKeyHashAddrID: lbrycrdRegtestPubkeyPrefix,
|
||||
ScriptHashAddrID: lbrycrdRegtestScriptPrefix,
|
||||
PrivateKeyID: 0x1c,
|
||||
Bech32HRPSegwit: "rlbc",
|
||||
}
|
||||
|
||||
var ChainParamsMap = map[string]chaincfg.Params{LbrycrdMain: mainNetParams, LbrycrdTestnet: testNetParams, LbrycrdRegtest: regTestNetParams}
|
||||
|
||||
func init() {
|
||||
// Register lbrycrd network
|
||||
err := chaincfg.Register(&MainNetParams)
|
||||
@@ -46,7 +94,7 @@ type Client struct {
|
||||
}
|
||||
|
||||
// New initializes a new Client
|
||||
func New(lbrycrdURL string) (*Client, error) {
|
||||
func New(lbrycrdURL string, chainParams *chaincfg.Params) (*Client, error) {
|
||||
// Connect to local bitcoin core RPC server using HTTP POST mode.
|
||||
|
||||
u, err := url.Parse(lbrycrdURL)
|
||||
@@ -60,10 +108,16 @@ func New(lbrycrdURL string) (*Client, error) {
|
||||
|
||||
password, _ := u.User.Password()
|
||||
|
||||
chain := MainNetParams
|
||||
if chainParams != nil {
|
||||
chain = *chainParams
|
||||
}
|
||||
|
||||
connCfg := &rpcclient.ConnConfig{
|
||||
Host: u.Host,
|
||||
User: u.User.Username(),
|
||||
Pass: password,
|
||||
Params: chain,
|
||||
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
||||
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
||||
}
|
||||
@@ -74,7 +128,7 @@ func New(lbrycrdURL string) (*Client, error) {
|
||||
}
|
||||
|
||||
// make sure lbrycrd is running and responsive
|
||||
_, err = client.GetInfo()
|
||||
_, err = client.GetBlockChainInfo()
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
@@ -82,12 +136,12 @@ func New(lbrycrdURL string) (*Client, error) {
|
||||
return &Client{client}, nil
|
||||
}
|
||||
|
||||
func NewWithDefaultURL() (*Client, error) {
|
||||
func NewWithDefaultURL(chainParams *chaincfg.Params) (*Client, error) {
|
||||
url, err := getLbrycrdURLFromConfFile()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(url)
|
||||
return New(url, chainParams)
|
||||
}
|
||||
|
||||
var errInsufficientFunds = errors.Base("insufficient funds")
|
||||
@@ -104,7 +158,7 @@ func (c *Client) SimpleSend(toAddress string, amount float64) (*chainhash.Hash,
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
hash, err := c.Client.SendFromMinConf("", decodedAddress, lbcAmount, 0)
|
||||
hash, err := c.Client.SendToAddress(decodedAddress, lbcAmount)
|
||||
if err != nil {
|
||||
if err.Error() == "-6: Insufficient funds" {
|
||||
err = errors.Err(errInsufficientFunds)
|
||||
@@ -114,30 +168,6 @@ func (c *Client) SimpleSend(toAddress string, amount float64) (*chainhash.Hash,
|
||||
return hash, nil
|
||||
}
|
||||
|
||||
//func (c *Client) SendWithSplit(toAddress string, amount float64, numUTXOs int) (*chainhash.Hash, error) {
|
||||
// decodedAddress, err := DecodeAddress(toAddress, &MainNetParams)
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err, 0)
|
||||
// }
|
||||
//
|
||||
// amountPerAddress, err := btcutil.NewAmount(amount / float64(numUTXOs))
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err, 0)
|
||||
// }
|
||||
//
|
||||
// amounts := map[btcutil.Address]btcutil.Amount{}
|
||||
// for i := 0; i < numUTXOs; i++ {
|
||||
// addr := decodedAddress // to give it a new address, so
|
||||
// amounts[addr] = amountPerAddress
|
||||
// }
|
||||
//
|
||||
// hash, err := c.Client.SendManyMinConf("", amounts, 0)
|
||||
// if err != nil && err.Error() == "-6: Insufficient funds" {
|
||||
// err = errors.Wrap(errInsufficientFunds, 0)
|
||||
// }
|
||||
// return hash, errors.Wrap(err, 0)
|
||||
//}
|
||||
|
||||
func getLbrycrdURLFromConfFile() (string, error) {
|
||||
if os.Getenv("HOME") == "" {
|
||||
return "", errors.Err("no $HOME var found")
|
||||
@@ -179,3 +209,179 @@ func getLbrycrdURLFromConfFile() (string, error) {
|
||||
|
||||
return "rpc://" + userpass + host + ":" + port, nil
|
||||
}
|
||||
|
||||
func (c *Client) CreateBaseRawTx(inputs []btcjson.TransactionInput, change float64) (*wire.MsgTx, error) {
|
||||
addresses := make(map[btcutil.Address]btcutil.Amount)
|
||||
changeAddress, err := c.GetNewAddress("")
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
changeAmount, err := btcutil.NewAmount(change)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
addresses[changeAddress] = changeAmount
|
||||
lockTime := int64(0)
|
||||
return c.CreateRawTransaction(inputs, addresses, &lockTime)
|
||||
}
|
||||
|
||||
func (c *Client) GetEmptyTx(totalOutputSpend float64) (*wire.MsgTx, error) {
|
||||
totalFees := 0.1
|
||||
unspentResults, err := c.ListUnspentMin(1)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
finder := newOutputFinder(unspentResults)
|
||||
|
||||
outputs, err := finder.nextBatch(totalOutputSpend + totalFees)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(outputs) == 0 {
|
||||
return nil, errors.Err("Not enough spendable outputs to create transaction")
|
||||
}
|
||||
inputs := make([]btcjson.TransactionInput, len(outputs))
|
||||
var totalInputSpend float64
|
||||
for i, output := range outputs {
|
||||
inputs[i] = btcjson.TransactionInput{Txid: output.TxID, Vout: output.Vout}
|
||||
totalInputSpend = totalInputSpend + output.Amount
|
||||
}
|
||||
|
||||
change := totalInputSpend - totalOutputSpend - totalFees
|
||||
return c.CreateBaseRawTx(inputs, change)
|
||||
}
|
||||
|
||||
func (c *Client) SignTxAndSend(rawTx *wire.MsgTx) (*chainhash.Hash, error) {
|
||||
signedTx, allInputsSigned, err := c.SignRawTransaction(rawTx)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
if !allInputsSigned {
|
||||
return nil, errors.Err("Not all inputs for the tx could be signed!")
|
||||
}
|
||||
|
||||
return c.SendRawTransaction(signedTx, false)
|
||||
}
|
||||
|
||||
type ScriptType int
|
||||
|
||||
const (
|
||||
ClaimName ScriptType = iota
|
||||
ClaimUpdate
|
||||
ClaimSupport
|
||||
)
|
||||
|
||||
func (c *Client) AddStakeToTx(rawTx *wire.MsgTx, claim *c.ClaimHelper, name string, claimAmount float64, scriptType ScriptType) error {
|
||||
|
||||
address, err := c.GetNewAddress("")
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
amount, err := btcutil.NewAmount(claimAmount)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
|
||||
value, err := claim.CompileValue()
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
var claimID string
|
||||
if len(claim.ClaimID) > 0 {
|
||||
claimID = hex.EncodeToString(rev(claim.ClaimID))
|
||||
}
|
||||
var script []byte
|
||||
switch scriptType {
|
||||
case ClaimName:
|
||||
script, err = getClaimNamePayoutScript(name, value, address)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
case ClaimUpdate:
|
||||
script, err = getUpdateClaimPayoutScript(name, claimID, value, address)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
case ClaimSupport:
|
||||
script, err = getUpdateClaimPayoutScript(name, claimID, value, address)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
}
|
||||
|
||||
rawTx.AddTxOut(wire.NewTxOut(int64(amount), script))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) CreateChannel(name string, amount float64) (*c.ClaimHelper, *btcec.PrivateKey, error) {
|
||||
channel, key, err := NewChannel()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
rawTx, err := c.GetEmptyTx(amount)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
err = c.AddStakeToTx(rawTx, channel, name, amount, ClaimName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
_, err = c.SignTxAndSend(rawTx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return channel, key, nil
|
||||
}
|
||||
|
||||
func (c *Client) SupportClaim(name, claimID, address, blockchainName string, claimAmount float64) (*chainhash.Hash, error) {
|
||||
const DefaultFeePerSupport = float64(0.0001)
|
||||
unspentResults, err := c.ListUnspentMin(1)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
finder := newOutputFinder(unspentResults)
|
||||
outputs, err := finder.nextBatch(claimAmount + DefaultFeePerSupport)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(outputs) == 0 {
|
||||
return nil, errors.Err("Not enough spendable outputs to create transaction")
|
||||
}
|
||||
inputs := make([]btcjson.TransactionInput, len(outputs))
|
||||
|
||||
var totalInputSpend float64
|
||||
for i, output := range outputs {
|
||||
inputs[i] = btcjson.TransactionInput{Txid: output.TxID, Vout: output.Vout}
|
||||
totalInputSpend = totalInputSpend + output.Amount
|
||||
}
|
||||
|
||||
change := totalInputSpend - claimAmount - DefaultFeePerSupport
|
||||
rawTx, err := c.CreateBaseRawTx(inputs, change)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chainParams, ok := ChainParamsMap[blockchainName]
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid blockchain name %s", blockchainName)
|
||||
}
|
||||
decodedAddress, err := DecodeAddress(address, &chainParams)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
amount, err := btcutil.NewAmount(claimAmount)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
script, err := getClaimSupportPayoutScript(name, claimID, decodedAddress)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
rawTx.AddTxOut(wire.NewTxOut(int64(amount), script))
|
||||
|
||||
return c.SignTxAndSend(rawTx)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
)
|
||||
|
||||
type outputFinder struct {
|
||||
unspent []btcjson.ListUnspentResult
|
||||
lastChecked int
|
||||
}
|
||||
|
||||
func newOutputFinder(unspentResults []btcjson.ListUnspentResult) *outputFinder {
|
||||
return &outputFinder{unspent: unspentResults, lastChecked: -1}
|
||||
}
|
||||
|
||||
func (f *outputFinder) nextBatch(minAmount float64) ([]btcjson.ListUnspentResult, error) {
|
||||
var batch []btcjson.ListUnspentResult
|
||||
var lbcBatched float64
|
||||
for i, unspent := range f.unspent {
|
||||
if i > f.lastChecked {
|
||||
if unspent.Spendable {
|
||||
batch = append(batch, unspent)
|
||||
lbcBatched = lbcBatched + unspent.Amount
|
||||
}
|
||||
}
|
||||
if lbcBatched >= minAmount {
|
||||
f.lastChecked = i
|
||||
break
|
||||
}
|
||||
if i == len(f.unspent)-1 {
|
||||
return nil, errors.Err("Not enough unspent outputs to spend %d on supports.", minAmount)
|
||||
}
|
||||
}
|
||||
|
||||
return batch, nil
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
func getClaimSupportPayoutScript(name, claimid string, address btcutil.Address) ([]byte, error) {
|
||||
//OP_SUPPORT_CLAIM <name> <claimid> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
bytes, err := hex.DecodeString(claimid)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_NOP7). //OP_SUPPORT_CLAIM
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(rev(bytes)). //<claimid>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
|
||||
}
|
||||
|
||||
func getClaimNamePayoutScript(name string, value []byte, address btcutil.Address) ([]byte, error) {
|
||||
//OP_CLAIM_NAME <name> <value> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_NOP6). //OP_CLAIMNAME
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(value). //<value>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
}
|
||||
|
||||
func getUpdateClaimPayoutScript(name, claimid string, value []byte, address btcutil.Address) ([]byte, error) {
|
||||
//OP_UPDATE_CLAIM <name> <claimid> <value> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
bytes, err := hex.DecodeString(claimid)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_NOP8). //OP_UPDATE_CLAIM
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(rev(bytes)). //<claimid>
|
||||
AddData(value). //<value>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/claim"
|
||||
"github.com/lbryio/lbry.go/v2/claim"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -16,19 +16,26 @@ This project uses Go modules. Make sure you have Go 1.11+ installed.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions to this project are welcome, encouraged, and compensated. For more details, see [lbry.io/faq/contributing](https://lbry.io/faq/contributing)
|
||||
Contributions to this project are welcome, encouraged, and compensated. For more details, see [lbry.com/faq/contributing](https://lbry.com/faq/contributing)
|
||||
|
||||
Make sure you `go fmt` your code before submitting PRs.
|
||||
|
||||
## Versioning
|
||||
|
||||
This codebase follows the semver standards. You can find the releases [here](https://github.com/lbryio/lbry.go/releases)
|
||||
|
||||
You can include the libraries by running `go get github.com/lbryio/lbry.go@latest`.
|
||||
You can lock (and you should) to a version whenever you make use of this set of libraries.
|
||||
|
||||
## License
|
||||
|
||||
This project is MIT licensed. For the full license, see [LICENSE](LICENSE).
|
||||
|
||||
## Security
|
||||
|
||||
We take security seriously. Please contact security@lbry.io regarding any issues you may encounter.
|
||||
We take security seriously. Please contact security@lbry.com regarding any issues you may encounter.
|
||||
Our PGP key is [here](https://keybase.io/lbry/key.asc) if you need it.
|
||||
|
||||
## Contact
|
||||
|
||||
The primary contact for this project is [@lyoshenka](https://github.com/lyoshenka) (grin@lbry.io)
|
||||
The primary contact for this project is [@lyoshenka](https://github.com/lyoshenka) (grin@lbry.com)
|
||||
@@ -0,0 +1,4 @@
|
||||
.idea/
|
||||
lbryschema-cli
|
||||
lbryschema-python-binding.h
|
||||
lbryschema-python-binding.so
|
||||
@@ -0,0 +1,9 @@
|
||||
os: linux
|
||||
dist: trusty
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.10.3
|
||||
|
||||
script:
|
||||
- ./build_and_test.sh
|
||||
@@ -0,0 +1,29 @@
|
||||
package address
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDecodeAddressLBRYCrdMain(t *testing.T) {
|
||||
addr := "bUc9gyCJPKu2CBYpTvJ98MdmsLb68utjP6"
|
||||
correct := [25]byte{85, 174, 41, 64, 245, 110, 91, 239, 43, 208, 32, 73, 115, 20, 70, 204, 83, 199, 3,
|
||||
206, 210, 176, 194, 188, 193}
|
||||
result, err := DecodeAddress(addr, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if result != correct {
|
||||
t.Error("Mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeAddressLBRYCrdMain(t *testing.T) {
|
||||
addr := [25]byte{85, 174, 41, 64, 245, 110, 91, 239, 43, 208, 32, 73, 115, 20, 70, 204, 83, 199, 3,
|
||||
206, 210, 176, 194, 188, 193}
|
||||
correct := "bUc9gyCJPKu2CBYpTvJ98MdmsLb68utjP6"
|
||||
result, err := EncodeAddress(addr, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if result != correct {
|
||||
t.Error("Mismatch")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package base58
|
||||
@@ -0,0 +1,21 @@
|
||||
package base58
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var b58Characters = [58]byte{0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45,
|
||||
0x46, 0x47, 0x48, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
|
||||
0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
|
||||
0x6a, 0x6b, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
|
||||
0x79, 0x7a}
|
||||
|
||||
func CharacterIndex(character byte) (*big.Int, error) {
|
||||
for i := 0; i < 58; i++ {
|
||||
if b58Characters[i] == character {
|
||||
return big.NewInt(int64(i)), nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("invalid character")
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package base58
|
||||
|
||||
import "crypto/sha256"
|
||||
|
||||
const checksumLength = 4
|
||||
|
||||
func VerifyBase58Checksum(v []byte) bool {
|
||||
checksum := [checksumLength]byte{}
|
||||
for i := range checksum {
|
||||
checksum[i] = v[len(v)-checksumLength+i]
|
||||
}
|
||||
real_checksum := sha256.Sum256(v[:len(v)-checksumLength])
|
||||
real_checksum = sha256.Sum256(real_checksum[:])
|
||||
for i, c := range checksum {
|
||||
if c != real_checksum[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package base58
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func DecodeBase58(value string, size int64) ([]byte, error) {
|
||||
buf := []byte(value)
|
||||
longValue := big.NewInt(0)
|
||||
result := make([]byte, size)
|
||||
for i := int64(len(buf) - 1); i >= 0; i-- {
|
||||
to_add := big.NewInt(0)
|
||||
to_add = to_add.Exp(big.NewInt(58), big.NewInt(i), to_add)
|
||||
c, err := CharacterIndex(buf[int64(len(buf))-i-1])
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
to_add = to_add.Mul(c, to_add)
|
||||
longValue = longValue.Add(to_add, longValue)
|
||||
}
|
||||
for i := size - 1; i >= 0; i-- {
|
||||
m := big.NewInt(0)
|
||||
longValue, m = longValue.DivMod(longValue, big.NewInt(256), m)
|
||||
bs := m.Bytes()
|
||||
if len(bs) == 0 {
|
||||
bs = append(bs, 0x00)
|
||||
}
|
||||
b := byte(bs[0])
|
||||
result[i] = b
|
||||
}
|
||||
if longValue.Int64() != 0 {
|
||||
return result, errors.New("cannot decode to the given size")
|
||||
}
|
||||
if size != int64(len(result)) {
|
||||
return result, errors.New("length mismatch")
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package base58
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func EncodeBase58(data []byte) string {
|
||||
longValue := big.NewInt(0)
|
||||
result := ""
|
||||
for i := 0; i < len(data); i++ {
|
||||
to_add := big.NewInt(0)
|
||||
to_add = to_add.Exp(big.NewInt(256), big.NewInt(int64(i)), to_add)
|
||||
to_add = to_add.Mul(big.NewInt(int64(data[24-i])), to_add)
|
||||
longValue = longValue.Add(to_add, longValue)
|
||||
}
|
||||
i := 0
|
||||
for {
|
||||
m := big.NewInt(0)
|
||||
longValue, m = longValue.DivMod(longValue, big.NewInt(58), m)
|
||||
bs := m.Bytes()
|
||||
if len(bs) == 0 {
|
||||
bs = append(bs, 0x00)
|
||||
}
|
||||
b := b58Characters[bs[0]]
|
||||
result = string(b) + result
|
||||
if longValue.Int64() == 0 {
|
||||
break
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package address
|
||||
|
||||
import (
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/schema/address/base58"
|
||||
)
|
||||
|
||||
func DecodeAddress(address string, blockchainName string) ([addressLength]byte, error) {
|
||||
decoded, err := base58.DecodeBase58(address, addressLength)
|
||||
if err != nil {
|
||||
return [addressLength]byte{}, errors.Err("failed to decode")
|
||||
}
|
||||
buf := [addressLength]byte{}
|
||||
for i, b := range decoded {
|
||||
buf[i] = b
|
||||
}
|
||||
|
||||
return ValidateAddress(buf, blockchainName)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package address
|
||||
|
||||
import (
|
||||
"github.com/lbryio/lbry.go/v2/schema/address/base58"
|
||||
)
|
||||
|
||||
func EncodeAddress(address [addressLength]byte, blockchainName string) (string, error) {
|
||||
buf, err := ValidateAddress(address, blockchainName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base58.EncodeBase58(buf[:]), nil
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package address
|
||||
|
||||
import (
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/schema/address/base58"
|
||||
)
|
||||
|
||||
const lbrycrdMainPubkeyPrefix = byte(85)
|
||||
const lbrycrdMainScriptPrefix = byte(122)
|
||||
|
||||
const lbrycrdTestnetPubkeyPrefix = byte(111)
|
||||
const lbrycrdTestnetScriptPrefix = byte(196)
|
||||
|
||||
const lbrycrdRegtestPubkeyPrefix = byte(111)
|
||||
const lbrycrdRegtestScriptPrefix = byte(196)
|
||||
|
||||
const prefixLength = 1
|
||||
const pubkeyLength = 20
|
||||
const checksumLength = 4
|
||||
const addressLength = prefixLength + pubkeyLength + checksumLength
|
||||
|
||||
const lbrycrdMain = "lbrycrd_main"
|
||||
const lbrycrdTestnet = "lbrycrd_testnet"
|
||||
const lbrycrdRegtest = "lbrycrd_regtest"
|
||||
|
||||
var addressPrefixes = map[string][2]byte{
|
||||
lbrycrdMain: [2]byte{lbrycrdMainPubkeyPrefix, lbrycrdMainScriptPrefix},
|
||||
lbrycrdTestnet: [2]byte{lbrycrdTestnetPubkeyPrefix, lbrycrdTestnetScriptPrefix},
|
||||
lbrycrdRegtest: [2]byte{lbrycrdRegtestPubkeyPrefix, lbrycrdRegtestScriptPrefix},
|
||||
}
|
||||
|
||||
func PrefixIsValid(address [addressLength]byte, blockchainName string) bool {
|
||||
prefix := address[0]
|
||||
for _, addrPrefix := range addressPrefixes[blockchainName] {
|
||||
if addrPrefix == prefix {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func PubKeyIsValid(address [addressLength]byte) bool {
|
||||
pubkey := address[prefixLength : pubkeyLength+prefixLength]
|
||||
// TODO: validate this for real
|
||||
if len(pubkey) != pubkeyLength {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func ChecksumIsValid(address [addressLength]byte) bool {
|
||||
return base58.VerifyBase58Checksum(address[:])
|
||||
}
|
||||
|
||||
func ValidateAddress(address [addressLength]byte, blockchainName string) ([addressLength]byte, error) {
|
||||
if blockchainName != lbrycrdMain && blockchainName != lbrycrdTestnet && blockchainName != lbrycrdRegtest {
|
||||
return address, errors.Err("invalid blockchain name")
|
||||
}
|
||||
if !PrefixIsValid(address, blockchainName) {
|
||||
return address, errors.Err("invalid prefix")
|
||||
}
|
||||
if !PubKeyIsValid(address) {
|
||||
return address, errors.Err("invalid pubkey")
|
||||
}
|
||||
if !ChecksumIsValid(address) {
|
||||
return address, errors.Err("invalid address checksum")
|
||||
}
|
||||
return address, nil
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euxo pipefail
|
||||
go build ./...
|
||||
go build ./cli/lbryschema-cli.go
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euxo pipefail
|
||||
./build.sh
|
||||
./test.sh
|
||||
@@ -0,0 +1,249 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"strconv"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/schema/address"
|
||||
legacy_pb "github.com/lbryio/types/v1/go"
|
||||
pb "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
type version byte
|
||||
|
||||
func (v version) byte() byte {
|
||||
return byte(v)
|
||||
}
|
||||
|
||||
const (
|
||||
NoSig = version(byte(0))
|
||||
//Signature using ECDSA SECP256k1 key and SHA-256 hash.
|
||||
WithSig = version(byte(1))
|
||||
UNKNOWN = version(byte(2))
|
||||
)
|
||||
|
||||
type ClaimHelper struct {
|
||||
*pb.Claim
|
||||
LegacyClaim *legacy_pb.Claim
|
||||
ClaimID []byte
|
||||
Version version
|
||||
Signature []byte
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
const migrationErrorMessage = "migration from v1 to v2 protobuf failed with: "
|
||||
|
||||
func (c *ClaimHelper) ValidateAddresses(blockchainName string) error {
|
||||
if c.Claim != nil { // V2
|
||||
// check the validity of a fee address
|
||||
if c.Claim.GetStream() != nil {
|
||||
fee := c.GetStream().GetFee()
|
||||
if fee != nil {
|
||||
return validateAddress(fee.GetAddress(), blockchainName)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
} else if c.GetChannel() != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return errors.Err("claim helper created with migrated v2 protobuf claim 'invalid state'")
|
||||
}
|
||||
|
||||
func validateAddress(tmp_addr []byte, blockchainName string) error {
|
||||
if len(tmp_addr) != 25 {
|
||||
return errors.Err("invalid address length: " + strconv.FormatInt(int64(len(tmp_addr)), 10) + "!")
|
||||
}
|
||||
addr := [25]byte{}
|
||||
for i := range addr {
|
||||
addr[i] = tmp_addr[i]
|
||||
}
|
||||
_, err := address.EncodeAddress(addr, blockchainName)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getVersionFromByte(versionByte byte) version {
|
||||
if versionByte == byte(0) {
|
||||
return NoSig
|
||||
} else if versionByte == byte(1) {
|
||||
return WithSig
|
||||
}
|
||||
|
||||
return UNKNOWN
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) ValidateCertificate() error {
|
||||
if c.GetChannel() == nil {
|
||||
return nil
|
||||
}
|
||||
_, err := c.GetPublicKey()
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) LoadFromBytes(raw_claim []byte, blockchainName string) error {
|
||||
if c.String() != "" {
|
||||
return errors.Err("already initialized")
|
||||
}
|
||||
if len(raw_claim) < 1 {
|
||||
return errors.Err("there is nothing to decode")
|
||||
}
|
||||
|
||||
var claim_pb *pb.Claim
|
||||
var legacy_claim_pb *legacy_pb.Claim
|
||||
|
||||
version := getVersionFromByte(raw_claim[0]) //First byte = version
|
||||
pbPayload := raw_claim[1:]
|
||||
var claimID []byte
|
||||
var signature []byte
|
||||
if version == WithSig {
|
||||
if len(raw_claim) < 86 {
|
||||
return errors.Err("signature version indicated by 1st byte but not enough bytes for valid format")
|
||||
}
|
||||
claimID = raw_claim[1:21] // channel claimid = next 20 bytes
|
||||
signature = raw_claim[21:85] // signature = next 64 bytes
|
||||
pbPayload = raw_claim[85:] // protobuf payload = remaining bytes
|
||||
}
|
||||
|
||||
claim_pb = &pb.Claim{}
|
||||
err := proto.Unmarshal(pbPayload, claim_pb)
|
||||
if err != nil {
|
||||
legacy_claim_pb = &legacy_pb.Claim{}
|
||||
legacyErr := proto.Unmarshal(raw_claim, legacy_claim_pb)
|
||||
if legacyErr == nil {
|
||||
claim_pb, err = migrateV1PBClaim(*legacy_claim_pb)
|
||||
if err != nil {
|
||||
return errors.Prefix(migrationErrorMessage, err)
|
||||
}
|
||||
if legacy_claim_pb.GetPublisherSignature() != nil {
|
||||
version = WithSig
|
||||
claimID = legacy_claim_pb.GetPublisherSignature().GetCertificateId()
|
||||
signature = legacy_claim_pb.GetPublisherSignature().GetSignature()
|
||||
}
|
||||
if legacy_claim_pb.GetCertificate() != nil {
|
||||
version = NoSig
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
*c = ClaimHelper{
|
||||
Claim: claim_pb,
|
||||
LegacyClaim: legacy_claim_pb,
|
||||
ClaimID: claimID,
|
||||
Version: version,
|
||||
Signature: signature,
|
||||
Payload: pbPayload,
|
||||
}
|
||||
|
||||
// Commenting out because of a bug in SDK release allowing empty addresses.
|
||||
//err = c.ValidateAddresses(blockchainName)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
|
||||
err = c.ValidateCertificate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) LoadFromHexString(claim_hex string, blockchainName string) error {
|
||||
buf, err := hex.DecodeString(claim_hex)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.LoadFromBytes(buf, blockchainName)
|
||||
}
|
||||
|
||||
func DecodeClaimProtoBytes(serialized []byte, blockchainName string) (*ClaimHelper, error) {
|
||||
claim := &ClaimHelper{&pb.Claim{}, nil, nil, NoSig, nil, nil}
|
||||
err := claim.LoadFromBytes(serialized, blockchainName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return claim, nil
|
||||
}
|
||||
|
||||
func DecodeClaimHex(serialized string, blockchainName string) (*ClaimHelper, error) {
|
||||
claim_bytes, err := hex.DecodeString(serialized)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
return DecodeClaimBytes(claim_bytes, blockchainName)
|
||||
}
|
||||
|
||||
// DecodeClaimBytes take a byte array and tries to decode it to a protobuf claim or migrate it from either json v1,2,3 or pb v1
|
||||
func DecodeClaimBytes(serialized []byte, blockchainName string) (*ClaimHelper, error) {
|
||||
helper, err := DecodeClaimProtoBytes(serialized, blockchainName)
|
||||
if err == nil {
|
||||
return helper, nil
|
||||
}
|
||||
helper = &ClaimHelper{}
|
||||
//If protobuf fails, try json versions before returning an error.
|
||||
v1Claim := new(V1Claim)
|
||||
err = v1Claim.Unmarshal(serialized)
|
||||
if err != nil {
|
||||
v2Claim := new(V2Claim)
|
||||
err := v2Claim.Unmarshal(serialized)
|
||||
if err != nil {
|
||||
v3Claim := new(V3Claim)
|
||||
err := v3Claim.Unmarshal(serialized)
|
||||
if err != nil {
|
||||
return nil, errors.Prefix("Claim value has no matching version", err)
|
||||
}
|
||||
helper.Claim, err = migrateV3Claim(*v3Claim)
|
||||
if err != nil {
|
||||
return nil, errors.Prefix("V3 Metadata Migration Error", err)
|
||||
}
|
||||
return helper, nil
|
||||
}
|
||||
helper.Claim, err = migrateV2Claim(*v2Claim)
|
||||
if err != nil {
|
||||
return nil, errors.Prefix("V2 Metadata Migration Error ", err)
|
||||
}
|
||||
return helper, nil
|
||||
}
|
||||
|
||||
helper.Claim, err = migrateV1Claim(*v1Claim)
|
||||
if err != nil {
|
||||
return nil, errors.Prefix("V1 Metadata Migration Error ", err)
|
||||
}
|
||||
return helper, nil
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) GetStream() *pb.Stream {
|
||||
if c != nil {
|
||||
return c.Claim.GetStream()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) CompileValue() ([]byte, error) {
|
||||
payload, err := c.serialized()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var value []byte
|
||||
value = append(value, c.Version.byte())
|
||||
if c.Version == WithSig {
|
||||
value = append(value, c.ClaimID...)
|
||||
value = append(value, c.Signature...)
|
||||
}
|
||||
value = append(value, payload...)
|
||||
|
||||
return value, nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package claim
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestClaimHelper(t *testing.T) {
|
||||
for _, rawClaim := range raw_claims {
|
||||
helper, err := DecodeClaimHex(rawClaim, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = helper.RenderJSON()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = helper.serialized()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = helper.serializedHexString()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = helper.serializedNoSignature()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = helper.ValidateAddresses("lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
pb "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
)
|
||||
|
||||
type rawClaim struct {
|
||||
Hex string
|
||||
ClaimID string
|
||||
}
|
||||
|
||||
var raw_claims = []string{
|
||||
"08011002225e0801100322583056301006072a8648ce3d020106052b8104000a03420004d015365a40f3e5c03c87227168e5851f44659837bcf6a3398ae633bc37d04ee19baeb26dc888003bd728146dbea39f5344bf8c52cedaf1a3a1623a0166f4a367",
|
||||
"080110011ad7010801128f01080410011a0c47616d65206f66206c696665221047616d65206f66206c696665206769662a0b4a6f686e20436f6e776179322e437265617469766520436f6d6d6f6e73204174747269627574696f6e20342e3020496e7465726e6174696f6e616c38004224080110011a195569c917f18bf5d2d67f1346aa467b218ba90cdbf2795676da250000803f4a0052005a001a41080110011a30b6adf6e2a62950407ea9fb045a96127b67d39088678d2f738c359894c88d95698075ee6203533d3c204330713aa7acaf2209696d6167652f6769662a5c080110031a40c73fe1be4f1743c2996102eec6ce0509e03744ab940c97d19ddb3b25596206367ab1a3d2583b16c04d2717eeb983ae8f84fee2a46621ffa5c4726b30174c6ff82214251305ca93d4dbedb50dceb282ebcb7b07b7ac65",
|
||||
"080110011ad7010801128f01080410011a0c47616d65206f66206c696665221047616d65206f66206c696665206769662a0b4a6f686e20436f6e776179322e437265617469766520436f6d6d6f6e73204174747269627574696f6e20342e3020496e7465726e6174696f6e616c38004224080110011a195569c917f18bf5d2d67f1346aa467b218ba90cdbf2795676da250000803f4a0052005a001a41080110011a30b6adf6e2a62950407ea9fb045a96127b67d39088678d2f738c359894c88d95698075ee6203533d3c204330713aa7acaf2209696d6167652f676966",
|
||||
"080110011af901080112b101080410011a1c43414e47474948207c204b412044494c554152204e4547455249207c222c0a68747470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d5f5470313577746e7753732a1042616d62616e6720536574796177616e321c436f7079726967687465642028636f6e7461637420617574686f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f5f5470313577746e77537352005a001a41080110011a304616bfdbb6fcb870d4c235443f9261d289ee8edbd4a51b8c6e3e95a34baeebbbb08978a7c5f9bf9a36245513b450943b2209766964656f2f6d70342a5c080110031a40f94a9db9c70217e4f17f9d38f08770096e7ce94a86b742b972e07c62c9606459c6ad735cd517175cf76ad6ea9eb16ca8198a17e2d31dc3ac53413005b5ca2a3a221402b1839207e2a706f0ba73dec0ce6b719043293d",
|
||||
"080110011aa510080112dd0f080410011a4b4953545249204d4142554b204e41494b204b412021207b547269707d205369646f61726a6f202d2042616e797577616e67692042617275204e61696b204b41205372692054616e6a756e6722a80e4b657265746120617069205372692054616e6a756e67206164616c61682072616e676b6169616e206b657265746120617069206b656c617320656b6f6e6f6d69204143206a6172616b206a617568206d696c696b205054204b65726574612041706920496e646f6e6573696120285065727365726f292079616e67206d656c6179616e6920727574652042616e797577616e676920426172752d4c656d707579616e67616e2c2070702e204b65726574612061706920696e692064696f7065726173696b616e206f6c656820446165726168204f706572617369204958204a656d6265722c2079616e67206469616d62696c2064617269205372692054616e6a756e672c206e616d6120746f6b6f682064616c616d206365726974612072616b7961742042616e797577616e67692e0a0a4b65726574612061706920696e6920626572616e676b617420646172692042616e797577616e67692070756b756c2030362e3330205749422074696261206469204c656d707579616e67616e2070756b756c2031392e3330205749422c20736564616e676b616e20626572616e676b61742064617269204c656d707579616e67616e2070756b756c2030372e31352057494220746962612064692042616e797577616e67692070756b756c2032312e3135205749422e204b65726574612061706920696e69206d656d62617761207361747520676572626f6e6720616c696e672d616c696e6720626572757061206b65726574612070656d62616e676b6974202862696173616e7961204b5033292c20656e616d206b65726574612070656e756d70616e67206b656c617320656b6f6e6f6d692c2073617475206b6572657461206d616b616e2070656d62616e676b6974206b656c617320656b6f6e6f6d692c2064616e2068616d7069722073656c616c75206d656d626177612073617475206b65726574612062616761736920756e696b2079616e67206265727761726e61206269727520706f6c6f732e204e616d756e2073656972696e672064656e67616e2070656d62617275616e20696d616765205054204b41492c207365636172612062657274616861702073656d756120676572626f6e67206d656e6767756e616b616e206c697665727920224b65736570616b6174616e22206d656e67696b757469206b657265746120617069206c61696e6e79612e0a0a44616c616d207065726a616c616e616e6e79612c206b65726574612061706920696e692062657268656e7469206469205374617369756e2042616e797577616e676920426172752c204b6172616e676173656d2c20526f676f6a616d70692c2054656d7567757275682c204b616c6973657461696c2c2053756d626572776164756e672c20476c656e6d6f72652c204b616c69626172752c204b616c697361742c204a656d6265722c2052616d626970756a692c2054616e6767756c2c2050726f626f6c696e67676f2c20506173757275616e2c2042616e67696c2c205369646f61726a6f2c20537572616261796120477562656e672c20576f6e6f6b726f6d6f2c204d6f6a6f6b6572746f2c204a6f6d62616e672c204b6572746f736f6e6f2c204e67616e6a756b2c204361727562616e2c204d616469756e2c2042617261742c205061726f6e2c2057616c696b756b756e2c2053726167656e2c20507572776f736172692c204b6c6174656e2c2064616e204c656d707579616e67616e2c2064656e67616e20746f74616c2077616b74752074656d7075682073656b697461722031332d3134206a616d2e0a0a4b687573757320756e74756b206b652061726168205374617369756e2042616e797577616e6769204261727520284b41203139342f313935292c206b657265746120696e692064617061742062657268656e7469206469205374617369756e205361726164616e2028756e74756b2070657273696c616e67616e292c204261726f6e2c2053756d6f6269746f2028756e74756b2070657273696c616e67616e292c2064616e20536570616e6a616e672e204469205374617369756e20537572616261796120477562656e672c2064696c616b756b616e2070656d696e646168616e20706f73697369206c6f6b6f6d6f7469662e0a0a5061646120746168756e2032303136207461726966204b41205372692054616e6a756e67206b656d62616c69206469737562736964692070656d6572696e7461682e20506164612074616e6767616c2031204a616e756172692068696e676761203331204d617265742074617269666e7961206164616c6168205270203130302e3030302c30302c206d756c6169203120417072696c2074617269666e7961206164616c61682052702039362e3030302c30302c2064616e206d756c61692031204a756c692074617269666e7961206164616c61682052702039342e3030302c30302e202857696b697065646961290a68747470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d754750344b5857614536512a1042616d62616e6720536574796177616e321c436f7079726967687465642028636f6e7461637420617574686f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f754750344b58576145365152005a001a41080110011a30d3d1d49ce3268e3dcf318ebbb6f4bfd454995d6b772bd5e27630743c0fb1d66387bf84b51afe28733812c5495b837b8f2209766964656f2f6d70342a5c080110031a40a47aa2d45ec15d1e578b91e5c8c76ee8a82e55af37da4873a7703795889ee7400967cf41e903788bcf0510d7c06976c99983fa01e702e1fb6d518b0646b0d565221402b1839207e2a706f0ba73dec0ce6b719043293d",
|
||||
"080110011aa30d080112db0c080410011a3b5354415349554e2042414e595557414e47492042415255207c2050656e6767616e7469205374617369756e2042616e797577616e6769204c616d6122b60b5374617369756e2042616e797577616e676920426172752028425729206164616c6168207374617369756e206b657265746120617069206b656c61732062657361722079616e6720626572616461206469204b65746170616e672c204b616c697075726f2c2042616e797577616e67692e205374617369756e2079616e67207465726c6574616b2070616461206b6574696e676769616e202b37206d20696e69206d65727570616b616e207374617369756e2079616e67206c6574616b6e79612070616c696e672074696d757220646920446165726168204f706572617369204958204a656d6265722e205374617369756e20696e692062657261646120646920756a756e672070616c696e672074696d75722050756c6175204a6177612064616e2068616e7961206265726a6172616b20313030206d6574657220646172692050656c61627568616e2046657269204b65746170616e6720736568696e676761207374617369756e20696e69206a75676120736572696e672064697365627574205374617369756e204b65746170616e672e205374617369756e20696e69206a756761206d65727570616b616e207374617369756e206b65726574612061706920616b7469662079616e67206265726c6f6b6173692070616c696e672074696d75722064692042616e797577616e67692c204a6177612054696d75722c2064616e20496e646f6e657369612e205374617369756e20696e6920646962616e67756e2062657273616d61616e2064656e67616e2070656d62616e67756e616e206a616c757220626172752064617269207374617369756e206e6f6e20616b746966204b61626174206d656e756a752070656c61627568616e207465727365627574207061646120746168756e20313938353b20646966756e6773696b616e20756e74756b206d656e6767616e74696b616e205374617369756e2042616e797577616e6769204c616d612079616e67206164612064692077696c61796168206b6f74612042616e797577616e67692e205374617369756e2042616e797577616e67692042617275207465726c6574616b203130206b6d20646172692077696c61796168206b6f7461206b6520617261682075746172613b20646962616e67756e20756e74756b206d656d656e756869206b656275747568616e207472616e73706f72746173692079616e672073696e657267697320616e74617261206b6572657461206170692064656e67616e206b6170616c20666572692064692070656e7965626572616e67616e204b65746170616e672e205374617369756e20696e69206d656d696c696b6920656e616d206a616c75722064656e67616e206a616c757220322073656261676169207365707572206c757275732e0a5374617369756e20696e692064696c656e676b6170692064656e67616e20737562206469706f206c6f6b6f6d6f7469662064616e206469706f206b65726574612020756e74756b206d656e79696d70616e2c206d6572617761742061726d616461206b657265746120617069206b68757375736e7961206d696c696b2044616f70204958206974752073656e646972692c206a756761206d656d70756e79616920207475726e7461626c652042616c6c6f6f6e204c6f6f702079616e67207465726c6574616b20646920736562656c61682075746172612e0a5374617369756e20696e69206a756761206d656c6179616e6920616e676b7574616e20626172616e672c207961697475206b6572657461206170692053656d656e205469676120526f64612079616e67206469626572616e676b61746b616e2064617269205374617369756e204e616d626f2064616e206d656e6a616469204b412079616e67206d656e656d707568206a6172616b2070616c696e67206a61756820646920496e646f6e657369612e5b77696b6970656469615d0a68747470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d475473535a5a30794a53452a1042616d62616e6720536574796177616e321c436f7079726967687465642028636f6e7461637420617574686f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f475473535a5a30794a534552005a001a41080110011a3048b3efe92661810e11118c9f8c0b4b4d1bca195eb6f74c8325070d97c699f4fb7ecc9ac90b3decc4feeb2ea0431e65922209766964656f2f6d70342a5c080110031a408e9fc836cad00c52ec7cdc95c11fc5369874948891df2187faaee212ca0925fc1058df5339c153dc00f055a8a21b853fb449a8ccb25ea52a98ba5645b22bdbfb221402b1839207e2a706f0ba73dec0ce6b719043293d",
|
||||
"080110011aa40b080112dc0a080410011a465354415349554e2054454d504548202854504529207c504155442d4b422053454b4152204152554d7c204a616c7572204d617469204c756d616a616e672d506173697269616e22ac095374617369756e2054656d706568202854504529206b6574696e676769616e202b3933206d206d65727570616b616e207374617369756e206b657265746120617069206d61746920286e6f6e20616b746966292079616e67207465726c6574616b20646920447573756e2054756c757372656a6f20492054656d706568204c6f72204b6563616d6174616e2054656d7065682c204b616275706174656e204c756d616a616e672064656e67616e204b6f6f7264696e6174203a203038c2b03131e280b235372e32e280b34c532c313133c2b03130e280b232392e38e280b342542e205374617369756e20696e69206d65727570616b616e2073616c61682073617475207374617369756e2070616461206a616c7572206b657265746120617069204c756d616a616e672d506173697269616e2079616e67206d756c616920646967756e616b616e2074616e6767616c203136204d65692031383936202064616e2074656c616820646974757475702073656d656e6a616b203120466562727561726920313938382e2050616461206d6173612070656e6a616a6168616e2042656c616e64612c206a616c75722d6a616c757220696e69206265726164612064692062617761682070656e67656c6f6c61616e2053746161747373706f6f722d20656e205472616d776567656e20284f6f737465726c696a6e656e29202853532d4f4c292e0a5361617420696e69206b6f6e64697369205374617369756e2054656d7065682074696e6767616c2062616e67756e616e207574616d612c2079616e672064696a6164696b616e20736562616761692074656d706174206265726d61696e206b616e616b2d6b616e616b205041554420e28093204b422053454b4152204152554d2e0a4a616c7572206b65726574612061706920696e692070616461206d617361206c616c75206d65727570616b616e206a616c75722079616e672063756b757020736962756b2c2064656e67616e205374617369756e204c756d616a616e67202d79616e67207465726265736172206469206a616c757220696e69206d656c6179616e692068616d706972203330302e3030302070656e756d70616e6720706572746168756e2064616e20626172616e672068696e676761203233207269627520746f6e206c6562696820646920616e7461726120746168756e20313935302d31393533202e204a756d6c61682070656e756d70616e672079616e67206e61696b2064617269205374617369756e2054656d7065682068616d70697220736574656e6761682062616e79616b6e79612079616e67206e61696b2064617269205374617369756e204c756d616a616e672e0a53656d656e74617261206a6172696e67616e2072656c2062657365727461206b656c656e676b6170616e20776573656c2064616e2070657273696e79616c616e6e79612074656c61682068616269732074616b20626572736973612e2042656b6173206a616c75722072656c6e7961206b696e69206d656e6a616469206a616c616e206b6563696c202867616e672920616e746172206b616d70756e672e202857696b697065646961290a68747470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d43704e33485f6f67695f6f2a1042616d62616e6720536574796177616e321c436f7079726967687465642028636f6e7461637420617574686f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f43704e33485f6f67695f6f52005a001a41080110011a30c11a6c72dc5cf5bb9b80bb58e760893984010a219702062234ef6eb9ec9572353a3c1b5b4da91a57057ee671b454f3c22209766964656f2f6d70342a5c080110031a40a8134e7e6e123c0b9ca568d95d8804da8a70877bdc47ca9b1c536db3a0e35a0de213ee66e3df77d42fb0c47cbd32c901b344b3e017f355169d7f85722a124dc9221402b1839207e2a706f0ba73dec0ce6b719043293d",
|
||||
"080110011a8307080112bb06080410011a484b4120534552415955202032313520444154414e47204449205354415349554e2042414e4a415220204d454d424157412050554c414e47207c4a75727573616e205057542d505345228905536161742073656c657361692070656e656c75737572616e206a616c7572206e6f6e20616b7469662042616e6a61722c2050616e67616e646172616e2073616d7061692043696a756c616e67206d61756e79612074656d75616e206469207374617369756e2042616e6a617220756e74756b206d656e67756361706b616e2073616c616d207065727069736168616e2064656e67616e204f6d204d6179626920507261626f776f2073616e67206d617374657220626c7573756b616e206a616c7572206e6f6e20616b7469662c207465726e79617461204b412079616e6720616b616e206d656d626177612070756c616e672062616c696b206b65204a616b6172746120646174616e672064756c75616e206461726920507572776f6b6572746f2064616e20736179612073656e64697269206d617369682062657261646120646961746173206a656d626174616e2f4f7665727061732079616e672062657261646120646920736562656c6168207374617369756e2042616e6a61722061726168204a616b617274612c20616b6869726e79612073616c616d207065727069736168616e2068616e79612064656e67616e206d656d766964696f6b616e206b65726574612079616e67206d656d626177616e79612070756c616e672062616c696b206b65204a616b6172746120646172692061746173204a656d626174616e2f4f7665727061732e0a536179612073656e646972692062616c696b206b652053757261626179612064656e67616e204b4120506173756e64616e2c20476f6f64627965206d7920667269656e6420746f206d65657420616761696e2e0a68747470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d596c6f594d3353447430452a1042616d62616e6720536574796177616e321c436f7079726967687465642028636f6e7461637420617574686f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f596c6f594d33534474304552005a001a41080110011a308c591efe76bd6d31b39c553996f925b3002b6fc150116f0e8d6bf7654e6674c5b3a59baef24c50fa908580a02dd90ded2209766964656f2f6d70342a5c080110031a40cbef89584d26bbf2695e039a10f2b34749843d827323c530e63b0472407fc7b184d174634d91f05efee9b90c1706e319bd9641226728524952e2b9004400684d221402b1839207e2a706f0ba73dec0ce6b719043293d",
|
||||
"080110011aed03080112a503080410011a3b4b41205345524159552020323136204449204a504c203432362d41205354415349554e2042414e4a4152207c4a75727573616e205053452d505754228002496e696c6168204b4120536572617975203231362079616e67206d656d62617761206d617374657220626c7573756b616e206a616c7572206e6f6e20616b746966204f6d204d6179626920507261626f776f202068747470733a2f2f7777772e796f75747562652e636f6d2f6368616e6e656c2f55435076355953496f59716f38364a525f4871626b437251202e0a5361617420696e6920616b616e206d656e656c7573757269206a616c7572206e6f6e20616b7469662042616e6a61722d50616e67616e646172616e2d43696a756c616e672e0a68747470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d4a6b4347615473774c35632a1042616d62616e6720536574796177616e321c436f7079726967687465642028636f6e7461637420617574686f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f4a6b4347615473774c356352005a001a41080110011a302ed97c79df5eccb145f8f8e1e866be1a392004a6794347c08c7e851c5f00b1504092a9f3c0674c78805a73a33c8b1bf32209766964656f2f6d70342a5c080110031a40cbcec20908e60b5f6198aecc192d2a9e4b069aa58d9238cb7154e37c4d04f268feefe92c2705c14009acf32e7e876df180cff3afdea6c989e75b4861150d1644221402b1839207e2a706f0ba73dec0ce6b719043293d",
|
||||
}
|
||||
|
||||
func TestDecodeClaim(t *testing.T) {
|
||||
claimHex := "000aa4010a8a010a30f1303989f58396694b0c5982c97f7e9d9435841d92aa13f4b80f671c27110c469babc4fbf4bd764155eaac089cfc49e8121454554d205045204d45524e45204c41472e6d703418cad0c8012209766964656f2f6d70343230c2c9389731e2a9568f66c78d703736a8c341015ada2e46f5dcc87aa6f08ab17c02df2121d9f6ef74055827a29dfc75801a044e6f6e6532040803180a5a0908b001109001188102421054554d205045204d45524e45204c41474a0944657369206c6f636b62020801"
|
||||
claim, err := DecodeClaimHex(claimHex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err, claim.ClaimID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeClaims(t *testing.T) {
|
||||
for _, claim_hex := range raw_claims {
|
||||
claim, err := DecodeClaimHex(claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
serializedHex, err := claim.serializedHexString()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if serializedHex != claim_hex {
|
||||
t.Error("failed to re-serialize")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestStripSignature(t *testing.T) {
|
||||
claimHex := raw_claims[1]
|
||||
claim, err := DecodeClaimHex(claimHex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
noSig, err := claim.serializedNoSignature()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if hex.EncodeToString(noSig) != raw_claims[2] {
|
||||
t.Error("failed to remove signature")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateChannelClaim(t *testing.T) {
|
||||
private, err := btcec.NewPrivateKey(btcec.S256())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
pubKeyBytes, err := PublicKeyToDER(private.PubKey())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
claim := &ClaimHelper{Claim: newChannelClaim(), Version: NoSig}
|
||||
claim.GetChannel().PublicKey = pubKeyBytes
|
||||
claim.Title = "Test Channel Title"
|
||||
claim.Description = "Test Channel Description"
|
||||
claim.GetChannel().Cover = &pb.Source{Url: "http://testcoverurl.com"}
|
||||
claim.Tags = []string{"TagA", "TagB", "TagC"}
|
||||
claim.Languages = []*pb.Language{{Language: pb.Language_en}, {Language: pb.Language_es}}
|
||||
claim.Thumbnail = &pb.Source{Url: "http://thumbnailurl.com"}
|
||||
claim.GetChannel().WebsiteUrl = "http://homepageurl.com"
|
||||
claim.Locations = []*pb.Location{{Country: pb.Location_AD}, {Country: pb.Location_US, State: "NJ", City: "some city"}}
|
||||
|
||||
rawClaim, err := claim.CompileValue()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
claim, err = DecodeClaimBytes(rawClaim, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if bytes, err := claim.CompileValue(); err != nil || len(bytes) != len(rawClaim) {
|
||||
t.Error("decoded claim does not match original")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/asn1"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
)
|
||||
|
||||
func PublicKeyToDER(publicKey *btcec.PublicKey) ([]byte, error) {
|
||||
var publicKeyBytes []byte
|
||||
var publicKeyAlgorithm pkix.AlgorithmIdentifier
|
||||
var err error
|
||||
pub := publicKey.ToECDSA()
|
||||
publicKeyBytes = elliptic.Marshal(pub.Curve, pub.X, pub.Y)
|
||||
//ans1 encoding oid for ecdsa public key https://github.com/golang/go/blob/release-branch.go1.12/src/crypto/x509/x509.go#L457
|
||||
publicKeyAlgorithm.Algorithm = asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1}
|
||||
//asn1 encoding oid for secp256k1 https://github.com/bitpay/bitpay-go/blob/v2.2.2/key_utils/key_utils.go#L30
|
||||
paramBytes, err := asn1.Marshal(asn1.ObjectIdentifier{1, 3, 132, 0, 10})
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
publicKeyAlgorithm.Parameters.FullBytes = paramBytes
|
||||
|
||||
return asn1.Marshal(publicKeyInfo{
|
||||
Algorithm: publicKeyAlgorithm,
|
||||
PublicKey: asn1.BitString{
|
||||
Bytes: publicKeyBytes,
|
||||
BitLength: 8 * len(publicKeyBytes),
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) GetPublicKey() (*btcec.PublicKey, error) {
|
||||
if c.GetChannel() == nil {
|
||||
return nil, errors.Err("claim is not of type channel, so there is no public key to get")
|
||||
}
|
||||
return getPublicKeyFromBytes(c.GetChannel().PublicKey)
|
||||
}
|
||||
|
||||
func getPublicKeyFromBytes(pubKeyBytes []byte) (*btcec.PublicKey, error) {
|
||||
PKInfo := publicKeyInfo{}
|
||||
asn1.Unmarshal(pubKeyBytes, &PKInfo)
|
||||
pubkeyBytes1 := []byte(PKInfo.PublicKey.Bytes)
|
||||
return btcec.ParsePubKey(pubkeyBytes1, btcec.S256())
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// The purpose of this test, is to make sure the function converts btcec.PublicKey to DER format the same way
|
||||
// lbry SDK does as this is the bytes that are put into protobuf and the same bytes are used for verify signatures.
|
||||
// Making sure these
|
||||
func TestPublicKeyToDER(t *testing.T) {
|
||||
cert_claim_hex := "08011002225e0801100322583056301006072a8648ce3d020106052b8104000a03420004d015365a40f3e5c03c87227168e5851f44659837bcf6a3398ae633bc37d04ee19baeb26dc888003bd728146dbea39f5344bf8c52cedaf1a3a1623a0166f4a367"
|
||||
cert_claim, err := DecodeClaimHex(cert_claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
p1, err := getPublicKeyFromBytes(cert_claim.Claim.GetChannel().PublicKey)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
pubkeyBytes2, err := PublicKeyToDER(p1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
for i, b := range cert_claim.Claim.GetChannel().PublicKey {
|
||||
assert.Assert(t, b == pubkeyBytes2[i], "DER format in bytes must match!")
|
||||
}
|
||||
|
||||
p2, err := getPublicKeyFromBytes(pubkeyBytes2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Assert(t, p1.IsEqual(p2), "The keys produced must be the same key!")
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
v1pb "github.com/lbryio/types/v1/go"
|
||||
pb "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
)
|
||||
|
||||
const lbrySDHash = "lbry_sd_hash"
|
||||
|
||||
func newStreamClaim() *pb.Claim {
|
||||
claimStream := new(pb.Claim_Stream)
|
||||
stream := new(pb.Stream)
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = claimStream
|
||||
claimStream.Stream = stream
|
||||
|
||||
return pbClaim
|
||||
}
|
||||
|
||||
func newChannelClaim() *pb.Claim {
|
||||
claimChannel := new(pb.Claim_Channel)
|
||||
channel := new(pb.Channel)
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = claimChannel
|
||||
claimChannel.Channel = channel
|
||||
|
||||
return pbClaim
|
||||
}
|
||||
|
||||
func setMetaData(claim *pb.Claim, author string, description string, language pb.Language_Language, license string,
|
||||
licenseURL *string, title string, thumbnail *string, nsfw bool) {
|
||||
claim.Title = title
|
||||
claim.Description = description
|
||||
|
||||
claim.GetStream().Author = author
|
||||
claim.Languages = []*pb.Language{{Language: language}}
|
||||
|
||||
if thumbnail != nil {
|
||||
source := new(pb.Source)
|
||||
source.Url = *thumbnail
|
||||
claim.Thumbnail = source
|
||||
}
|
||||
if nsfw {
|
||||
claim.Tags = []string{"mature"}
|
||||
}
|
||||
claim.GetStream().License = license
|
||||
if licenseURL != nil {
|
||||
claim.GetStream().LicenseUrl = *licenseURL
|
||||
}
|
||||
}
|
||||
|
||||
func migrateV1PBClaim(vClaim v1pb.Claim) (*pb.Claim, error) {
|
||||
if *vClaim.ClaimType == v1pb.Claim_streamType {
|
||||
return migrateV1PBStream(vClaim)
|
||||
}
|
||||
if *vClaim.ClaimType == v1pb.Claim_certificateType {
|
||||
return migrateV1PBChannel(vClaim)
|
||||
}
|
||||
return nil, errors.Err("Could not migrate v1 protobuf claim due to unknown type '%s'.", vClaim.ClaimType.String())
|
||||
}
|
||||
|
||||
func migrateV1PBStream(vClaim v1pb.Claim) (*pb.Claim, error) {
|
||||
claim := newStreamClaim()
|
||||
source := new(pb.Source)
|
||||
source.MediaType = vClaim.GetStream().GetSource().GetContentType()
|
||||
source.SdHash = vClaim.GetStream().GetSource().GetSource()
|
||||
claim.GetStream().Source = source
|
||||
md := vClaim.GetStream().GetMetadata()
|
||||
if md.GetFee() != nil {
|
||||
claim.GetStream().Fee = new(pb.Fee)
|
||||
claim.GetStream().GetFee().Amount = uint64(*md.GetFee().Amount * 100000000)
|
||||
claim.GetStream().GetFee().Address = md.GetFee().GetAddress()
|
||||
claim.GetStream().GetFee().Currency = pb.Fee_Currency(pb.Fee_Currency_value[md.GetFee().GetCurrency().String()])
|
||||
}
|
||||
if vClaim.GetStream().GetMetadata().GetNsfw() {
|
||||
claim.Tags = []string{"mature"}
|
||||
}
|
||||
thumbnailSource := new(pb.Source)
|
||||
thumbnailSource.Url = md.GetThumbnail()
|
||||
claim.Thumbnail = thumbnailSource
|
||||
language := pb.Language_Language(pb.Language_Language_value[md.GetLanguage().String()])
|
||||
claim.Languages = []*pb.Language{{Language: language}}
|
||||
claim.GetStream().LicenseUrl = md.GetLicenseUrl()
|
||||
claim.GetStream().License = md.GetLicense()
|
||||
claim.Title = md.GetTitle()
|
||||
claim.Description = md.GetDescription()
|
||||
claim.GetStream().Author = md.GetAuthor()
|
||||
|
||||
return claim, nil
|
||||
}
|
||||
|
||||
func migrateV1PBChannel(vClaim v1pb.Claim) (*pb.Claim, error) {
|
||||
claim := newChannelClaim()
|
||||
claim.GetChannel().PublicKey = vClaim.GetCertificate().PublicKey
|
||||
|
||||
return claim, nil
|
||||
}
|
||||
|
||||
func migrateV1Claim(vClaim V1Claim) (*pb.Claim, error) {
|
||||
pbClaim := newStreamClaim()
|
||||
//Stream
|
||||
// -->Universal
|
||||
setFee(vClaim.Fee, pbClaim)
|
||||
// -->MetaData
|
||||
language := pb.Language_Language(pb.Language_Language_value[vClaim.Language])
|
||||
setMetaData(pbClaim, vClaim.Author, vClaim.Description, language,
|
||||
vClaim.License, nil, vClaim.Title, vClaim.Thumbnail, false)
|
||||
// -->Source
|
||||
source := new(pb.Source)
|
||||
source.MediaType = vClaim.ContentType
|
||||
|
||||
src, err := hex.DecodeString(vClaim.Sources.LbrySDHash)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
source.SdHash = src
|
||||
pbClaim.GetStream().Source = source
|
||||
|
||||
return pbClaim, nil
|
||||
}
|
||||
|
||||
func migrateV2Claim(vClaim V2Claim) (*pb.Claim, error) {
|
||||
pbClaim := newStreamClaim()
|
||||
//Stream
|
||||
// -->Fee
|
||||
setFee(vClaim.Fee, pbClaim)
|
||||
// -->MetaData
|
||||
language := pb.Language_Language(pb.Language_Language_value[vClaim.Language])
|
||||
setMetaData(pbClaim, vClaim.Author, vClaim.Description, language,
|
||||
vClaim.License, vClaim.LicenseURL, vClaim.Title, vClaim.Thumbnail, vClaim.NSFW)
|
||||
// -->Source
|
||||
source := new(pb.Source)
|
||||
source.MediaType = vClaim.ContentType
|
||||
src, err := hex.DecodeString(vClaim.Sources.LbrySDHash)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
source.SdHash = src
|
||||
pbClaim.GetStream().Source = source
|
||||
|
||||
return pbClaim, nil
|
||||
}
|
||||
|
||||
func migrateV3Claim(vClaim V3Claim) (*pb.Claim, error) {
|
||||
pbClaim := newStreamClaim()
|
||||
//Stream
|
||||
// -->Fee
|
||||
setFee(vClaim.Fee, pbClaim)
|
||||
// -->MetaData
|
||||
language := pb.Language_Language(pb.Language_Language_value[vClaim.Language])
|
||||
setMetaData(pbClaim, vClaim.Author, vClaim.Description, language,
|
||||
vClaim.License, vClaim.LicenseURL, vClaim.Title, vClaim.Thumbnail, vClaim.NSFW)
|
||||
// -->Source
|
||||
source := new(pb.Source)
|
||||
source.MediaType = vClaim.ContentType
|
||||
src, err := hex.DecodeString(vClaim.Sources.LbrySDHash)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
source.SdHash = src
|
||||
pbClaim.GetStream().Source = source
|
||||
|
||||
return pbClaim, nil
|
||||
}
|
||||
|
||||
func setFee(fee *Fee, pbClaim *pb.Claim) {
|
||||
if fee != nil {
|
||||
amount := float32(0.0)
|
||||
currency := pb.Fee_LBC
|
||||
address := ""
|
||||
if fee.BTC != nil {
|
||||
amount = fee.BTC.Amount
|
||||
currency = pb.Fee_BTC
|
||||
address = fee.BTC.Address
|
||||
} else if fee.LBC != nil {
|
||||
amount = fee.LBC.Amount
|
||||
currency = pb.Fee_LBC
|
||||
address = fee.LBC.Address
|
||||
} else if fee.USD != nil {
|
||||
amount = fee.USD.Amount
|
||||
currency = pb.Fee_USD
|
||||
address = fee.USD.Address
|
||||
}
|
||||
pbClaim.GetStream().Fee = new(pb.Fee)
|
||||
//Fee Settings
|
||||
pbClaim.GetStream().GetFee().Amount = uint64(amount * 100000000)
|
||||
pbClaim.GetStream().GetFee().Currency = currency
|
||||
pbClaim.GetStream().GetFee().Address = base58.Decode(address)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/schema/address"
|
||||
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
type valueTestPair struct {
|
||||
ValueAsHex string
|
||||
Claim claimResult
|
||||
}
|
||||
|
||||
type claimResult struct {
|
||||
Version string
|
||||
Author string
|
||||
Title string
|
||||
Description string
|
||||
License string
|
||||
LicenseURL string
|
||||
FeeAmount float32
|
||||
FeeCurrency string
|
||||
FeeAddress string
|
||||
ContentType string
|
||||
Language string
|
||||
LbrySDHash string
|
||||
Thumbnail string
|
||||
NSFW bool
|
||||
}
|
||||
|
||||
var badJsonVersionTests = []string{
|
||||
"7b22666565223a20352c2022766572223a2022302e302e33222c20226c6963656e7365223a202247504c20332e30222c20226c616e6775616765223a2022656e222c2022617574686f72223a2022576f6e64657220576f6d616e2031393933222c20227469746c65223a2022576f6e64657220576f6d616e2031393933222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022323338663832363932356462323235353863646335636430373436303637626666393964636263333834333832666661303236646463373230373261366362323461393332346461373961626136643232373437313164653035353063396534227d2c20226e736677223a20747275652c2022636f6e74656e745f74797065223a2022696d6167652f6a706567222c20227468756d626e61696c223a2022687474703a2f2f692e696d6775722e636f6d2f4568344a4658732e6a7067222c20226465736372697074696f6e223a2022466f7220746865206c6f766521227d",
|
||||
"7b22666565223a2022302e303031222c2022766572223a2022302e302e33222c20226465736372697074696f6e223a20224120717569636b206c6f6f6b2061742074686520536f6e79204c44502033363030204c617365726469736320706c61796572222c20226c6963656e7365223a20224c42525920696e63222c20227469746c65223a2022536f6e79204c44502033363030204c617365726469736320506c61796572222c2022617574686f72223a20225061756c204b6176616e616768222c20226c616e6775616765223a2022656e222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022393962383766363064643136643730316538613562666238353130633938343239623866633563656538623764663333643665666135386464313133313261333665616437303638643133636364636331383563376465613730643930393261227d2c2022636f6e74656e745f74797065223a2022766964656f2f6d7034222c20226e736677223a2066616c73657d",
|
||||
"080110011ac3bd01080112c2b501080410011a0b57696e205465737420313122065465737420322a0444617665322e437265617469766520436f6d6d6f6e73204174747269627574696f6e20332e3020556e697465642053746174657338004224080110031a19556bc2a9c28bc2b057c3aec2901d5445c3b17cc384c3bd29c3b72b5f74101cc2aec2aac2a1250000c2b2424a0052005a3868747470733a2f2f6372656174697665636f6d6d6f6e732e6f72672f6c6963656e7365732f62792f332e302f75732f6c6567616c636f64651a41080110011a302a1ec2a42cc383223f7cc2b4c291353d0f687675c289c3a34cc3a73942c383c3abc3b7330dc3912d162ac388c3bec3a5c2aec293c2b1c38f68c3a2c2bfc2907a04c3b8c39dc2b1742209696d6167652f706e67",
|
||||
"7b22666565223a2022302e303031222c2022766572223a2022302e302e33222c20226465736372697074696f6e223a20224120717569636b206c6f6f6b2061742074686520536f6e79204c44502033363030204c617365726469736320706c61796572222c20226c6963656e7365223a20224c42525920696e63222c20227469746c65223a2022536f6e79204c44502033363030204c617365726469736320506c61796572222c2022617574686f72223a20225061756c204b6176616e616768222c20226c616e6775616765223a2022656e222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022393962383766363064643136643730316538613562666238353130633938343239623866633563656538623764663333643665666135386464313133313261333665616437303638643133636364636331383563376465613730643930393261227d2c2022636f6e74656e745f74797065223a2022766964656f2f6d7034222c20226e736677223a2066616c73657d",
|
||||
"7b22666565223a2022302e303031222c2022766572223a2022302e302e33222c20226465736372697074696f6e223a20224120717569636b206c6f6f6b2061742074686520536f6e79204c44502033363030204c617365726469736320706c61796572222c20226c6963656e7365223a20224c42525920696e63222c2022617574686f72223a20225061756c204b6176616e616768222c20227469746c65223a2022536f6e79204c44502033363030204c617365726469736320506c61796572222c20226c616e6775616765223a2022656e222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022626639663033333464623237393634303730663035636637356262376131626664663431363864356565376130633866373563663661623536653965633363643039633534636636383262353366316531353030363930616165353530663134227d2c2022636f6e74656e745f74797065223a2022766964656f2f6d7034222c20226e736677223a2066616c73657d",
|
||||
"30383031313030313161356330383031313231343038303431303030316130303232303032613030333230303338303034613030353230303561303031613432303830313130303131613330333933333030616561386262623636613238613966633031316231666238373634636364386338323633656233343532623733303832363233656534356431363866646530343836346435303563376535396539353430636263643766623336323230613639366436313637363532663661373036353637",
|
||||
}
|
||||
|
||||
var jsonVersionTests = []valueTestPair{
|
||||
{"7b22666565223a207b224c4243223a207b22616d6f756e74223a20312e302c202261646472657373223a2022625077474139683775696a6f79357541767a565051773951794c6f595a6568484a6f227d7d2c20226465736372697074696f6e223a2022313030304d4220746573742066696c6520746f206d65617375726520646f776e6c6f6164207370656564206f6e204c627279207032702d6e6574776f726b2e222c20226c6963656e7365223a20224e6f6e65222c2022617574686f72223a2022726f6f74222c20226c616e6775616765223a2022456e676c697368222c20227469746c65223a2022313030304d4220737065656420746573742066696c65222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022626439343033336431336634663339303837303837303163616635363562666130396366616466326633346661646634613733666238366232393564316232316137653634383035393934653435623566626336353066333062616334383734227d2c2022636f6e74656e742d74797065223a20226170706c69636174696f6e2f6f637465742d73747265616d222c20227468756d626e61696c223a20222f686f6d65726f626572742f6c6272792f73706565642e6a7067227d",
|
||||
claimResult{"0.0.1",
|
||||
"root",
|
||||
"1000MB speed test file",
|
||||
"1000MB test file to measure download speed on Lbry p2p-network.",
|
||||
"None",
|
||||
"",
|
||||
1,
|
||||
"LBC",
|
||||
"bPwGA9h7uijoy5uAvzVPQw9QyLoYZehHJo",
|
||||
"application/octet-stream",
|
||||
"", //"English" is not supported for conversion.
|
||||
"bd94033d13f4f3908708701caf565bfa09cfadf2f34fadf4a73fb86b295d1b21a7e64805994e45b5fbc650f30bac4874",
|
||||
"/homerobert/lbry/speed.jpg",
|
||||
false,
|
||||
},
|
||||
},
|
||||
{"7b22666565223a207b224c4243223a207b22616d6f756e74223a2035302e302c202261646472657373223a2022624c5673336966507275795a6e70596d46665432544c416d68715a76676a70514461227d7d2c20226465736372697074696f6e223a2022466f757220636f75706c6573206d65657420666f722053756e646179206272756e6368206f6e6c7920746f20646973636f76657220746865792061726520737475636b20696e206120686f75736520746f6765746865722061732074686520776f726c64206d61792062652061626f757420746f20656e642e222c20226c6963656e7365223a20224f7363696c6c6f73636f7065204c61626f7261746f72696573222c2022617574686f72223a20225772697474656e20616e6420646972656374656420627920546f646420426572676572222c20226c616e6775616765223a2022656e222c20227469746c65223a2022497427732061204469736173746572222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022646363316266323838393361353033376561623965346139636437613462666536663736616436633231393730656134636565653031323266353032656630373936353764346463613435366234626533323439383439633465313836386238227d2c2022636f6e74656e742d74797065223a2022766964656f2f717569636b74696d65222c20227468756d626e61696c223a2022687474703a2f2f69612e6d656469612d696d64622e636f6d2f696d616765732f4d2f4d5635424d5451774e6a597a4d5451304d6c35424d6c3542616e426e586b46745a5463774e44557a4f444d354e7740402e5f56315f5359313030305f4352302c302c3637332c313030305f414c5f2e6a7067227d",
|
||||
claimResult{"0.0.1",
|
||||
"Written and directed by Todd Berger",
|
||||
"It's a Disaster",
|
||||
"Four couples meet for Sunday brunch only to discover they are stuck in a house together as the world may be about to end.",
|
||||
"Oscilloscope Laboratories",
|
||||
"",
|
||||
50,
|
||||
"LBC",
|
||||
"bLVs3ifPruyZnpYmFfT2TLAmhqZvgjpQDa",
|
||||
"video/quicktime",
|
||||
"language:en ",
|
||||
"dcc1bf28893a5037eab9e4a9cd7a4bfe6f76ad6c21970ea4ceee0122f502ef079657d4dca456b4be3249849c4e1868b8",
|
||||
"http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg",
|
||||
false,
|
||||
},
|
||||
},
|
||||
{"7b226465736372697074696f6e223a202241647669736f7220416c6578205461626172726f6b206769766573206869732074616b65206f6e204c4252592e222c20226c6963656e7365223a20224c4252592c20496e632e222c2022617574686f72223a202253616d75656c20427279616e222c20226c616e6775616765223a2022656e222c20227469746c65223a20224d65657420746865205465616d20457069736f64652031222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022373939613164653933623865353536643766363638313033613666666334386163356664363830316464346438396361653637373363383064383163323833373130666434666432356564363864306462656565323638663832393134313435227d2c2022636f6e74656e742d74797065223a2022766964656f2f6d7034227d",
|
||||
claimResult{"0.0.1",
|
||||
"Samuel Bryan",
|
||||
"Meet the Team Episode 1",
|
||||
"Advisor Alex Tabarrok gives his take on LBRY.",
|
||||
"LBRY, Inc.",
|
||||
"",
|
||||
0,
|
||||
"UNKNOWN_CURRENCY",
|
||||
"",
|
||||
"video/mp4",
|
||||
"language:en ",
|
||||
"799a1de93b8e556d7f668103a6ffc48ac5fd6801dd4d89cae6773c80d81c283710fd4fd25ed68d0dbeee268f82914145",
|
||||
"http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg",
|
||||
false,
|
||||
},
|
||||
},
|
||||
{"7b226c616e6775616765223a2022656e222c2022666565223a207b22555344223a207b22616d6f756e74223a20302e30312c202261646472657373223a2022624d486d5a4b5a6250713662504245514663384d5870694468463966374d56784d52227d7d2c2022736f7572636573223a207b226c6272795f73645f68617368223a2022326264386439646431613231386337663536373137653533666135313065666435613863303839656431663236373561306638643062356238626233633165643338336362396633616562396238393137383937363133303532393339373961227d2c20226465736372697074696f6e223a2022636c6f756473222c20226c6963656e7365223a2022637265617469766520636f6d6d6f6e73222c2022617574686f72223a202268747470733a2f2f7777772e76696465657a792e636f6d2f636c6f7564732f323637362d6461726b2d73746f726d2d636c6f7564732d726f79616c74792d667265652d68642d73746f636b2d766964656f222c20226e736677223a2066616c73652c20227469746c65223a2022636c6f756473222c2022636f6e74656e742d74797065223a2022766964656f2f6d7034222c2022766572223a2022302e302e32227d",
|
||||
claimResult{"0.0.2",
|
||||
"https://www.videezy.com/clouds/2676-dark-storm-clouds-royalty-free-hd-stock-video",
|
||||
"clouds",
|
||||
"clouds",
|
||||
"creative commons",
|
||||
"",
|
||||
0.01,
|
||||
"USD",
|
||||
"bMHmZKZbPq6bPBEQFc8MXpiDhF9f7MVxMR",
|
||||
"video/mp4",
|
||||
"language:en ",
|
||||
"2bd8d9dd1a218c7f56717e53fa510efd5a8c089ed1f2675a0f8d0b5b8bb3c1ed383cb9f3aeb9b891789761305293979a",
|
||||
"",
|
||||
false,
|
||||
},
|
||||
},
|
||||
{"7b226c6963656e7365223a2022437265617469766520436f6d6d6f6e73204174747269627574696f6e20332e3020556e6974656420537461746573222c2022666565223a207b224c4243223a207b22616d6f756e74223a20312c202261646472657373223a20226256507157775966766a424859426f7575766b6e62514d58555a46764c644573354d227d7d2c2022766572223a2022302e302e32222c20226465736372697074696f6e223a20227a222c20226c616e6775616765223a2022656e222c2022617574686f72223a202279222c20227469746c65223a202278222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022376332316565323337333234653561353061333432353632306665366363343030643363636363303535313938363763646131623963313061393737313934653331323030343134643837313436626666343730626162376637643735343738227d2c20226e736677223a2066616c73652c20226c6963656e73655f75726c223a202268747470733a2f2f6372656174697665636f6d6d6f6e732e6f72672f6c6963656e7365732f62792f332e302f75732f6c6567616c636f6465222c2022636f6e74656e742d74797065223a2022746578742f706c61696e227d",
|
||||
claimResult{"0.0.2",
|
||||
"y",
|
||||
"x",
|
||||
"z",
|
||||
"Creative Commons Attribution 3.0 United States",
|
||||
"https://creativecommons.org/licenses/by/3.0/us/legalcode",
|
||||
1,
|
||||
"LBC",
|
||||
"bVPqWwYfvjBHYBouuvknbQMXUZFvLdEs5M",
|
||||
"text/plain",
|
||||
"language:en ",
|
||||
"7c21ee237324e5a50a3425620fe6cc400d3cccc05519867cda1b9c10a977194e31200414d87146bff470bab7f7d75478",
|
||||
"",
|
||||
false,
|
||||
},
|
||||
},
|
||||
{"7b22666565223a207b22555344223a207b22616d6f756e74223a20302e342c202261646472657373223a202262485365334b417674565352346d365331317a6475754639584874777363446a6f45227d7d2c2022766572223a2022302e302e33222c20226c6963656e7365223a2022437265617469766520436f6d6d6f6e73204174747269627574696f6e20332e3020556e6974656420537461746573222c20226c616e6775616765223a2022656e222c20227469746c65223a2022526561647920506c61796572204f6e652028417564696f626f6f6b2031206f66203229222c2022617574686f72223a202245726e65737420436c696e65222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022333430653164646130653834313463323166616662623166323866326338623338343832316665306431653261373134336134383130353435653634653236613431303530343264346434376463393735346236313865636466653064313931227d2c20226e736677223a2066616c73652c2022636f6e74656e745f74797065223a2022617564696f2f6d706567222c20226c6963656e73655f75726c223a202268747470733a2f2f6372656174697665636f6d6d6f6e732e6f72672f6c6963656e7365732f62792f332e302f75732f6c6567616c636f6465222c20227468756d626e61696c223a2022687474703a2f2f692e696d6775722e636f6d2f6c794b45485a632e6a7067222c20226465736372697074696f6e223a2022496e20746865207965617220323034342c2074686520776f726c64206973206772697070656420627920616e20656e65726779206372697369732063617573696e67207769646573707265616420736f6369616c2070726f626c656d7320616e642065636f6e6f6d696320737461676e6174696f6e2e20546865207072696d6172792065736361706520666f72206d6f73742070656f706c6520697320746865204f415349532c2061207669727475616c20756e6976657273652c20616363657373656420776974682061207669736f7220616e642068617074696320676c6f7665732e2049742066756e6374696f6e7320626f746820617320616e204d4d4f52504720616e642061732061207669727475616c20736f63696574792c2077697468206974732063757272656e6379206265696e6720746865206d6f737420737461626c652063757272656e637920696e2074686520776f726c642e204974207761732063726561746564206279204a616d65732048616c6c696461792c2077686f73652077696c6c206c656674206120736572696573206f6620636c75657320746f776172647320616e20456173746572204567672077697468696e20746865204f41534953207468617420776f756c64206772616e742077686f6576657220666f756e6420697420626f74682068697320666f7274756e6520616e6420636f6e74726f6c206f6620746865204f4153495320697473656c662e205468697320686173206c656420746f20616e20696e74656e736520696e74657265737420696e20616c6c2061737065637473206f662038307320706f702063756c747572652c2077686963682048616c6c69646179206d61646520636c65617220776f756c6420626520657373656e7469616c20746f2066696e64696e6720686973206567672e227d",
|
||||
claimResult{"0.0.3",
|
||||
"Ernest Cline",
|
||||
"Ready Player One (Audiobook 1 of 2)",
|
||||
"In the year 2044, the world is gripped by an energy crisis causing widespread social problems and economic stagnation. The primary escape for most people is the OASIS, a virtual universe, accessed with a visor and haptic gloves. It functions both as an MMORPG and as a virtual society, with its currency being the most stable currency in the world. It was created by James Halliday, whose will left a series of clues towards an Easter Egg within the OASIS that would grant whoever found it both his fortune and control of the OASIS itself. This has led to an intense interest in all aspects of 80s pop culture, which Halliday made clear would be essential to finding his egg.",
|
||||
"Creative Commons Attribution 3.0 United States",
|
||||
"https://creativecommons.org/licenses/by/3.0/us/legalcode",
|
||||
0.4,
|
||||
"USD",
|
||||
"bHSe3KAvtVSR4m6S11zduuF9XHtwscDjoE",
|
||||
"audio/mpeg",
|
||||
"language:en ",
|
||||
"340e1dda0e8414c21fafbb1f28f2c8b384821fe0d1e2a7143a4810545e64e26a4105042d4d47dc9754b618ecdfe0d191",
|
||||
"http://i.imgur.com/lyKEHZc.jpg",
|
||||
false,
|
||||
},
|
||||
},
|
||||
{"7b22666565223a207b224c4243223a207b22616d6f756e74223a20312c202261646472657373223a202262525478744355706a3654764a48675763527347634861467972524c6b6b69586747227d7d2c2022766572223a2022302e302e33222c20226c6963656e7365223a2022436f707972696768742032303136206272617a7a657273222c20226c616e6775616765223a2022656e222c20227469746c65223a2022686f7420706f726e222c2022617574686f72223a20226272617a7a657273222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022666330646163356366633532363335343936336666313736396636653733396334653432613037393034323066666162396661336236343031653933616535613035313565666639363066386339633237323930376564613666636261323534227d2c20226e736677223a20747275652c2022636f6e74656e745f74797065223a2022766964656f2f6d7034222c20226465736372697074696f6e223a2022686f7420706f726e5c6e6272617a7a657273227d",
|
||||
claimResult{"0.0.3",
|
||||
"brazzers",
|
||||
"hot porn",
|
||||
"hot porn\nbrazzers",
|
||||
"Copyright 2016 brazzers",
|
||||
"",
|
||||
1,
|
||||
"LBC",
|
||||
"bRTxtCUpj6TvJHgWcRsGcHaFyrRLkkiXgG",
|
||||
"video/mp4",
|
||||
"language:en ",
|
||||
"fc0dac5cfc526354963ff1769f6e739c4e42a0790420ffab9fa3b6401e93ae5a0515eff960f8c9c272907eda6fcba254",
|
||||
"",
|
||||
true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestBadMigrationFromJSON(t *testing.T) {
|
||||
for _, hexStr := range badJsonVersionTests {
|
||||
valueBytes, err := hex.DecodeString(hexStr)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = DecodeClaimBytes(valueBytes, "lbrycrd_main")
|
||||
if err == nil {
|
||||
t.Error(fmt.Sprintf("Decode error: The raw claim '%s' should have failed decoding.", hexStr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrationFromJSON(t *testing.T) {
|
||||
for _, pair := range jsonVersionTests {
|
||||
valueBytes, err := hex.DecodeString(pair.ValueAsHex)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
helper, err := DecodeClaimBytes(valueBytes, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error("Decode error: ", err)
|
||||
}
|
||||
if helper.Claim.GetStream().GetAuthor() != pair.Claim.Author {
|
||||
t.Error("Author mismatch: expected", pair.Claim.Author, "got", helper.Claim.GetStream().GetAuthor())
|
||||
}
|
||||
if helper.Claim.GetTitle() != pair.Claim.Title {
|
||||
t.Error("Title mismatch: expected", pair.Claim.Title, "got '", helper.Claim.GetTitle(), "'")
|
||||
}
|
||||
if helper.Claim.GetDescription() != pair.Claim.Description {
|
||||
t.Error("Description mismatch: expected", pair.Claim.Description, "got '", helper.Claim.GetDescription(), "'")
|
||||
}
|
||||
if helper.Claim.GetStream().GetLicense() != pair.Claim.License {
|
||||
t.Error("License mismatch: expected", pair.Claim.License, "got", helper.Claim.GetStream().GetLicense())
|
||||
}
|
||||
if helper.Claim.GetStream().GetLicenseUrl() != pair.Claim.LicenseURL {
|
||||
t.Error("LicenseURL mismatch: expected", pair.Claim.LicenseURL, "got", helper.Claim.GetStream().GetLicenseUrl())
|
||||
}
|
||||
if helper.Claim.GetStream().GetFee().GetAmount() != uint64(pair.Claim.FeeAmount*100000000) {
|
||||
t.Error("Fee Amount mismatch: expected", pair.Claim.FeeAmount, "got", helper.Claim.GetStream().GetFee().GetAmount())
|
||||
}
|
||||
if helper.Claim.GetStream().GetFee().GetCurrency().String() != pair.Claim.FeeCurrency {
|
||||
t.Error("Fee Currency mismatch: expected", pair.Claim.FeeCurrency, "got", helper.Claim.GetStream().GetFee().GetCurrency())
|
||||
}
|
||||
hexaddress := base58.Encode(helper.Claim.GetStream().GetFee().GetAddress())
|
||||
if hexaddress != pair.Claim.FeeAddress {
|
||||
t.Error("Fee Address mismatch: expected", pair.Claim.FeeAddress, "got", hexaddress)
|
||||
}
|
||||
if helper.Claim.GetStream().GetSource().GetMediaType() != pair.Claim.ContentType {
|
||||
t.Error("ContentType mismatch: expected", pair.Claim.ContentType, "got", helper.Claim.GetStream().GetSource().GetMediaType())
|
||||
}
|
||||
if helper.Claim.GetLanguages()[0].String() != pair.Claim.Language {
|
||||
t.Error("Language mismatch: expected ", pair.Claim.Language, " got ", helper.Claim.GetLanguages()[0].String())
|
||||
}
|
||||
content := hex.EncodeToString(helper.Claim.GetStream().GetSource().GetSdHash())
|
||||
if content != pair.Claim.LbrySDHash {
|
||||
t.Error("Source mismatch: expected", pair.Claim.LbrySDHash, "got", content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrationFromV1YTSync(t *testing.T) {
|
||||
claimHex := "080110011aee04080112a604080410011a2b4865726520617265203520526561736f6e73204920e29da4efb88f204e657874636c6f7564207c20544c4722920346696e64206f7574206d6f72652061626f7574204e657874636c6f75643a2068747470733a2f2f6e657874636c6f75642e636f6d2f0a0a596f752063616e2066696e64206d65206f6e20746865736520736f6369616c733a0a202a20466f72756d733a2068747470733a2f2f666f72756d2e6865617679656c656d656e742e696f2f0a202a20506f64636173743a2068747470733a2f2f6f6666746f706963616c2e6e65740a202a2050617472656f6e3a2068747470733a2f2f70617472656f6e2e636f6d2f7468656c696e757867616d65720a202a204d657263683a2068747470733a2f2f746565737072696e672e636f6d2f73746f7265732f6f6666696369616c2d6c696e75782d67616d65720a202a205477697463683a2068747470733a2f2f7477697463682e74762f786f6e64616b0a202a20547769747465723a2068747470733a2f2f747769747465722e636f6d2f7468656c696e757867616d65720a0a2e2e2e0a68747470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d4672546442434f535f66632a0f546865204c696e75782047616d6572321c436f7079726967687465642028636f6e7461637420617574686f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f4672546442434f535f666352005a001a41080110011a30040e8ac6e89c061f982528c23ad33829fd7146435bf7a4cc22f0bff70c4fe0b91fd36da9a375e3e1c171db825bf5d1f32209766964656f2f6d70342a5c080110031a4062b2dd4c45e364030fbfad1a6fefff695ebf20ea33a5381b947753e2a0ca359989a5cc7d15e5392a0d354c0b68498382b2701b22c03beb8dcb91089031b871e72214feb61536c007cdf4faeeaab4876cb397feaf6b51"
|
||||
claim, err := DecodeClaimHex(claimHex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Assert(t, claim.GetTitle() == "Here are 5 Reasons I ❤️ Nextcloud | TLG")
|
||||
assert.Assert(t, claim.GetDescription() == "Find out more about Nextcloud: https://nextcloud.com/\n\nYou can find me on these socials:\n * Forums: https://forum.heavyelement.io/\n * Podcast: https://offtopical.net\n * Patreon: https://patreon.com/thelinuxgamer\n * Merch: https://teespring.com/stores/official-linux-gamer\n * Twitch: https://twitch.tv/xondak\n * Twitter: https://twitter.com/thelinuxgamer\n\n...\nhttps://www.youtube.com/watch?v=FrTdBCOS_fc")
|
||||
assert.Assert(t, claim.GetStream().GetLicense() == "Copyrighted (contact author)")
|
||||
assert.Assert(t, claim.GetStream().GetAuthor() == "The Linux Gamer")
|
||||
//?assert.Assert(t, claim.GetStream().GetLanguages()[0])
|
||||
assert.Assert(t, claim.GetStream().GetSource().GetMediaType() == "video/mp4")
|
||||
assert.Assert(t, claim.GetThumbnail().GetUrl() == "https://berk.ninja/thumbnails/FrTdBCOS_fc")
|
||||
sdHashBytes, err := hex.DecodeString("040e8ac6e89c061f982528c23ad33829fd7146435bf7a4cc22f0bff70c4fe0b91fd36da9a375e3e1c171db825bf5d1f3")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Assert(t, bytes.Equal(claim.GetStream().GetSource().GetSdHash(), sdHashBytes))
|
||||
|
||||
channelHex := "08011002225e0801100322583056301006072a8648ce3d020106052b8104000a034200043878b1edd4a1373149909ef03f4339f6da9c2bd2214c040fd2e530463ffe66098eca14fc70b50ff3aefd106049a815f595ed5a13eda7419ad78d9ed7ae473f17"
|
||||
channel, err := DecodeClaimHex(channelHex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
pubKeyBytes, err := hex.DecodeString("3056301006072a8648ce3d020106052b8104000a034200043878b1edd4a1373149909ef03f4339f6da9c2bd2214c040fd2e530463ffe66098eca14fc70b50ff3aefd106049a815f595ed5a13eda7419ad78d9ed7ae473f17")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Assert(t, bytes.Equal(pubKeyBytes, channel.GetChannel().GetPublicKey()))
|
||||
}
|
||||
|
||||
func TestMigrationFromV1UnsignedWithFee(t *testing.T) {
|
||||
claimHex := "080110011ad6010801127c080410011a08727067206d69646922046d6964692a08727067206d696469322e437265617469766520436f6d6d6f6e73204174747269627574696f6e20342e3020496e7465726e6174696f6e616c38004224080110011a19553f00bc139bbf40de425f94d51fffb34c1bea6d9171cd374c25000070414a0052005a001a54080110011a301f41eb0312aa7e8a5ce49349bc77d811da975833719d751523b19f123fc3d528d6a94e3446ccddb7b9329f27a9cad7e3221c6170706c69636174696f6e2f782d7a69702d636f6d70726573736564"
|
||||
claim, err := DecodeClaimHex(claimHex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Assert(t, claim.GetTitle() == "rpg midi")
|
||||
assert.Assert(t, claim.GetDescription() == "midi")
|
||||
assert.Assert(t, claim.GetStream().GetLicense() == "Creative Commons Attribution 4.0 International")
|
||||
assert.Assert(t, claim.GetStream().GetAuthor() == "rpg midi")
|
||||
//assert.Assert(t, claim.GetStream().GetLanguage() == "en")
|
||||
assert.Assert(t, claim.GetStream().GetSource().GetMediaType() == "application/x-zip-compressed")
|
||||
sdHashBytes, err := hex.DecodeString("1f41eb0312aa7e8a5ce49349bc77d811da975833719d751523b19f123fc3d528d6a94e3446ccddb7b9329f27a9cad7e3")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Assert(t, bytes.Equal(claim.GetStream().GetSource().GetSdHash(), sdHashBytes))
|
||||
feeAddressBytes, err := address.DecodeAddress("bJUQ9MxS9N6M29zsA5GTpVSDzsnPjMBBX9", "lbrycrd_main")
|
||||
assert.Assert(t, bytes.Equal(claim.GetStream().GetFee().GetAddress(), feeAddressBytes[:]))
|
||||
assert.Assert(t, claim.GetStream().GetFee().GetAmount() == 1500000000)
|
||||
assert.Assert(t, claim.GetStream().GetFee().GetCurrency().String() == "LBC")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
)
|
||||
|
||||
func marshalToString(c *ClaimHelper) (string, error) {
|
||||
m_pb := &jsonpb.Marshaler{}
|
||||
return m_pb.MarshalToString(c)
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) RenderJSON() (string, error) {
|
||||
r, err := marshalToString(c)
|
||||
if err != nil {
|
||||
fmt.Println("err")
|
||||
return "", err
|
||||
}
|
||||
var dat map[string]interface{}
|
||||
err = json.Unmarshal([]byte(r), &dat)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
//TODO: encode byte arrays with b58 for addresses and b16 for source hashes instead of the default of b64
|
||||
@@ -0,0 +1,125 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
)
|
||||
|
||||
// V1Claim is the first version of claim metadata used by lbry.
|
||||
type V1Claim struct {
|
||||
Version string `json:"ver,omitempty"`
|
||||
Title string `json:"title"` //Required
|
||||
Description string `json:"description"` //Required
|
||||
Author string `json:"author"` //Required
|
||||
Language string `json:"language"` //Required
|
||||
License string `json:"license"` //Required
|
||||
Sources Sources `json:"sources"` //Required
|
||||
ContentType string `json:"content-type"` //Required
|
||||
Thumbnail *string `json:"thumbnail,omitempty"`
|
||||
Fee *Fee `json:"fee,omitempty"`
|
||||
Contact *int `json:"contact,omitempty"`
|
||||
PubKey *string `json:"pubkey,omitempty"`
|
||||
}
|
||||
|
||||
// V2Claim is the second version of claim metadata used by lbry.
|
||||
type V2Claim struct {
|
||||
Version string `json:"ver"` //Required
|
||||
Title string `json:"title"` //Required
|
||||
Description string `json:"description"` //Required
|
||||
Author string `json:"author"` //Required
|
||||
Language string `json:"language"` //Required
|
||||
License string `json:"license"` //Required
|
||||
Sources Sources `json:"sources"` //Required
|
||||
ContentType string `json:"content-type"` //Required
|
||||
Thumbnail *string `json:"thumbnail,omitempty"`
|
||||
Fee *Fee `json:"fee,omitempty"`
|
||||
Contact *int `json:"contact,omitempty"`
|
||||
PubKey *string `json:"pubkey,omitempty"`
|
||||
LicenseURL *string `json:"license_url,omitempty"`
|
||||
NSFW bool `json:"nsfw"` //Required
|
||||
|
||||
}
|
||||
|
||||
// V3Claim is the third version of claim metadata used by lbry.
|
||||
type V3Claim struct {
|
||||
Version string `json:"ver"` //Required
|
||||
Title string `json:"title"` //Required
|
||||
Description string `json:"description"` //Required
|
||||
Author string `json:"author"` //Required
|
||||
Language string `json:"language"` //Required
|
||||
License string `json:"license"` //Required
|
||||
Sources Sources `json:"sources"` //Required
|
||||
ContentType string `json:"content_type"` //Required
|
||||
Thumbnail *string `json:"thumbnail,omitempty"`
|
||||
Fee *Fee `json:"fee,omitempty"`
|
||||
Contact *int `json:"contact,omitempty"`
|
||||
PubKey *string `json:"pubkey,omitempty"`
|
||||
LicenseURL *string `json:"license_url,omitempty"`
|
||||
NSFW bool `json:"nsfw"` //Required
|
||||
Sig *string `json:"sig"`
|
||||
}
|
||||
|
||||
// FeeInfo is the structure of fee information used by lbry.
|
||||
type FeeInfo struct {
|
||||
Amount float32 `json:"amount"` //Required
|
||||
Address string `json:"address"` //Required
|
||||
}
|
||||
|
||||
// Sources is the structure of Sources that can be used for a claim. Sources mainly include lbrysdhash but could be from
|
||||
// elsewhere in the future.
|
||||
type Sources struct {
|
||||
LbrySDHash string `json:"lbry_sd_hash"` //Required
|
||||
BTIH string `json:"btih"` //Required
|
||||
URL string `json:"url"` //Required
|
||||
}
|
||||
|
||||
// Fee is the structure used for different currencies allowed for claims.
|
||||
type Fee struct {
|
||||
LBC *FeeInfo `json:"LBC,omitempty"`
|
||||
BTC *FeeInfo `json:"BTC,omitempty"`
|
||||
USD *FeeInfo `json:"USD,omitempty"`
|
||||
}
|
||||
|
||||
// Unmarshal is an implementation to unmarshal the V1 claim from json. Main addition is to check the version.
|
||||
func (c *V1Claim) Unmarshal(value []byte) error {
|
||||
err := json.Unmarshal(value, c)
|
||||
if err != nil {
|
||||
return err
|
||||
} //Version can be blank for version 1
|
||||
if c.Version != "" && c.Version != "0.0.1" {
|
||||
err = errors.Base("Incorrect version, expected 0.0.1 found " + c.Version)
|
||||
return err
|
||||
}
|
||||
//ToDo - restrict to required fields?
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unmarshal is an implementation to unmarshal the V2 claim from json. Main addition is to check the version.
|
||||
func (c *V2Claim) Unmarshal(value []byte) error {
|
||||
err := json.Unmarshal(value, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c.Version != "0.0.2" {
|
||||
err = errors.Base("Incorrect version, expected 0.0.2 found " + c.Version)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unmarshal is an implementation to unmarshal the V3 claim from json. Main addition is to check the version.
|
||||
func (c *V3Claim) Unmarshal(value []byte) error {
|
||||
err := json.Unmarshal(value, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c.Version != "0.0.3" {
|
||||
err = errors.Base("Incorrect version, expected 0.0.3 found " + c.Version)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
legacy "github.com/lbryio/types/v1/go"
|
||||
pb "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func (c *ClaimHelper) serialized() ([]byte, error) {
|
||||
serialized := c.String()
|
||||
if serialized == "" {
|
||||
return nil, errors.Err("not initialized")
|
||||
}
|
||||
|
||||
if c.LegacyClaim != nil {
|
||||
return proto.Marshal(c.getLegacyProtobuf())
|
||||
}
|
||||
|
||||
return proto.Marshal(c.getProtobuf())
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) getProtobuf() *pb.Claim {
|
||||
claim := &pb.Claim{
|
||||
Title: c.GetTitle(),
|
||||
Description: c.GetDescription(),
|
||||
Thumbnail: c.GetThumbnail(),
|
||||
Tags: c.GetTags(),
|
||||
Languages: c.GetLanguages(),
|
||||
Locations: c.GetLocations(),
|
||||
}
|
||||
if c.GetChannel() != nil {
|
||||
claim.Type = &pb.Claim_Channel{Channel: c.GetChannel()}
|
||||
} else if c.GetStream() != nil {
|
||||
claim.Type = &pb.Claim_Stream{Stream: c.GetStream()}
|
||||
} else if c.GetCollection() != nil {
|
||||
claim.Type = &pb.Claim_Collection{Collection: c.GetCollection()}
|
||||
} else if c.GetRepost() != nil {
|
||||
claim.Type = &pb.Claim_Repost{Repost: c.GetRepost()}
|
||||
}
|
||||
|
||||
return claim
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) getLegacyProtobuf() *legacy.Claim {
|
||||
v := c.LegacyClaim.GetVersion()
|
||||
t := c.LegacyClaim.GetClaimType()
|
||||
return &legacy.Claim{
|
||||
Version: &v,
|
||||
ClaimType: &t,
|
||||
Stream: c.LegacyClaim.GetStream(),
|
||||
Certificate: c.LegacyClaim.GetCertificate(),
|
||||
PublisherSignature: c.LegacyClaim.GetPublisherSignature()}
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) serializedHexString() (string, error) {
|
||||
serialized, err := c.serialized()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
serialized_hex := hex.EncodeToString(serialized)
|
||||
return serialized_hex, nil
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) serializedNoSignature() ([]byte, error) {
|
||||
if c.String() == "" {
|
||||
return nil, errors.Err("not initialized")
|
||||
}
|
||||
if c.Signature == nil {
|
||||
serialized, err := c.serialized()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return serialized, nil
|
||||
} else {
|
||||
if c.LegacyClaim != nil {
|
||||
clone := &legacy.Claim{}
|
||||
proto.Merge(clone, c.getLegacyProtobuf())
|
||||
proto.ClearAllExtensions(clone.PublisherSignature)
|
||||
clone.PublisherSignature = nil
|
||||
return proto.Marshal(clone)
|
||||
}
|
||||
clone := &pb.Claim{}
|
||||
proto.Merge(clone, c.getProtobuf())
|
||||
return proto.Marshal(clone)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/schema/address"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
)
|
||||
|
||||
func Sign(privKey btcec.PrivateKey, channel ClaimHelper, claim ClaimHelper, k string) (*Signature, error) {
|
||||
if channel.GetChannel() == nil {
|
||||
return nil, errors.Err("claim as channel is not of type channel")
|
||||
}
|
||||
if claim.LegacyClaim != nil {
|
||||
return claim.signV1(privKey, channel, k)
|
||||
}
|
||||
|
||||
return claim.sign(privKey, channel, k)
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) sign(privKey btcec.PrivateKey, channel ClaimHelper, firstInputTxID string) (*Signature, error) {
|
||||
|
||||
txidBytes, err := hex.DecodeString(firstInputTxID)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
metadataBytes, err := c.serialized()
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
var digest []byte
|
||||
digest = append(digest, txidBytes...)
|
||||
digest = append(digest, c.ClaimID...)
|
||||
digest = append(digest, metadataBytes...)
|
||||
hash := sha256.Sum256(digest)
|
||||
hashBytes := make([]byte, len(hash))
|
||||
for i, b := range hash {
|
||||
hashBytes[i] = b
|
||||
}
|
||||
|
||||
sig, err := privKey.Sign(hashBytes)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
return &Signature{*sig}, nil
|
||||
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) signV1(privKey btcec.PrivateKey, channel ClaimHelper, claimAddress string) (*Signature, error) {
|
||||
metadataBytes, err := c.serializedNoSignature()
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
addressBytes, err := address.DecodeAddress(claimAddress, "lbrycrd_main")
|
||||
if err != nil {
|
||||
return nil, errors.Prefix("V1 signing requires claim address and the decode failed with: ", err)
|
||||
}
|
||||
|
||||
var digest []byte
|
||||
|
||||
address := make([]byte, len(addressBytes))
|
||||
for i, b := range addressBytes {
|
||||
address[i] = b
|
||||
}
|
||||
|
||||
digest = append(digest, address...)
|
||||
digest = append(digest, metadataBytes...)
|
||||
digest = append(digest, channel.ClaimID...)
|
||||
|
||||
hash := sha256.Sum256(digest)
|
||||
hashBytes := make([]byte, len(hash))
|
||||
for i, b := range hash {
|
||||
hashBytes[i] = b
|
||||
}
|
||||
|
||||
sig, err := privKey.Sign(hashBytes)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
return &Signature{*sig}, nil
|
||||
}
|
||||
|
||||
type Signature struct {
|
||||
btcec.Signature
|
||||
}
|
||||
|
||||
func (s *Signature) LBRYSDKEncode() ([]byte, error) {
|
||||
if s.R == nil || s.S == nil {
|
||||
return nil, errors.Err("invalid signature, both S & R are nil")
|
||||
}
|
||||
rBytes := s.R.Bytes()
|
||||
sBytes := s.S.Bytes()
|
||||
|
||||
return append(rBytes, sBytes...), nil
|
||||
}
|
||||
|
||||
// rev reverses a byte slice. useful for switching endian-ness
|
||||
func reverseBytes(b []byte) []byte {
|
||||
r := make([]byte, len(b))
|
||||
for left, right := 0, len(b)-1; left < right; left, right = left+1, right-1 {
|
||||
r[left], r[right] = b[right], b[left]
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func TestSign(t *testing.T) {
|
||||
privateKey, err := btcec.NewPrivateKey(btcec.S256())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
channel := &ClaimHelper{newChannelClaim(), nil, nil, NoSig, nil, nil}
|
||||
pubkeyBytes, err := PublicKeyToDER(privateKey.PubKey())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
channel.GetChannel().PublicKey = pubkeyBytes
|
||||
claimID := "cf3f7c898af87cc69b06a6ac7899efb9a4878fdb" //Fake
|
||||
txid := "4c1df9e022e396859175f9bfa69b38e444db10fb53355fa99a0989a83bcdb82f" //Fake
|
||||
claimIDHexBytes, err := hex.DecodeString(claimID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
claim := &ClaimHelper{newStreamClaim(), nil, reverseBytes(claimIDHexBytes), WithSig, nil, nil}
|
||||
claim.Claim.Title = "Test title"
|
||||
claim.Claim.Description = "Test description"
|
||||
sig, err := Sign(*privateKey, *channel, *claim, txid)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
signatureBytes, err := sig.LBRYSDKEncode()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
claim.Signature = signatureBytes
|
||||
|
||||
rawChannel, err := channel.CompileValue()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
rawClaim, err := claim.CompileValue()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
channel, err = DecodeClaimBytes(rawChannel, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
claim, err = DecodeClaimBytes(rawClaim, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
valid, err := claim.ValidateClaimSignature(channel, txid, claimID, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
assert.Assert(t, valid, "could not verify signature")
|
||||
|
||||
}
|
||||
|
||||
func TestSignWithV1Channel(t *testing.T) {
|
||||
cert_claim_hex := "08011002225e0801100322583056301006072a8648ce3d020106052b8104000a03420004d015365a40f3e5c03c87227168e5851f44659837bcf6a3398ae633bc37d04ee19baeb26dc888003bd728146dbea39f5344bf8c52cedaf1a3a1623a0166f4a367"
|
||||
channel, err := DecodeClaimHex(cert_claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
privateKey, err := btcec.NewPrivateKey(btcec.S256())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
pubkeyBytes, err := PublicKeyToDER(privateKey.PubKey())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
channel.GetChannel().PublicKey = pubkeyBytes
|
||||
|
||||
claimID := "251305ca93d4dbedb50dceb282ebcb7b07b7ac64"
|
||||
txid := "4c1df9e022e396859175f9bfa69b38e444db10fb53355fa99a0989a83bcdb82f" //Fake
|
||||
claimIDHexBytes, err := hex.DecodeString(claimID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
claim := &ClaimHelper{newStreamClaim(), nil, reverseBytes(claimIDHexBytes), WithSig, nil, nil}
|
||||
claim.Claim.Title = "Test title"
|
||||
claim.Claim.Description = "Test description"
|
||||
sig, err := Sign(*privateKey, *channel, *claim, txid)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
signatureBytes, err := sig.LBRYSDKEncode()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
claim.Signature = signatureBytes
|
||||
compiledClaim, err := claim.CompileValue()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
claim, err = DecodeClaimBytes(compiledClaim, "lbrycrd_main")
|
||||
|
||||
valid, err := claim.ValidateClaimSignature(channel, txid, claimID, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
assert.Assert(t, valid, "could not verify signature")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/sha256"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/asn1"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/schema/address"
|
||||
)
|
||||
|
||||
type publicKeyInfo struct {
|
||||
Raw asn1.RawContent
|
||||
Algorithm pkix.AlgorithmIdentifier
|
||||
PublicKey asn1.BitString
|
||||
}
|
||||
|
||||
const SECP256k1 = "SECP256k1"
|
||||
|
||||
//const NIST256p = "NIST256p"
|
||||
//const NIST384p = "NIST384p"
|
||||
|
||||
func getClaimSignatureDigest(bytes ...[]byte) [32]byte {
|
||||
|
||||
var combined []byte
|
||||
for _, b := range bytes {
|
||||
combined = append(combined, b...)
|
||||
}
|
||||
digest := sha256.Sum256(combined)
|
||||
return [32]byte(digest)
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) VerifyDigest(certificate *ClaimHelper, signature [64]byte, digest [32]byte) bool {
|
||||
if certificate == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
R := &big.Int{}
|
||||
S := &big.Int{}
|
||||
R.SetBytes(signature[0:32])
|
||||
S.SetBytes(signature[32:64])
|
||||
pk, err := certificate.GetPublicKey()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return ecdsa.Verify(pk.ToECDSA(), digest[:], R, S)
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) ValidateClaimSignature(certificate *ClaimHelper, k string, certificateId string, blockchainName string) (bool, error) {
|
||||
if c.LegacyClaim != nil {
|
||||
return c.validateV1ClaimSignature(certificate, k, certificateId, blockchainName)
|
||||
}
|
||||
|
||||
return c.validateClaimSignature(certificate, k, certificateId, blockchainName)
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) validateClaimSignature(certificate *ClaimHelper, firstInputTxHash, certificateId string, blockchainName string) (bool, error) {
|
||||
certificateIdSlice, err := hex.DecodeString(certificateId)
|
||||
if err != nil {
|
||||
return false, errors.Err(err)
|
||||
}
|
||||
certificateIdSlice = reverseBytes(certificateIdSlice)
|
||||
firstInputTxIDBytes, err := hex.DecodeString(firstInputTxHash)
|
||||
if err != nil {
|
||||
return false, errors.Err(err)
|
||||
}
|
||||
|
||||
signature := c.Signature
|
||||
if signature == nil {
|
||||
return false, errors.Err("claim does not have a signature")
|
||||
}
|
||||
signatureBytes := [64]byte{}
|
||||
for i, b := range signature {
|
||||
signatureBytes[i] = b
|
||||
}
|
||||
|
||||
claimDigest := getClaimSignatureDigest(firstInputTxIDBytes, certificateIdSlice, c.Payload)
|
||||
return c.VerifyDigest(certificate, signatureBytes, claimDigest), nil
|
||||
}
|
||||
|
||||
func (c *ClaimHelper) validateV1ClaimSignature(certificate *ClaimHelper, claimAddy string, certificateId string, blockchainName string) (bool, error) {
|
||||
addressBytes, err := address.DecodeAddress(claimAddy, blockchainName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
//For V1 claim_id was incorrectly stored for claim signing.
|
||||
// So the bytes are not reversed like they are supposed to be (Endianess)
|
||||
certificateIdSlice, err := hex.DecodeString(certificateId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
signature := c.Signature
|
||||
if signature == nil {
|
||||
return false, errors.Err("claim does not have a signature")
|
||||
}
|
||||
signatureBytes := [64]byte{}
|
||||
for i := range signatureBytes {
|
||||
signatureBytes[i] = signature[i]
|
||||
}
|
||||
|
||||
claimAddress, err := address.ValidateAddress(addressBytes, blockchainName)
|
||||
if err != nil {
|
||||
return false, errors.Err("invalid address")
|
||||
}
|
||||
|
||||
serializedNoSig, err := c.serializedNoSignature()
|
||||
if err != nil {
|
||||
return false, errors.Err("serialization error")
|
||||
}
|
||||
|
||||
claimDigest := getClaimSignatureDigest(claimAddress[:], serializedNoSig, certificateIdSlice)
|
||||
return c.VerifyDigest(certificate, signatureBytes, claimDigest), nil
|
||||
}
|
||||
|
||||
func GetOutpointHash(txid string, vout uint32) (string, error) {
|
||||
txidBytes, err := hex.DecodeString(txid)
|
||||
if err != nil {
|
||||
return "", errors.Err(err)
|
||||
}
|
||||
var voutBytes = make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(voutBytes, vout)
|
||||
return hex.EncodeToString(append(reverseBytes(txidBytes), voutBytes...)), nil
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
func TestV1ValidateClaimSignature(t *testing.T) {
|
||||
cert_claim_hex := "08011002225e0801100322583056301006072a8648ce3d020106052b8104000a03420004d015365a40f3e5c03c87227168e5851f44659837bcf6a3398ae633bc37d04ee19baeb26dc888003bd728146dbea39f5344bf8c52cedaf1a3a1623a0166f4a367"
|
||||
signed_claim_hex := "080110011ad7010801128f01080410011a0c47616d65206f66206c696665221047616d65206f66206c696665206769662a0b4a6f686e20436f6e776179322e437265617469766520436f6d6d6f6e73204174747269627574696f6e20342e3020496e7465726e6174696f6e616c38004224080110011a195569c917f18bf5d2d67f1346aa467b218ba90cdbf2795676da250000803f4a0052005a001a41080110011a30b6adf6e2a62950407ea9fb045a96127b67d39088678d2f738c359894c88d95698075ee6203533d3c204330713aa7acaf2209696d6167652f6769662a5c080110031a40c73fe1be4f1743c2996102eec6ce0509e03744ab940c97d19ddb3b25596206367ab1a3d2583b16c04d2717eeb983ae8f84fee2a46621ffa5c4726b30174c6ff82214251305ca93d4dbedb50dceb282ebcb7b07b7ac65"
|
||||
|
||||
signed_claim, err := DecodeClaimHex(signed_claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cert_claim, err := DecodeClaimHex(cert_claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
claim_addr := "bSkUov7HMWpYBiXackDwRnR5ishhGHvtJt"
|
||||
cert_id := "251305ca93d4dbedb50dceb282ebcb7b07b7ac65"
|
||||
|
||||
result, err := signed_claim.ValidateClaimSignature(cert_claim, claim_addr, cert_id, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if result != true {
|
||||
t.Error("failed to validate signature:", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1FailToValidateClaimSignature(t *testing.T) {
|
||||
cert_claim_hex := "08011002225e0801100322583056301006072a8648ce3d020106052b8104000a03420004d015365a40f3e5c03c87227168e5851f44659837bcf6a3398ae633bc37d04ee19baeb26dc888003bd728146dbea39f5344bf8c52cedaf1a3a1623a0166f4a367"
|
||||
signed_claim_hex := "080110011ad7010801128f01080410011a0c47616d65206f66206c696665221047616d65206f66206c696665206769662a0b4a6f686e20436f6e776179322e437265617469766520436f6d6d6f6e73204174747269627574696f6e20342e3020496e7465726e6174696f6e616c38004224080110011a195569c917f18bf5d2d67f1346aa467b218ba90cdbf2795676da250000803f4a0052005a001a41080110011a30b6adf6e2a62950407ea9fb045a96127b67d39088678d2f738c359894c88d95698075ee6203533d3c204330713aa7acaf2209696d6167652f6769662a5c080110031a40c73fe1be4f1743c2996102eec6ce0509e03744ab940c97d19ddb3b25596206367ab1a3d2583b16c04d2717eeb983ae8f84fee2a46621ffa5c4726b30174c6ff82214251305ca93d4dbedb50dceb282ebcb7b07b7ac65"
|
||||
|
||||
signed_claim, err := DecodeClaimHex(signed_claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cert_claim, err := DecodeClaimHex(cert_claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
claim_addr := "bSkUov7HMWpYBiXackDwRnR5ishhGHvtJt"
|
||||
cert_id := "251305ca93d4dbedb50dceb282ebcb7b07b7ac64"
|
||||
|
||||
result, err := signed_claim.ValidateClaimSignature(cert_claim, claim_addr, cert_id, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if result != false {
|
||||
t.Error("failed to validate signature:", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV2ValidateClaimSignature(t *testing.T) {
|
||||
cert_claim_hex := "00125a0a583056301006072a8648ce3d020106052b8104000a034200045a0343c155302280da01ae0001b7295241eb03c42a837acf92ccb9680892f7db50fd1d3c14b28bb594e304f05fc4ae7c1f222a85d1d1a3461b3cfb9906f66cb5"
|
||||
signed_claim_hex := "015cb78e424a34fbf79b67f9107430427aa62373e69b4998a29ecec8f14a9e0a213a043ced8064c069d7e464b5fd3ccb92b45bd59b15c0e1bb27e3c366d43f86a9a6b5ad42647a1aad69a73ac50b19ae3ec978c2c70aa2010a99010a301c662f19abc461e7eddecf165adfa7fca569e209773f3db31241c1e297f0a8d5b3e4768828b065fbeb1d6776f61073f6121b3031202d20556e6d6173746572656420496d70756c7365732e377a187a22146170706c69636174696f6e2f782d6578742d377a32302eb61ea475017e28c013616a56c1219ba90dc35fffff453d9675146f648f66634e0d1516528d37aba9f5801229d9f2181a044e6f6e6542087465737420707562520062020801"
|
||||
|
||||
signed_claim, err := DecodeClaimHex(signed_claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cert_claim, err := DecodeClaimHex(cert_claim_hex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
firstInputTxHash, err := GetOutpointHash("becb96a4a2e66bd24f083772fe9da904654ea9b5f07cc5bfbee233355911ddb1", uint32(0))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cert_id := "e67323a67a42307410f9679bf7fb344a428eb75c"
|
||||
|
||||
result, err := signed_claim.ValidateClaimSignature(cert_claim, firstInputTxHash, cert_id, "lbrycrd_main")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if result != true {
|
||||
t.Error("failed to validate signature:", result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestGetOutpointHash(t *testing.T) {
|
||||
hash, err := GetOutpointHash("dc3dcf2f94d3c91e454ac2474802e20f26b30705372dda43890c811d918aef64", 1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Assert(t, hash == "64ef8a911d810c8943da2d370507b3260fe2024847c24a451ec9d3942fcf3ddc01000000", uint(1))
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/schema/claim"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
if len(args) == 1 {
|
||||
claimBytes := []byte(args[0])
|
||||
decoded, err := claim.DecodeClaimBytes(claimBytes, "lbrycrd_main")
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error:", err)
|
||||
return
|
||||
}
|
||||
text, err := decoded.RenderJSON()
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(text)
|
||||
return
|
||||
} else if (len(args) == 2) && (args[1] == "--decode_hex") {
|
||||
claimHex := args[0]
|
||||
decoded, err := claim.DecodeClaimHex(claimHex, "lbrycrd_main")
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error:", err)
|
||||
return
|
||||
}
|
||||
text, err := decoded.RenderJSON()
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(text)
|
||||
return
|
||||
} else {
|
||||
fmt.Println("encountered an error\nusage: \n\tlbryschema-cli <value to decode> [--decode_hex]")
|
||||
return
|
||||
}
|
||||
}
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
go test ./... -v
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export IMPORTPATH="github.com/lbryio/lbry.go/v2"
|
||||
export VERSIONSHORT="${TRAVIS_COMMIT:-"$(git describe --tags --always --dirty)"}"
|
||||
export VERSIONLONG="${TRAVIS_COMMIT:-"$(git describe --tags --always --dirty --long)"}"
|
||||
export COMMITMSG="$(echo ${TRAVIS_COMMIT_MESSAGE:-"$(git show -s --format=%s)"} | tr -d '"' | head -n 1)"
|
||||
curl -sL https://git.io/goreleaser | bash
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
GO111MODULE=off go get github.com/caarlos0/svu
|
||||
git tag `svu "$1"`
|
||||
git push --tags
|
||||
+6
-2
@@ -8,10 +8,14 @@ import (
|
||||
"encoding/hex"
|
||||
"strconv"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
)
|
||||
|
||||
const MaxBlobSize = 2097152 // 2mb, or 2 * 2^20
|
||||
const (
|
||||
MaxBlobSize = 2097152 // 2mb, or 2 * 2^20
|
||||
BlobHashSize = sha512.Size384
|
||||
BlobHashHexLength = BlobHashSize * 2 // in hex, each byte is 2 chars
|
||||
)
|
||||
|
||||
type Blob []byte
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
)
|
||||
|
||||
// inspired by https://blog.gopheracademy.com/advent-2016/advanced-encoding-decoding/
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
)
|
||||
|
||||
type Stream []Blob
|
||||
|
||||
Reference in new issue
Block a user