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

     1  package fujicoin
     2  
     3  import (
     4  	"blockbook/bchain/coins/btc"
     5  
     6  	"github.com/martinboehm/btcd/wire"
     7  	"github.com/martinboehm/btcutil/chaincfg"
     8  )
     9  
    10  const (
    11  	// MainnetMagic is mainnet network constant
    12  	MainnetMagic wire.BitcoinNet = 0x696a7566
    13  	// TestnetMagic is testnet network constant
    14  	TestnetMagic wire.BitcoinNet = 0x66756a69
    15  	// RegtestMagic is regtest network constant
    16  	RegtestMagic wire.BitcoinNet = 0x66756a69
    17  )
    18  
    19  var (
    20  	// MainNetParams are parser parameters for mainnet
    21  	MainNetParams chaincfg.Params
    22  	// TestNetParams are parser parameters for testnet
    23  	TestNetParams chaincfg.Params
    24  )
    25  
    26  func init() {
    27  	MainNetParams = chaincfg.MainNetParams
    28  	MainNetParams.Net = MainnetMagic
    29  	MainNetParams.PubKeyHashAddrID = []byte{36}
    30  	MainNetParams.ScriptHashAddrID = []byte{16}
    31  	MainNetParams.Bech32HRPSegwit = "fc"
    32  
    33  	TestNetParams = chaincfg.TestNet3Params
    34  	TestNetParams.Net = TestnetMagic
    35  	TestNetParams.PubKeyHashAddrID = []byte{74}
    36  	TestNetParams.ScriptHashAddrID = []byte{196}
    37  	TestNetParams.Bech32HRPSegwit = "tfc"
    38  }
    39  
    40  // FujicoinParser handle
    41  type FujicoinParser struct {
    42  	*btc.BitcoinParser
    43  }
    44  
    45  // NewFujicoinParser returns new FujicoinParser instance
    46  func NewFujicoinParser(params *chaincfg.Params, c *btc.Configuration) *FujicoinParser {
    47  	return &FujicoinParser{BitcoinParser: btc.NewBitcoinParser(params, c)}
    48  }
    49  
    50  // GetChainParams contains network parameters for the main Fujicoin network,
    51  // and the test Fujicoin network
    52  func GetChainParams(chain string) *chaincfg.Params {
    53  	if !chaincfg.IsRegistered(&MainNetParams) {
    54  		err := chaincfg.Register(&MainNetParams)
    55  		if err == nil {
    56  			err = chaincfg.Register(&TestNetParams)
    57  		}
    58  		if err != nil {
    59  			panic(err)
    60  		}
    61  	}
    62  	switch chain {
    63  	case "test":
    64  		return &TestNetParams
    65  	default:
    66  		return &MainNetParams
    67  	}
    68  }