github.com/cerberus-wallet/blockbook@v0.3.2/bchain/coins/vertcoin/vertcoinparser.go (about)

     1  package vertcoin
     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 = 0xdab5bffb
    13  	TestnetMagic wire.BitcoinNet = 0x74726576 // "vert" word
    14  	RegtestMagic wire.BitcoinNet = 0xdab5bffc
    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{71}
    27  	MainNetParams.ScriptHashAddrID = []byte{5}
    28  	MainNetParams.Bech32HRPSegwit = "vtc"
    29  
    30  	TestNetParams = chaincfg.TestNet3Params
    31  	TestNetParams.Net = TestnetMagic
    32  	TestNetParams.PubKeyHashAddrID = []byte{74}
    33  	TestNetParams.ScriptHashAddrID = []byte{196}
    34  	TestNetParams.Bech32HRPSegwit = "tvtc"
    35  }
    36  
    37  // VertcoinParser handle
    38  type VertcoinParser struct {
    39  	*btc.BitcoinParser
    40  }
    41  
    42  // NewVertcoinParser returns new VertcoinParser instance
    43  func NewVertcoinParser(params *chaincfg.Params, c *btc.Configuration) *VertcoinParser {
    44  	return &VertcoinParser{BitcoinParser: btc.NewBitcoinParser(params, c)}
    45  }
    46  
    47  // GetChainParams contains network parameters for the main Vertcoin network,
    48  // and the test Vertcoin 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  }