github.com/trezor/blockbook@v0.4.1-0.20240328132726-e9a08582ee2c/bchain/coins/flo/floparser.go (about) 1 package flo 2 3 import ( 4 "github.com/martinboehm/btcd/wire" 5 "github.com/martinboehm/btcutil/chaincfg" 6 "github.com/trezor/blockbook/bchain" 7 "github.com/trezor/blockbook/bchain/coins/btc" 8 ) 9 10 // magic numbers 11 const ( 12 MainnetMagic wire.BitcoinNet = 0xf1a5c0fd 13 TestnetMagic wire.BitcoinNet = 0xf25ac0fd 14 RegtestMagic wire.BitcoinNet = 0xdab5bffa 15 ) 16 17 // chain parameters 18 var ( 19 MainNetParams chaincfg.Params 20 TestNetParams chaincfg.Params 21 ) 22 23 func init() { 24 MainNetParams = chaincfg.MainNetParams 25 MainNetParams.Net = MainnetMagic 26 MainNetParams.PubKeyHashAddrID = []byte{35} 27 MainNetParams.ScriptHashAddrID = []byte{94} 28 MainNetParams.Bech32HRPSegwit = "flo" 29 30 TestNetParams = chaincfg.TestNet3Params 31 TestNetParams.Net = TestnetMagic 32 TestNetParams.PubKeyHashAddrID = []byte{115} 33 TestNetParams.ScriptHashAddrID = []byte{198} 34 TestNetParams.Bech32HRPSegwit = "tflo" 35 } 36 37 // FloParser handle 38 type FloParser struct { 39 *btc.BitcoinLikeParser 40 baseparser *bchain.BaseParser 41 } 42 43 // NewFloParser returns new FloParser instance 44 func NewFloParser(params *chaincfg.Params, c *btc.Configuration) *FloParser { 45 return &FloParser{ 46 BitcoinLikeParser: btc.NewBitcoinLikeParser(params, c), 47 baseparser: &bchain.BaseParser{}, 48 } 49 } 50 51 // GetChainParams contains network parameters for the main Flo network, 52 // and the test Flo network 53 func GetChainParams(chain string) *chaincfg.Params { 54 if !chaincfg.IsRegistered(&MainNetParams) { 55 err := chaincfg.Register(&MainNetParams) 56 if err == nil { 57 err = chaincfg.Register(&TestNetParams) 58 } 59 if err != nil { 60 panic(err) 61 } 62 } 63 switch chain { 64 case "test": 65 return &TestNetParams 66 default: 67 return &MainNetParams 68 } 69 } 70 71 // PackTx packs transaction to byte array using protobuf 72 func (p *FloParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) { 73 return p.baseparser.PackTx(tx, height, blockTime) 74 } 75 76 // UnpackTx unpacks transaction from protobuf byte array 77 func (p *FloParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) { 78 return p.baseparser.UnpackTx(buf) 79 }