Merge branch 'params-registration'
This commit is contained in:
commit
2aaf2fe137
2
Gopkg.lock
generated
2
Gopkg.lock
generated
@ -113,7 +113,7 @@
|
|||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/jakm/btcutil"
|
name = "github.com/jakm/btcutil"
|
||||||
packages = [".","base58","bech32","chaincfg","txscript"]
|
packages = [".","base58","bech32","chaincfg","txscript"]
|
||||||
revision = "c50a69d8979c23daad1728b3574c6f20691174f7"
|
revision = "4656891ba33d07bb3c37ed1eb5120774c42a6bf6"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
|||||||
@ -25,6 +25,23 @@ const (
|
|||||||
RegTestPrefix = "bchreg:"
|
RegTestPrefix = "bchreg:"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
MainNetParams chaincfg.Params
|
||||||
|
TestNetParams chaincfg.Params
|
||||||
|
RegtestParams chaincfg.Params
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
MainNetParams = chaincfg.MainNetParams
|
||||||
|
MainNetParams.Net = bchutil.MainnetMagic
|
||||||
|
|
||||||
|
TestNetParams = chaincfg.TestNet3Params
|
||||||
|
TestNetParams.Net = bchutil.TestnetMagic
|
||||||
|
|
||||||
|
RegtestParams = chaincfg.RegressionNetParams
|
||||||
|
RegtestParams.Net = bchutil.Regtestmagic
|
||||||
|
}
|
||||||
|
|
||||||
// BCashParser handle
|
// BCashParser handle
|
||||||
type BCashParser struct {
|
type BCashParser struct {
|
||||||
*btc.BitcoinParser
|
*btc.BitcoinParser
|
||||||
@ -62,17 +79,26 @@ func NewBCashParser(params *chaincfg.Params, c *btc.Configuration) (*BCashParser
|
|||||||
// the regression test Bitcoin Cash network, the test Bitcoin Cash network and
|
// the regression test Bitcoin Cash network, the test Bitcoin Cash network and
|
||||||
// the simulation test Bitcoin Cash network, in this order
|
// the simulation test Bitcoin Cash network, in this order
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&TestNetParams)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&RegtestParams)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
var params *chaincfg.Params
|
var params *chaincfg.Params
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
params = &chaincfg.TestNet3Params
|
return &TestNetParams
|
||||||
params.Net = bchutil.TestnetMagic
|
|
||||||
case "regtest":
|
case "regtest":
|
||||||
params = &chaincfg.RegressionNetParams
|
return &RegtestParams
|
||||||
params.Net = bchutil.Regtestmagic
|
|
||||||
default:
|
default:
|
||||||
params = &chaincfg.MainNetParams
|
return &MainNetParams
|
||||||
params.Net = bchutil.MainnetMagic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|||||||
@ -7,10 +7,19 @@ import (
|
|||||||
"blockbook/bchain/coins/btc"
|
"blockbook/bchain/coins/btc"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress(t *testing.T) {
|
func Test_GetAddrDescFromAddress(t *testing.T) {
|
||||||
mainParserCashAddr, mainParserLegacy, testParserCashAddr, _ := setupParsers(t)
|
mainParserCashAddr, mainParserLegacy, testParserCashAddr, _ := setupParsers(t)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|||||||
@ -42,6 +42,9 @@ func NewBitcoinParser(params *chaincfg.Params, c *Configuration) *BitcoinParser
|
|||||||
// the regression test Bitcoin network, the test Bitcoin network and
|
// the regression test Bitcoin network, the test Bitcoin network and
|
||||||
// the simulation test Bitcoin network, in this order
|
// the simulation test Bitcoin network, in this order
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
|
if !chaincfg.IsRegistered(&chaincfg.MainNetParams) {
|
||||||
|
chaincfg.RegisterBitcoinParams()
|
||||||
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
return &chaincfg.TestNet3Params
|
return &chaincfg.TestNet3Params
|
||||||
|
|||||||
@ -6,10 +6,19 @@ import (
|
|||||||
"blockbook/bchain"
|
"blockbook/bchain"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress(t *testing.T) {
|
func Test_GetAddrDescFromAddress(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
address string
|
address string
|
||||||
|
|||||||
@ -23,7 +23,7 @@ var (
|
|||||||
TestNetParams chaincfg.Params
|
TestNetParams chaincfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
|
|
||||||
@ -39,14 +39,6 @@ func initParams() {
|
|||||||
// see https://github.com/satoshilabs/slips/blob/master/slip-0173.md
|
// see https://github.com/satoshilabs/slips/blob/master/slip-0173.md
|
||||||
MainNetParams.Bech32HRPSegwit = "btg"
|
MainNetParams.Bech32HRPSegwit = "btg"
|
||||||
TestNetParams.Bech32HRPSegwit = "tbtg"
|
TestNetParams.Bech32HRPSegwit = "tbtg"
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
|
||||||
if err == nil {
|
|
||||||
err = chaincfg.Register(&TestNetParams)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BGoldParser handle
|
// BGoldParser handle
|
||||||
@ -63,8 +55,14 @@ func NewBGoldParser(params *chaincfg.Params, c *btc.Configuration) *BGoldParser
|
|||||||
// the regression test Bitcoin Cash network, the test Bitcoin Cash network and
|
// the regression test Bitcoin Cash network, the test Bitcoin Cash network and
|
||||||
// the simulation test Bitcoin Cash network, in this order
|
// the simulation test Bitcoin Cash network, in this order
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
initParams()
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&TestNetParams)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
|
|||||||
@ -8,10 +8,19 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
type testBlock struct {
|
type testBlock struct {
|
||||||
size int
|
size int
|
||||||
time int64
|
time int64
|
||||||
|
|||||||
@ -19,7 +19,7 @@ var (
|
|||||||
RegtestParams chaincfg.Params
|
RegtestParams chaincfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
|
|
||||||
@ -40,17 +40,6 @@ func initParams() {
|
|||||||
// Address encoding magics
|
// Address encoding magics
|
||||||
RegtestParams.PubKeyHashAddrID = []byte{140} // base58 prefix: y
|
RegtestParams.PubKeyHashAddrID = []byte{140} // base58 prefix: y
|
||||||
RegtestParams.ScriptHashAddrID = []byte{19} // base58 prefix: 8 or 9
|
RegtestParams.ScriptHashAddrID = []byte{19} // base58 prefix: 8 or 9
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
|
||||||
if err == nil {
|
|
||||||
err = chaincfg.Register(&TestNetParams)
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
err = chaincfg.Register(&RegtestParams)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DashParser handle
|
// DashParser handle
|
||||||
@ -67,8 +56,17 @@ func NewDashParser(params *chaincfg.Params, c *btc.Configuration) *DashParser {
|
|||||||
// the regression test Dash network, the test Dash network and
|
// the regression test Dash network, the test Dash network and
|
||||||
// the simulation test Dash network, in this order
|
// the simulation test Dash network, in this order
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
initParams()
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&TestNetParams)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&RegtestParams)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
|
|||||||
@ -18,16 +18,11 @@ var (
|
|||||||
MainNetParams chaincfg.Params
|
MainNetParams chaincfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
MainNetParams.PubKeyHashAddrID = []byte{30}
|
MainNetParams.PubKeyHashAddrID = []byte{30}
|
||||||
MainNetParams.ScriptHashAddrID = []byte{22}
|
MainNetParams.ScriptHashAddrID = []byte{22}
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DogecoinParser handle
|
// DogecoinParser handle
|
||||||
@ -43,8 +38,11 @@ func NewDogecoinParser(params *chaincfg.Params, c *btc.Configuration) *DogecoinP
|
|||||||
// GetChainParams contains network parameters for the main Dogecoin network,
|
// GetChainParams contains network parameters for the main Dogecoin network,
|
||||||
// and the test Dogecoin network
|
// and the test Dogecoin network
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
initParams()
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -10,11 +10,20 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
address string
|
address string
|
||||||
|
|||||||
@ -18,7 +18,7 @@ var (
|
|||||||
TestNetParams chaincfg.Params
|
TestNetParams chaincfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
MainNetParams.PubKeyHashAddrID = []byte{48}
|
MainNetParams.PubKeyHashAddrID = []byte{48}
|
||||||
@ -30,14 +30,6 @@ func initParams() {
|
|||||||
TestNetParams.PubKeyHashAddrID = []byte{111}
|
TestNetParams.PubKeyHashAddrID = []byte{111}
|
||||||
TestNetParams.ScriptHashAddrID = []byte{58}
|
TestNetParams.ScriptHashAddrID = []byte{58}
|
||||||
TestNetParams.Bech32HRPSegwit = "tltc"
|
TestNetParams.Bech32HRPSegwit = "tltc"
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
|
||||||
if err == nil {
|
|
||||||
err = chaincfg.Register(&TestNetParams)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LitecoinParser handle
|
// LitecoinParser handle
|
||||||
@ -53,8 +45,17 @@ func NewLitecoinParser(params *chaincfg.Params, c *btc.Configuration) *LitecoinP
|
|||||||
// GetChainParams contains network parameters for the main Litecoin network,
|
// GetChainParams contains network parameters for the main Litecoin network,
|
||||||
// and the test Litecoin network
|
// and the test Litecoin network
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&chaincfg.MainNetParams) {
|
||||||
initParams()
|
chaincfg.RegisterBitcoinParams()
|
||||||
|
}
|
||||||
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&TestNetParams)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
|
|||||||
@ -7,10 +7,19 @@ import (
|
|||||||
"blockbook/bchain/coins/btc"
|
"blockbook/bchain/coins/btc"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress_Testnet(t *testing.T) {
|
func Test_GetAddrDescFromAddress_Testnet(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
address string
|
address string
|
||||||
@ -28,17 +37,29 @@ func Test_GetAddrDescFromAddress_Testnet(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "P2SH1",
|
name: "P2SH1-legacy",
|
||||||
args: args{address: "2MvGVySztevmycxrSmMRjJaVj2iJin7qpap"},
|
args: args{address: "2MvGVySztevmycxrSmMRjJaVj2iJin7qpap"},
|
||||||
want: "a9142126232e3f47ae0f1246ec5f05fc400d83c86a0d87",
|
want: "a9142126232e3f47ae0f1246ec5f05fc400d83c86a0d87",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "P2SH2",
|
name: "P2SH2-legacy",
|
||||||
args: args{address: "2N9a2TNzWz1FEKGFxUdMEh62V83URdZ5QAZ"},
|
args: args{address: "2N9a2TNzWz1FEKGFxUdMEh62V83URdZ5QAZ"},
|
||||||
want: "a914b31049e7ee51501fe19e3e0cdb803dc84cf99f9e87",
|
want: "a914b31049e7ee51501fe19e3e0cdb803dc84cf99f9e87",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "P2SH1",
|
||||||
|
args: args{address: "QPdG6Ts8g2q4m9cVPTTkPGwAB6kYgXB7Hc"},
|
||||||
|
want: "a9142126232e3f47ae0f1246ec5f05fc400d83c86a0d87",
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "P2SH2",
|
||||||
|
args: args{address: "QcvnaPrm17JKTT216jPFmnTvGRvFX2fWzN"},
|
||||||
|
want: "a914b31049e7ee51501fe19e3e0cdb803dc84cf99f9e87",
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
parser := NewLitecoinParser(GetChainParams("test"), &btc.Configuration{})
|
parser := NewLitecoinParser(GetChainParams("test"), &btc.Configuration{})
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ var (
|
|||||||
MonaTestParams monacoinCfg.Params
|
MonaTestParams monacoinCfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
MainNetParams.PubKeyHashAddrID = []byte{50}
|
MainNetParams.PubKeyHashAddrID = []byte{50}
|
||||||
@ -48,14 +48,6 @@ func initParams() {
|
|||||||
MonaTestParams.PubKeyHashAddrID = 111
|
MonaTestParams.PubKeyHashAddrID = 111
|
||||||
MonaTestParams.ScriptHashAddrID = 117
|
MonaTestParams.ScriptHashAddrID = 117
|
||||||
MonaTestParams.Bech32HRPSegwit = "tmona"
|
MonaTestParams.Bech32HRPSegwit = "tmona"
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
|
||||||
if err == nil {
|
|
||||||
err = chaincfg.Register(&TestNetParams)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonacoinParser handle
|
// MonacoinParser handle
|
||||||
@ -73,8 +65,14 @@ func NewMonacoinParser(params *chaincfg.Params, c *btc.Configuration) *MonacoinP
|
|||||||
// GetChainParams contains network parameters for the main Monacoin network,
|
// GetChainParams contains network parameters for the main Monacoin network,
|
||||||
// and the test Monacoin network
|
// and the test Monacoin network
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
initParams()
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&TestNetParams)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
|
|||||||
@ -7,10 +7,19 @@ import (
|
|||||||
"blockbook/bchain/coins/btc"
|
"blockbook/bchain/coins/btc"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress_Testnet(t *testing.T) {
|
func Test_GetAddrDescFromAddress_Testnet(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
address string
|
address string
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import (
|
|||||||
"blockbook/bchain/coins/utils"
|
"blockbook/bchain/coins/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
"github.com/jakm/btcutil/chaincfg"
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -18,22 +18,17 @@ var (
|
|||||||
MainNetParams chaincfg.Params
|
MainNetParams chaincfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
|
|
||||||
MainNetParams.Bech32HRPSegwit = "my"
|
MainNetParams.Bech32HRPSegwit = "my"
|
||||||
|
|
||||||
MainNetParams.PubKeyHashAddrID = []byte{50} // 0x32 - starts with M
|
MainNetParams.PubKeyHashAddrID = []byte{50} // 0x32 - starts with M
|
||||||
MainNetParams.ScriptHashAddrID = []byte{9} // 0x09 - starts with 4
|
MainNetParams.ScriptHashAddrID = []byte{9} // 0x09 - starts with 4
|
||||||
MainNetParams.PrivateKeyID = []byte{178} // 0xB2
|
MainNetParams.PrivateKeyID = []byte{178} // 0xB2
|
||||||
|
|
||||||
MainNetParams.HDCoinType = 90
|
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
MainNetParams.HDCoinType = 90
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyriadParser handle
|
// MyriadParser handle
|
||||||
@ -48,8 +43,11 @@ func NewMyriadParser(params *chaincfg.Params, c *btc.Configuration) *MyriadParse
|
|||||||
|
|
||||||
// GetChainParams contains network parameters for the main Myriad network
|
// GetChainParams contains network parameters for the main Myriad network
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
initParams()
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -7,10 +7,19 @@ import (
|
|||||||
"blockbook/bchain/coins/btc"
|
"blockbook/bchain/coins/btc"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
address string
|
address string
|
||||||
@ -57,9 +66,8 @@ func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testTx1 bchain.Tx
|
testTx1 bchain.Tx
|
||||||
testTxPacked1 = "00004e208ab194a1180100000001163465df9bb21d89e90056f11887a398d5a313aef71e3974306459661a91588c000000006b4830450220129c9e9a27406796f3f7d7edcc446037b38ddb3ef94745cec8e7cde618a811140221008eb3b893cdd3725e99b74c020867821e1f74199065260586f5ef3c22b133dd2a012103e2e23d38dc8fa493cde4077f650ab9f22eacafd14a10b123994f38c9f35dfee9ffffffff025e90ec28050000001976a9141cba92fe1510b8c73550fd4d3e0b44acdffcd12d88ac79c268ba0a0000001976a9142f86cdfa98cac89143cf9e3d309cc072caccdf6f88ac00000000"
|
testTxPacked1 = "00004e208ab194a1180100000001163465df9bb21d89e90056f11887a398d5a313aef71e3974306459661a91588c000000006b4830450220129c9e9a27406796f3f7d7edcc446037b38ddb3ef94745cec8e7cde618a811140221008eb3b893cdd3725e99b74c020867821e1f74199065260586f5ef3c22b133dd2a012103e2e23d38dc8fa493cde4077f650ab9f22eacafd14a10b123994f38c9f35dfee9ffffffff025e90ec28050000001976a9141cba92fe1510b8c73550fd4d3e0b44acdffcd12d88ac79c268ba0a0000001976a9142f86cdfa98cac89143cf9e3d309cc072caccdf6f88ac00000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -18,16 +18,11 @@ var (
|
|||||||
MainNetParams chaincfg.Params
|
MainNetParams chaincfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
MainNetParams.PubKeyHashAddrID = []byte{52}
|
MainNetParams.PubKeyHashAddrID = []byte{52}
|
||||||
MainNetParams.ScriptHashAddrID = []byte{13}
|
MainNetParams.ScriptHashAddrID = []byte{13}
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NamecoinParser handle
|
// NamecoinParser handle
|
||||||
@ -43,8 +38,11 @@ func NewNamecoinParser(params *chaincfg.Params, c *btc.Configuration) *NamecoinP
|
|||||||
// GetChainParams contains network parameters for the main Namecoin network,
|
// GetChainParams contains network parameters for the main Namecoin network,
|
||||||
// and the test Namecoin network
|
// and the test Namecoin network
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
initParams()
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -8,11 +8,20 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
address string
|
address string
|
||||||
|
|||||||
@ -18,7 +18,7 @@ var (
|
|||||||
TestNetParams chaincfg.Params
|
TestNetParams chaincfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
MainNetParams.PubKeyHashAddrID = []byte{71}
|
MainNetParams.PubKeyHashAddrID = []byte{71}
|
||||||
@ -30,14 +30,6 @@ func initParams() {
|
|||||||
TestNetParams.PubKeyHashAddrID = []byte{74}
|
TestNetParams.PubKeyHashAddrID = []byte{74}
|
||||||
TestNetParams.ScriptHashAddrID = []byte{196}
|
TestNetParams.ScriptHashAddrID = []byte{196}
|
||||||
TestNetParams.Bech32HRPSegwit = "tvtc"
|
TestNetParams.Bech32HRPSegwit = "tvtc"
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
|
||||||
if err == nil {
|
|
||||||
err = chaincfg.Register(&TestNetParams)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VertcoinParser handle
|
// VertcoinParser handle
|
||||||
@ -53,8 +45,14 @@ func NewVertcoinParser(params *chaincfg.Params, c *btc.Configuration) *VertcoinP
|
|||||||
// GetChainParams contains network parameters for the main Vertcoin network,
|
// GetChainParams contains network parameters for the main Vertcoin network,
|
||||||
// and the test Vertcoin network
|
// and the test Vertcoin network
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
initParams()
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&TestNetParams)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
|
|||||||
@ -7,10 +7,19 @@ import (
|
|||||||
"blockbook/bchain/coins/btc"
|
"blockbook/bchain/coins/btc"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
address string
|
address string
|
||||||
|
|||||||
@ -17,9 +17,10 @@ const (
|
|||||||
var (
|
var (
|
||||||
MainNetParams chaincfg.Params
|
MainNetParams chaincfg.Params
|
||||||
TestNetParams chaincfg.Params
|
TestNetParams chaincfg.Params
|
||||||
|
RegtestParams chaincfg.Params
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParams() {
|
func init() {
|
||||||
MainNetParams = chaincfg.MainNetParams
|
MainNetParams = chaincfg.MainNetParams
|
||||||
MainNetParams.Net = MainnetMagic
|
MainNetParams.Net = MainnetMagic
|
||||||
|
|
||||||
@ -36,13 +37,8 @@ func initParams() {
|
|||||||
TestNetParams.PubKeyHashAddrID = []byte{0x1D, 0x25} // base58 prefix: tm
|
TestNetParams.PubKeyHashAddrID = []byte{0x1D, 0x25} // base58 prefix: tm
|
||||||
TestNetParams.ScriptHashAddrID = []byte{0x1C, 0xBA} // base58 prefix: t2
|
TestNetParams.ScriptHashAddrID = []byte{0x1C, 0xBA} // base58 prefix: t2
|
||||||
|
|
||||||
err := chaincfg.Register(&MainNetParams)
|
RegtestParams = chaincfg.RegressionNetParams
|
||||||
if err == nil {
|
RegtestParams.Net = RegtestMagic
|
||||||
err = chaincfg.Register(&TestNetParams)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZCashParser handle
|
// ZCashParser handle
|
||||||
@ -63,16 +59,24 @@ func NewZCashParser(params *chaincfg.Params, c *btc.Configuration) *ZCashParser
|
|||||||
// the regression test ZCash network, the test ZCash network and
|
// the regression test ZCash network, the test ZCash network and
|
||||||
// the simulation test ZCash network, in this order
|
// the simulation test ZCash network, in this order
|
||||||
func GetChainParams(chain string) *chaincfg.Params {
|
func GetChainParams(chain string) *chaincfg.Params {
|
||||||
if MainNetParams.Name == "" {
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
||||||
initParams()
|
err := chaincfg.Register(&MainNetParams)
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&TestNetParams)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
err = chaincfg.Register(&RegtestParams)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var params *chaincfg.Params
|
var params *chaincfg.Params
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
return &TestNetParams
|
return &TestNetParams
|
||||||
case "regtest":
|
case "regtest":
|
||||||
params = &chaincfg.RegressionNetParams
|
return &RegtestParams
|
||||||
params.Net = RegtestMagic
|
|
||||||
default:
|
default:
|
||||||
return &MainNetParams
|
return &MainNetParams
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -91,6 +94,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetAddrDesc(t *testing.T) {
|
func TestGetAddrDesc(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
tx bchain.Tx
|
tx bchain.Tx
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
vlq "github.com/bsm/go-vlq"
|
vlq "github.com/bsm/go-vlq"
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,6 +26,12 @@ import (
|
|||||||
// for number n, the packing is: 2*n if n>=0 else 2*(-n)-1
|
// for number n, the packing is: 2*n if n>=0 else 2*(-n)-1
|
||||||
// takes only 1 byte if abs(n)<127
|
// takes only 1 byte if abs(n)<127
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
c := m.Run()
|
||||||
|
chaincfg.ResetParams()
|
||||||
|
os.Exit(c)
|
||||||
|
}
|
||||||
|
|
||||||
func bitcoinTestnetParser() *btc.BitcoinParser {
|
func bitcoinTestnetParser() *btc.BitcoinParser {
|
||||||
return btc.NewBitcoinParser(
|
return btc.NewBitcoinParser(
|
||||||
btc.GetChainParams("test"),
|
btc.GetChainParams("test"),
|
||||||
|
|||||||
@ -15,6 +15,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jakm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestFunc func(t *testing.T, coin string, chain bchain.BlockChain, testConfig json.RawMessage)
|
type TestFunc func(t *testing.T, coin string, chain bchain.BlockChain, testConfig json.RawMessage)
|
||||||
@ -52,6 +54,7 @@ func runTests(t *testing.T, coin string, cfg map[string]json.RawMessage) {
|
|||||||
if cfg == nil || len(cfg) == 0 {
|
if cfg == nil || len(cfg) == 0 {
|
||||||
t.Skip("No tests to run")
|
t.Skip("No tests to run")
|
||||||
}
|
}
|
||||||
|
defer chaincfg.ResetParams()
|
||||||
|
|
||||||
bc, err := makeBlockChain(coin)
|
bc, err := makeBlockChain(coin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user