github.com/trezor/blockbook@v0.4.1-0.20240328132726-e9a08582ee2c/bchain/coins/digibyte/digibyteparser.go (about) 1 package digibyte 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 // network constants 10 const ( 11 MainnetMagic wire.BitcoinNet = 0xdab6c3fa 12 TestnetMagic wire.BitcoinNet = 0xddbdc8fd 13 ) 14 15 // parser parameters 16 var ( 17 MainNetParams chaincfg.Params 18 TestNetParams chaincfg.Params 19 ) 20 21 func init() { 22 MainNetParams = chaincfg.MainNetParams 23 MainNetParams.Net = MainnetMagic 24 MainNetParams.PubKeyHashAddrID = []byte{30} 25 MainNetParams.ScriptHashAddrID = []byte{63} 26 MainNetParams.Bech32HRPSegwit = "dgb" 27 28 TestNetParams = chaincfg.TestNet3Params 29 TestNetParams.Net = TestnetMagic 30 TestNetParams.PubKeyHashAddrID = []byte{126} 31 TestNetParams.ScriptHashAddrID = []byte{140} 32 TestNetParams.Bech32HRPSegwit = "dgbt" 33 } 34 35 // DigiByteParser handle 36 type DigiByteParser struct { 37 *btc.BitcoinLikeParser 38 } 39 40 // NewDigiByteParser returns new DigiByteParser instance 41 func NewDigiByteParser(params *chaincfg.Params, c *btc.Configuration) *DigiByteParser { 42 p := &DigiByteParser{BitcoinLikeParser: btc.NewBitcoinLikeParser(params, c)} 43 p.VSizeSupport = true 44 return p 45 } 46 47 // GetChainParams contains network parameters for the main DigiByte network 48 // and the DigiByte Testnet network 49 func GetChainParams(chain string) *chaincfg.Params { 50 if !chaincfg.IsRegistered(&MainNetParams) { 51 err := chaincfg.Register(&MainNetParams) 52 if err == nil { 53 err = chaincfg.Register(&TestNetParams) 54 } 55 if err != nil { 56 panic(err) 57 } 58 } 59 switch chain { 60 case "test": 61 return &TestNetParams 62 default: 63 return &MainNetParams 64 } 65 }