Add chain params to lbrycrd client creation
Add Bech notation to alternative chain params
This commit is contained in:
parent
1835deb2c9
commit
9541d765a9
3 changed files with 18 additions and 6 deletions
4
go.mod
4
go.mod
|
@ -1,9 +1,11 @@
|
||||||
module github.com/lbryio/lbry.go/v2
|
module github.com/lbryio/lbry.go/v2
|
||||||
|
|
||||||
|
replace github.com/btcsuite/btcd => github.com/lbryio/lbrycrd.go v0.0.0-20200203050410-e1076f12bf19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
|
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
|
||||||
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32
|
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32
|
||||||
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803
|
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
|
||||||
github.com/davecgh/go-spew v1.1.1
|
github.com/davecgh/go-spew v1.1.1
|
||||||
github.com/fatih/structs v1.1.0
|
github.com/fatih/structs v1.1.0
|
||||||
github.com/go-errors/errors v1.0.1
|
github.com/go-errors/errors v1.0.1
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -5,12 +5,12 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
|
||||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
|
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/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||||
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78=
|
|
||||||
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=
|
|
||||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
|
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/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||||
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803 h1:j3AgPKKZtZStM2nyhrDSLSYgT7YHrZKdSkq1OYeLjvM=
|
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803 h1:j3AgPKKZtZStM2nyhrDSLSYgT7YHrZKdSkq1OYeLjvM=
|
||||||
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/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 h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
|
||||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
||||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd h1:qdGvebPBDuYDPGi1WCPjy1tGyMpmDK8IEapSsszn7HE=
|
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd h1:qdGvebPBDuYDPGi1WCPjy1tGyMpmDK8IEapSsszn7HE=
|
||||||
|
@ -84,6 +84,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c/go.mod h1:muH7wpUqE8hRA3OrYYosw9+Sl681BF9cwcjzE+OCNK8=
|
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c/go.mod h1:muH7wpUqE8hRA3OrYYosw9+Sl681BF9cwcjzE+OCNK8=
|
||||||
github.com/lbryio/lbry.go v1.1.2 h1:Dyxc+glT/rVWJwHfIf7vjlPYYbjzrQz5ARmJd5Hp69c=
|
github.com/lbryio/lbry.go v1.1.2 h1:Dyxc+glT/rVWJwHfIf7vjlPYYbjzrQz5ARmJd5Hp69c=
|
||||||
github.com/lbryio/lbry.go v1.1.2/go.mod h1:JtyI30bU51rm0LZ/po3mQuzf++14OWb6kR/6mMRAmKU=
|
github.com/lbryio/lbry.go v1.1.2/go.mod h1:JtyI30bU51rm0LZ/po3mQuzf++14OWb6kR/6mMRAmKU=
|
||||||
|
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/lbryschema.go v0.0.0-20190428231007-c54836bca002/go.mod h1:dAzPCBj3CKKWBGYBZxK6tKBP5SCgY2tqd9SnQd/OyKo=
|
github.com/lbryio/lbryschema.go v0.0.0-20190428231007-c54836bca002/go.mod h1:dAzPCBj3CKKWBGYBZxK6tKBP5SCgY2tqd9SnQd/OyKo=
|
||||||
github.com/lbryio/lbryschema.go v0.0.0-20190602173230-6d2f69a36f46 h1:LemfR+rMxhf7nnOrzy2HqS7Me7SZ5gEwOcNFzKC8ySQ=
|
github.com/lbryio/lbryschema.go v0.0.0-20190602173230-6d2f69a36f46 h1:LemfR+rMxhf7nnOrzy2HqS7Me7SZ5gEwOcNFzKC8ySQ=
|
||||||
github.com/lbryio/lbryschema.go v0.0.0-20190602173230-6d2f69a36f46/go.mod h1:dAzPCBj3CKKWBGYBZxK6tKBP5SCgY2tqd9SnQd/OyKo=
|
github.com/lbryio/lbryschema.go v0.0.0-20190602173230-6d2f69a36f46/go.mod h1:dAzPCBj3CKKWBGYBZxK6tKBP5SCgY2tqd9SnQd/OyKo=
|
||||||
|
|
|
@ -68,12 +68,14 @@ var testNetParams = chaincfg.Params{
|
||||||
PubKeyHashAddrID: lbrycrdTestnetPubkeyPrefix,
|
PubKeyHashAddrID: lbrycrdTestnetPubkeyPrefix,
|
||||||
ScriptHashAddrID: lbrycrdTestnetScriptPrefix,
|
ScriptHashAddrID: lbrycrdTestnetScriptPrefix,
|
||||||
PrivateKeyID: 0x1c,
|
PrivateKeyID: 0x1c,
|
||||||
|
Bech32HRPSegwit: "tlbc",
|
||||||
}
|
}
|
||||||
|
|
||||||
var regTestNetParams = chaincfg.Params{
|
var regTestNetParams = chaincfg.Params{
|
||||||
PubKeyHashAddrID: lbrycrdRegtestPubkeyPrefix,
|
PubKeyHashAddrID: lbrycrdRegtestPubkeyPrefix,
|
||||||
ScriptHashAddrID: lbrycrdRegtestScriptPrefix,
|
ScriptHashAddrID: lbrycrdRegtestScriptPrefix,
|
||||||
PrivateKeyID: 0x1c,
|
PrivateKeyID: 0x1c,
|
||||||
|
Bech32HRPSegwit: "rlbc",
|
||||||
}
|
}
|
||||||
|
|
||||||
var ChainParamsMap = map[string]chaincfg.Params{LbrycrdMain: mainNetParams, LbrycrdTestnet: testNetParams, LbrycrdRegtest: regTestNetParams}
|
var ChainParamsMap = map[string]chaincfg.Params{LbrycrdMain: mainNetParams, LbrycrdTestnet: testNetParams, LbrycrdRegtest: regTestNetParams}
|
||||||
|
@ -92,7 +94,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New initializes a new Client
|
// 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.
|
// Connect to local bitcoin core RPC server using HTTP POST mode.
|
||||||
|
|
||||||
u, err := url.Parse(lbrycrdURL)
|
u, err := url.Parse(lbrycrdURL)
|
||||||
|
@ -106,10 +108,16 @@ func New(lbrycrdURL string) (*Client, error) {
|
||||||
|
|
||||||
password, _ := u.User.Password()
|
password, _ := u.User.Password()
|
||||||
|
|
||||||
|
chain := MainNetParams
|
||||||
|
if chainParams != nil {
|
||||||
|
chain = *chainParams
|
||||||
|
}
|
||||||
|
|
||||||
connCfg := &rpcclient.ConnConfig{
|
connCfg := &rpcclient.ConnConfig{
|
||||||
Host: u.Host,
|
Host: u.Host,
|
||||||
User: u.User.Username(),
|
User: u.User.Username(),
|
||||||
Pass: password,
|
Pass: password,
|
||||||
|
Params: chain,
|
||||||
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
||||||
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
||||||
}
|
}
|
||||||
|
@ -128,12 +136,12 @@ func New(lbrycrdURL string) (*Client, error) {
|
||||||
return &Client{client}, nil
|
return &Client{client}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWithDefaultURL() (*Client, error) {
|
func NewWithDefaultURL(chainParams *chaincfg.Params) (*Client, error) {
|
||||||
url, err := getLbrycrdURLFromConfFile()
|
url, err := getLbrycrdURLFromConfFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return New(url)
|
return New(url, chainParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
var errInsufficientFunds = errors.Base("insufficient funds")
|
var errInsufficientFunds = errors.Base("insufficient funds")
|
||||||
|
|
Loading…
Reference in a new issue