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

     1  package bitzeny
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/trezor/blockbook/bchain"
     7  	"github.com/trezor/blockbook/bchain/coins/btc"
     8  
     9  	"github.com/golang/glog"
    10  )
    11  
    12  // BitZenyRPC is an interface to JSON-RPC bitcoind service.
    13  type BitZenyRPC struct {
    14  	*btc.BitcoinRPC
    15  }
    16  
    17  // NewBitZenyRPC returns new BitZenyRPC instance.
    18  func NewBitZenyRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
    19  	b, err := btc.NewBitcoinRPC(config, pushHandler)
    20  	if err != nil {
    21  		return nil, err
    22  	}
    23  
    24  	s := &BitZenyRPC{
    25  		b.(*btc.BitcoinRPC),
    26  	}
    27  	s.RPCMarshaler = btc.JSONMarshalerV2{}
    28  	s.ChainConfig.SupportsEstimateFee = false
    29  
    30  	return s, nil
    31  }
    32  
    33  // Initialize initializes BitZenyRPC instance.
    34  func (b *BitZenyRPC) Initialize() error {
    35  	ci, err := b.GetChainInfo()
    36  	if err != nil {
    37  		return err
    38  	}
    39  	chainName := ci.Chain
    40  
    41  	glog.Info("Chain name ", chainName)
    42  	params := GetChainParams(chainName)
    43  
    44  	// always create parser
    45  	b.Parser = NewBitZenyParser(params, b.ChainConfig)
    46  
    47  	// parameters for getInfo request
    48  	if params.Net == MainnetMagic {
    49  		b.Testnet = false
    50  		b.Network = "livenet"
    51  	} else {
    52  		b.Testnet = true
    53  		b.Network = "testnet"
    54  	}
    55  
    56  	glog.Info("rpc: block chain ", params.Name)
    57  
    58  	return nil
    59  }