Use coin specific interface when creating mempool
parent
a6f4783d86
commit
f5a8bed629
|
@ -33,7 +33,7 @@ func NewBCashRPC(config json.RawMessage, pushHandler func(bchain.NotificationTyp
|
|||
// Initialize initializes BCashRPC instance.
|
||||
func (b *BCashRPC) Initialize() error {
|
||||
|
||||
chainName, err := b.GetChainInfoAndInitializeMempool()
|
||||
chainName, err := b.GetChainInfoAndInitializeMempool(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -89,6 +89,11 @@ func (c *blockChainWithMetrics) GetSubversion() string {
|
|||
return c.b.GetSubversion()
|
||||
}
|
||||
|
||||
func (c *blockChainWithMetrics) GetBlockChainInfo() (v string, err error) {
|
||||
defer func(s time.Time) { c.observeRPCLatency("GetBlockChainInfo", s, err) }(time.Now())
|
||||
return c.b.GetBlockChainInfo()
|
||||
}
|
||||
|
||||
func (c *blockChainWithMetrics) GetBestBlockHash() (v string, err error) {
|
||||
defer func(s time.Time) { c.observeRPCLatency("GetBestBlockHash", s, err) }(time.Now())
|
||||
return c.b.GetBestBlockHash()
|
||||
|
|
|
@ -75,9 +75,9 @@ func NewBitcoinRPC(config json.RawMessage, pushHandler func(bchain.NotificationT
|
|||
// GetChainInfoAndInitializeMempool is called by Initialize and reused by other coins
|
||||
// it contacts the blockchain rpc interface for the first time
|
||||
// and if successful it connects to ZeroMQ and creates mempool handler
|
||||
func (b *BitcoinRPC) GetChainInfoAndInitializeMempool() (string, error) {
|
||||
func (b *BitcoinRPC) GetChainInfoAndInitializeMempool(bc bchain.BlockChain) (string, error) {
|
||||
// try to connect to block chain and get some info
|
||||
chainName, err := b.GetBlockChainInfo()
|
||||
chainName, err := bc.GetBlockChainInfo()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func (b *BitcoinRPC) GetChainInfoAndInitializeMempool() (string, error) {
|
|||
}
|
||||
b.mq = mq
|
||||
|
||||
b.Mempool = bchain.NewUTXOMempool(b)
|
||||
b.Mempool = bchain.NewUTXOMempool(bc)
|
||||
|
||||
return chainName, nil
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ func (b *BitcoinRPC) GetChainInfoAndInitializeMempool() (string, error) {
|
|||
// Initialize initializes BitcoinRPC instance.
|
||||
func (b *BitcoinRPC) Initialize() error {
|
||||
|
||||
chainName, err := b.GetChainInfoAndInitializeMempool()
|
||||
chainName, err := b.GetChainInfoAndInitializeMempool(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -244,6 +244,18 @@ func (b *EthereumRPC) GetSubversion() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// GetBlockChainInfo returns the NetworkID of the ethereum network
|
||||
func (b *EthereumRPC) GetBlockChainInfo() (string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
|
||||
defer cancel()
|
||||
|
||||
id, err := b.client.NetworkID(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return id.String(), nil
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) getBestHeader() (*ethtypes.Header, error) {
|
||||
b.bestHeaderMu.Lock()
|
||||
defer b.bestHeaderMu.Unlock()
|
||||
|
|
|
@ -26,7 +26,7 @@ func NewZCashRPC(config json.RawMessage, pushHandler func(bchain.NotificationTyp
|
|||
|
||||
// Initialize initializes ZCashRPC instance.
|
||||
func (z *ZCashRPC) Initialize() error {
|
||||
_, err := z.GetChainInfoAndInitializeMempool()
|
||||
_, err := z.GetChainInfoAndInitializeMempool(z)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -128,6 +128,7 @@ type BlockChain interface {
|
|||
GetNetworkName() string
|
||||
GetSubversion() string
|
||||
// requests
|
||||
GetBlockChainInfo() (string, error)
|
||||
GetBestBlockHash() (string, error)
|
||||
GetBestBlockHeight() (uint32, error)
|
||||
GetBlockHash(height uint32) (string, error)
|
||||
|
|
Loading…
Reference in New Issue