github.com/cerberus-wallet/blockbook@v0.3.2/bchain/coins/dash/dashparser.go (about) 1 package dash 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 const ( 12 // MainnetMagic is mainnet network constant 13 MainnetMagic wire.BitcoinNet = 0xbd6b0cbf 14 // TestnetMagic is testnet network constant 15 TestnetMagic wire.BitcoinNet = 0xffcae2ce 16 // RegtestMagic is regtest network constant 17 RegtestMagic wire.BitcoinNet = 0xdcb7c1fc 18 ) 19 20 var ( 21 // MainNetParams are parser parameters for mainnet 22 MainNetParams chaincfg.Params 23 // TestNetParams are parser parameters for testnet 24 TestNetParams chaincfg.Params 25 // RegtestParams are parser parameters for regtest 26 RegtestParams chaincfg.Params 27 ) 28 29 func init() { 30 MainNetParams = chaincfg.MainNetParams 31 MainNetParams.Net = MainnetMagic 32 33 // Address encoding magics 34 MainNetParams.PubKeyHashAddrID = []byte{76} // base58 prefix: X 35 MainNetParams.ScriptHashAddrID = []byte{16} // base58 prefix: 7 36 37 TestNetParams = chaincfg.TestNet3Params 38 TestNetParams.Net = TestnetMagic 39 40 // Address encoding magics 41 TestNetParams.PubKeyHashAddrID = []byte{140} // base58 prefix: y 42 TestNetParams.ScriptHashAddrID = []byte{19} // base58 prefix: 8 or 9 43 44 RegtestParams = chaincfg.RegressionNetParams 45 RegtestParams.Net = RegtestMagic 46 47 // Address encoding magics 48 RegtestParams.PubKeyHashAddrID = []byte{140} // base58 prefix: y 49 RegtestParams.ScriptHashAddrID = []byte{19} // base58 prefix: 8 or 9 50 } 51 52 // DashParser handle 53 type DashParser struct { 54 *btc.BitcoinParser 55 baseparser *bchain.BaseParser 56 } 57 58 // NewDashParser returns new DashParser instance 59 func NewDashParser(params *chaincfg.Params, c *btc.Configuration) *DashParser { 60 return &DashParser{ 61 BitcoinParser: btc.NewBitcoinParser(params, c), 62 baseparser: &bchain.BaseParser{}, 63 } 64 } 65 66 // GetChainParams contains network parameters for the main Dash network, 67 // the regression test Dash network, the test Dash network and 68 // the simulation test Dash network, in this order 69 func GetChainParams(chain string) *chaincfg.Params { 70 if !chaincfg.IsRegistered(&MainNetParams) { 71 err := chaincfg.Register(&MainNetParams) 72 if err == nil { 73 err = chaincfg.Register(&TestNetParams) 74 } 75 if err == nil { 76 err = chaincfg.Register(&RegtestParams) 77 } 78 if err != nil { 79 panic(err) 80 } 81 } 82 switch chain { 83 case "test": 84 return &TestNetParams 85 case "regtest": 86 return &RegtestParams 87 default: 88 return &MainNetParams 89 } 90 } 91 92 // PackTx packs transaction to byte array using protobuf 93 func (p *DashParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) { 94 return p.baseparser.PackTx(tx, height, blockTime) 95 } 96 97 // UnpackTx unpacks transaction from protobuf byte array 98 func (p *DashParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) { 99 return p.baseparser.UnpackTx(buf) 100 }