github.com/bchainhub/blockbook@v0.3.2/bchain/coins/deeponion/deeponionparser.go (about) 1 package deeponion 2 3 import ( 4 "blockbook/bchain" 5 "blockbook/bchain/coins/btc" 6 7 "github.com/martinboehm/btcd/wire" 8 "github.com/martinboehm/btcutil/chaincfg" 9 ) 10 11 // magic numbers 12 const ( 13 MainnetMagic wire.BitcoinNet = 0xf2dbf1d1 14 ) 15 16 // chain parameters 17 var ( 18 MainNetParams chaincfg.Params 19 ) 20 21 func init() { 22 MainNetParams = chaincfg.MainNetParams 23 MainNetParams.Net = MainnetMagic 24 MainNetParams.PubKeyHashAddrID = []byte{31} 25 MainNetParams.ScriptHashAddrID = []byte{78} 26 MainNetParams.Bech32HRPSegwit = "dpn" 27 } 28 29 // DeepOnionParser handle 30 type DeepOnionParser struct { 31 *btc.BitcoinParser 32 baseparser *bchain.BaseParser 33 } 34 35 // NewDeepOnionParser returns new DeepOnionParser instance 36 func NewDeepOnionParser(params *chaincfg.Params, c *btc.Configuration) *DeepOnionParser { 37 return &DeepOnionParser{ 38 BitcoinParser: btc.NewBitcoinParser(params, c), 39 baseparser: &bchain.BaseParser{}, 40 } 41 } 42 43 // GetChainParams contains network parameters for the main DeepOnion network, 44 func GetChainParams(chain string) *chaincfg.Params { 45 // register bitcoin parameters in addition to deeponion parameters 46 // deeponion has dual standard of addresses and we want to be able to 47 // parse both standards 48 if !chaincfg.IsRegistered(&chaincfg.MainNetParams) { 49 chaincfg.RegisterBitcoinParams() 50 } 51 if !chaincfg.IsRegistered(&MainNetParams) { 52 err := chaincfg.Register(&MainNetParams) 53 if err != nil { 54 panic(err) 55 } 56 } 57 return &MainNetParams 58 } 59 60 // PackTx packs transaction to byte array using protobuf 61 func (p *DeepOnionParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) { 62 return p.baseparser.PackTx(tx, height, blockTime) 63 } 64 65 // UnpackTx unpacks transaction from protobuf byte array 66 func (p *DeepOnionParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) { 67 return p.baseparser.UnpackTx(buf) 68 }