github.com/bchainhub/blockbook@v0.3.2/bchain/coins/cpuchain/cpuchainparser.go (about) 1 package cpuchain 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 = 0xefbeadde 13 TestnetMagic wire.BitcoinNet = 0x0cb0cefa 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{28} 26 MainNetParams.ScriptHashAddrID = []byte{30} 27 MainNetParams.Bech32HRPSegwit = "cpu" 28 29 TestNetParams = chaincfg.TestNet3Params 30 TestNetParams.Net = TestnetMagic 31 TestNetParams.PubKeyHashAddrID = []byte{111} 32 TestNetParams.ScriptHashAddrID = []byte{196} 33 TestNetParams.Bech32HRPSegwit = "tcpu" 34 } 35 36 // CPUchainParser handle 37 type CPUchainParser struct { 38 *btc.BitcoinParser 39 } 40 41 // NewCPUchainParser returns new CPUchainParser instance 42 func NewCPUchainParser(params *chaincfg.Params, c *btc.Configuration) *CPUchainParser { 43 return &CPUchainParser{BitcoinParser: btc.NewBitcoinParser(params, c)} 44 } 45 46 // GetChainParams contains network parameters for the main CPUchain network, 47 // and the test CPUchain 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 }