github.com/cerberus-wallet/blockbook@v0.3.2/bchain/coins/litecoin/litecoinparser.go (about) 1 package litecoin 2 3 import ( 4 "blockbook/bchain/coins/btc" 5 6 "github.com/martinboehm/btcd/wire" 7 "github.com/martinboehm/btcutil/chaincfg" 8 ) 9 10 // magic numbers 11 const ( 12 MainnetMagic wire.BitcoinNet = 0xdbb6c0fb 13 TestnetMagic wire.BitcoinNet = 0xf1c8d2fd 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{48} 27 MainNetParams.ScriptHashAddrID = []byte{50} 28 MainNetParams.Bech32HRPSegwit = "ltc" 29 30 TestNetParams = chaincfg.TestNet3Params 31 TestNetParams.Net = TestnetMagic 32 TestNetParams.PubKeyHashAddrID = []byte{111} 33 TestNetParams.ScriptHashAddrID = []byte{58} 34 TestNetParams.Bech32HRPSegwit = "tltc" 35 } 36 37 // LitecoinParser handle 38 type LitecoinParser struct { 39 *btc.BitcoinParser 40 } 41 42 // NewLitecoinParser returns new LitecoinParser instance 43 func NewLitecoinParser(params *chaincfg.Params, c *btc.Configuration) *LitecoinParser { 44 return &LitecoinParser{BitcoinParser: btc.NewBitcoinParser(params, c)} 45 } 46 47 // GetChainParams contains network parameters for the main Litecoin network, 48 // and the test Litecoin network 49 func GetChainParams(chain string) *chaincfg.Params { 50 // register bitcoin parameters in addition to litecoin parameters 51 // litecoin has dual standard of addresses and we want to be able to 52 // parse both standards 53 if !chaincfg.IsRegistered(&chaincfg.MainNetParams) { 54 chaincfg.RegisterBitcoinParams() 55 } 56 if !chaincfg.IsRegistered(&MainNetParams) { 57 err := chaincfg.Register(&MainNetParams) 58 if err == nil { 59 err = chaincfg.Register(&TestNetParams) 60 } 61 if err != nil { 62 panic(err) 63 } 64 } 65 switch chain { 66 case "test": 67 return &TestNetParams 68 default: 69 return &MainNetParams 70 } 71 }