github.com/cerberus-wallet/blockbook@v0.3.2/bchain/coins/grs/grsparser.go (about) 1 package grs 2 3 import ( 4 "blockbook/bchain" 5 "blockbook/bchain/coins/btc" 6 7 "github.com/martinboehm/btcd/wire" 8 "github.com/martinboehm/btcutil/base58" 9 "github.com/martinboehm/btcutil/chaincfg" 10 ) 11 12 // magic numbers 13 const ( 14 MainnetMagic wire.BitcoinNet = 0xd4b4bef9 15 TestnetMagic wire.BitcoinNet = 0x0709110b 16 ) 17 18 // chain parameters 19 var ( 20 MainNetParams chaincfg.Params 21 TestNetParams chaincfg.Params 22 ) 23 24 func init() { 25 MainNetParams = chaincfg.MainNetParams 26 MainNetParams.Net = MainnetMagic 27 28 // Address encoding magics 29 MainNetParams.PubKeyHashAddrID = []byte{36} 30 MainNetParams.ScriptHashAddrID = []byte{5} 31 MainNetParams.Bech32HRPSegwit = "grs" 32 MainNetParams.Base58CksumHasher = base58.Groestl512D 33 34 TestNetParams = chaincfg.TestNet3Params 35 TestNetParams.Net = TestnetMagic 36 37 // Address encoding magics 38 TestNetParams.PubKeyHashAddrID = []byte{111} 39 TestNetParams.ScriptHashAddrID = []byte{196} 40 TestNetParams.Bech32HRPSegwit = "tgrs" 41 TestNetParams.Base58CksumHasher = base58.Groestl512D 42 } 43 44 // GroestlcoinParser handle 45 type GroestlcoinParser struct { 46 *btc.BitcoinParser 47 baseparser *bchain.BaseParser 48 } 49 50 // NewGroestlcoinParser returns new GroestlcoinParser instance 51 func NewGroestlcoinParser(params *chaincfg.Params, c *btc.Configuration) *GroestlcoinParser { 52 return &GroestlcoinParser{ 53 BitcoinParser: btc.NewBitcoinParser(params, c), 54 baseparser: &bchain.BaseParser{}, 55 } 56 } 57 58 // GetChainParams contains network parameters for the main Groestlcoin network, 59 // the regression test Groestlcoin network, the test Groestlcoin network and 60 // the simulation test Groestlcoin network, in this order 61 func GetChainParams(chain string) *chaincfg.Params { 62 if !chaincfg.IsRegistered(&MainNetParams) { 63 err := chaincfg.Register(&MainNetParams) 64 if err == nil { 65 err = chaincfg.Register(&TestNetParams) 66 } 67 if err != nil { 68 panic(err) 69 } 70 } 71 switch chain { 72 case "test": 73 return &TestNetParams 74 default: 75 return &MainNetParams 76 } 77 } 78 79 // PackTx packs transaction to byte array using protobuf 80 func (p *GroestlcoinParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) { 81 return p.baseparser.PackTx(tx, height, blockTime) 82 } 83 84 // UnpackTx unpacks transaction from protobuf byte array 85 func (p *GroestlcoinParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) { 86 return p.baseparser.UnpackTx(buf) 87 }