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