Use coin specific interface when creating mempool

pull/7/head
Martin Boehm 2018-05-17 12:30:45 +02:00
parent a6f4783d86
commit f5a8bed629
6 changed files with 24 additions and 6 deletions

View File

@ -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
}

View File

@ -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()

View File

@ -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
}

View File

@ -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()

View File

@ -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
}

View File

@ -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)