github.com/cerberus-wallet/blockbook@v0.3.2/bchain/coins/monacoin/monacoinparser.go (about) 1 package monacoin 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 = 0xdbb6c0fb 13 TestnetMagic wire.BitcoinNet = 0xf1c8d2fd 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{50} 26 MainNetParams.ScriptHashAddrID = []byte{55} 27 MainNetParams.Bech32HRPSegwit = "mona" 28 29 TestNetParams = chaincfg.TestNet3Params 30 TestNetParams.Net = TestnetMagic 31 TestNetParams.PubKeyHashAddrID = []byte{111} 32 TestNetParams.ScriptHashAddrID = []byte{117} 33 TestNetParams.Bech32HRPSegwit = "tmona" 34 } 35 36 // MonacoinParser handle 37 type MonacoinParser struct { 38 *btc.BitcoinParser 39 } 40 41 // NewMonacoinParser returns new MonacoinParser instance 42 func NewMonacoinParser(params *chaincfg.Params, c *btc.Configuration) *MonacoinParser { 43 return &MonacoinParser{BitcoinParser: btc.NewBitcoinParser(params, c)} 44 } 45 46 // GetChainParams contains network parameters for the main Monacoin network, 47 // and the test Monacoin 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 }