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