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

     1  package gamecredits
     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 = 0x0709110b
    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{38}
    27  	MainNetParams.ScriptHashAddrID = []byte{62}
    28  	MainNetParams.Bech32HRPSegwit = "game"
    29  
    30  	TestNetParams = chaincfg.TestNet3Params
    31  	TestNetParams.Net = TestnetMagic
    32  	TestNetParams.PubKeyHashAddrID = []byte{111}
    33  	TestNetParams.ScriptHashAddrID = []byte{58}
    34  	TestNetParams.Bech32HRPSegwit = "tgame"
    35  }
    36  
    37  // GameCreditsParser handle
    38  type GameCreditsParser struct {
    39  	*btc.BitcoinParser
    40  }
    41  
    42  // NewGameCreditsParser returns new GameCreditsParser instance
    43  func NewGameCreditsParser(params *chaincfg.Params, c *btc.Configuration) *GameCreditsParser {
    44  	return &GameCreditsParser{BitcoinParser: btc.NewBitcoinParser(params, c)}
    45  }
    46  
    47  // GetChainParams contains network parameters for the main GameCredits network,
    48  // and the test GameCredits 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  }