github.com/bchainhub/blockbook@v0.3.2/bchain/coins/bellcoin/bellcoinparser.go (about) 1 package bellcoin 2 3 import ( 4 "blockbook/bchain/coins/btc" 5 6 "github.com/martinboehm/btcd/wire" 7 "github.com/martinboehm/btcutil/chaincfg" 8 ) 9 10 // magic numbers 11 const ( 12 MainnetMagic wire.BitcoinNet = 0xbebacefa 13 TestnetMagic wire.BitcoinNet = 0x0709110b 14 ) 15 16 // chain parameters 17 var ( 18 MainNetParams chaincfg.Params 19 TestNetParams chaincfg.Params 20 ) 21 22 func init() { 23 MainNetParams = chaincfg.MainNetParams 24 MainNetParams.Net = MainnetMagic 25 MainNetParams.PubKeyHashAddrID = []byte{25} 26 MainNetParams.ScriptHashAddrID = []byte{85} 27 MainNetParams.Bech32HRPSegwit = "bm" 28 29 TestNetParams = chaincfg.TestNet3Params 30 TestNetParams.Net = TestnetMagic 31 TestNetParams.PubKeyHashAddrID = []byte{111} 32 TestNetParams.ScriptHashAddrID = []byte{196} 33 TestNetParams.Bech32HRPSegwit = "bt" 34 } 35 36 // BellcoinParser handle 37 type BellcoinParser struct { 38 *btc.BitcoinParser 39 } 40 41 // NewBellcoinParser returns new BellcoinParser instance 42 func NewBellcoinParser(params *chaincfg.Params, c *btc.Configuration) *BellcoinParser { 43 return &BellcoinParser{BitcoinParser: btc.NewBitcoinParser(params, c)} 44 } 45 46 // GetChainParams contains network parameters for the main Bellcoin network, 47 // and the test Bellcoin network 48 func GetChainParams(chain string) *chaincfg.Params { 49 if !chaincfg.IsRegistered(&MainNetParams) { 50 err := chaincfg.Register(&MainNetParams) 51 if err == nil { 52 err = chaincfg.Register(&TestNetParams) 53 } 54 if err != nil { 55 panic(err) 56 } 57 } 58 switch chain { 59 case "test": 60 return &TestNetParams 61 default: 62 return &MainNetParams 63 } 64 }