github.com/bchainhub/blockbook@v0.3.2/bchain/coins/polis/polisparser.go (about) 1 package polis 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 = 0xbd6b0cbf 13 TestnetMagic wire.BitcoinNet = 0xffcae2ce 14 RegtestMagic wire.BitcoinNet = 0xdcb7c1fc 15 ) 16 17 // chain parameters 18 var ( 19 MainNetParams chaincfg.Params 20 TestNetParams chaincfg.Params 21 RegtestParams chaincfg.Params 22 ) 23 24 func init() { 25 MainNetParams = chaincfg.MainNetParams 26 MainNetParams.Net = MainnetMagic 27 28 // Address encoding magics 29 MainNetParams.PubKeyHashAddrID = []byte{55} // base58 prefix: P 30 MainNetParams.ScriptHashAddrID = []byte{56} // base58 prefix: 3 31 32 TestNetParams = chaincfg.TestNet3Params 33 TestNetParams.Net = TestnetMagic 34 35 // Address encoding magics 36 TestNetParams.PubKeyHashAddrID = []byte{140} // base58 prefix: y 37 TestNetParams.ScriptHashAddrID = []byte{19} // base58 prefix: 8 or 9 38 39 RegtestParams = chaincfg.RegressionNetParams 40 RegtestParams.Net = RegtestMagic 41 42 // Address encoding magics 43 RegtestParams.PubKeyHashAddrID = []byte{140} // base58 prefix: y 44 RegtestParams.ScriptHashAddrID = []byte{19} // base58 prefix: 8 or 9 45 } 46 47 // PolisParser handle 48 type PolisParser struct { 49 *btc.BitcoinParser 50 } 51 52 // NewPolisParser returns new PolisParser instance 53 func NewPolisParser(params *chaincfg.Params, c *btc.Configuration) *PolisParser { 54 return &PolisParser{BitcoinParser: btc.NewBitcoinParser(params, c)} 55 } 56 57 // GetChainParams contains network parameters for the main Polis network, 58 // the regression test Polis network, the test Polis network and 59 // the simulation test Polis network, in this order 60 func GetChainParams(chain string) *chaincfg.Params { 61 if !chaincfg.IsRegistered(&MainNetParams) { 62 err := chaincfg.Register(&MainNetParams) 63 if err == nil { 64 err = chaincfg.Register(&TestNetParams) 65 } 66 if err == nil { 67 err = chaincfg.Register(&RegtestParams) 68 } 69 if err != nil { 70 panic(err) 71 } 72 } 73 switch chain { 74 case "test": 75 return &TestNetParams 76 case "regtest": 77 return &RegtestParams 78 default: 79 return &MainNetParams 80 } 81 }