github.com/bchainhub/blockbook@v0.3.2/bchain/coins/btg/bgoldrpc.go (about)

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