github.com/trezor/blockbook@v0.4.1-0.20240328132726-e9a08582ee2c/bchain/coins/gamecredits/gamecreditsparser.go (about)

     1  package gamecredits
     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  // magic numbers
    10  const (
    11  	MainnetMagic wire.BitcoinNet = 0xdbb6c0fb
    12  	TestnetMagic wire.BitcoinNet = 0x0709110b
    13  	RegtestMagic wire.BitcoinNet = 0xdab5bffa
    14  )
    15  
    16  // chain parameters
    17  var (
    18  	MainNetParams chaincfg.Params
    19  	TestNetParams chaincfg.Params
    20  )
    21  
    22  func init() {
    23  	MainNetParams = chaincfg.MainNetParams
    24  	MainNetParams.Net = MainnetMagic
    25  	MainNetParams.PubKeyHashAddrID = []byte{38}
    26  	MainNetParams.ScriptHashAddrID = []byte{62}
    27  	MainNetParams.Bech32HRPSegwit = "game"
    28  
    29  	TestNetParams = chaincfg.TestNet3Params
    30  	TestNetParams.Net = TestnetMagic
    31  	TestNetParams.PubKeyHashAddrID = []byte{111}
    32  	TestNetParams.ScriptHashAddrID = []byte{58}
    33  	TestNetParams.Bech32HRPSegwit = "tgame"
    34  }
    35  
    36  // GameCreditsParser handle
    37  type GameCreditsParser struct {
    38  	*btc.BitcoinLikeParser
    39  }
    40  
    41  // NewGameCreditsParser returns new GameCreditsParser instance
    42  func NewGameCreditsParser(params *chaincfg.Params, c *btc.Configuration) *GameCreditsParser {
    43  	return &GameCreditsParser{BitcoinLikeParser: btc.NewBitcoinLikeParser(params, c)}
    44  }
    45  
    46  // GetChainParams contains network parameters for the main GameCredits network,
    47  // and the test GameCredits network
    48  func GetChainParams(chain string) *chaincfg.Params {
    49  	if !chaincfg.IsRegistered(&MainNetParams) {
    50  		err := chaincfg.Register(&MainNetParams)
    51  		if err == nil {
    52  			err = chaincfg.Register(&TestNetParams)
    53  		}
    54  		if err != nil {
    55  			panic(err)
    56  		}
    57  	}
    58  	switch chain {
    59  	case "test":
    60  		return &TestNetParams
    61  	default:
    62  		return &MainNetParams
    63  	}
    64  }