From 4435dbbfb4da3a7ede3fed649018f04eb157f95f Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Wed, 3 Apr 2019 22:08:32 +0200 Subject: [PATCH] Pass correct blockchain object to mempool --- bchain/coins/blockchain.go | 6 +++--- bchain/coins/btc/bitcoinrpc.go | 4 ++-- bchain/coins/eth/ethrpc.go | 4 ++-- bchain/types.go | 2 +- server/public_test.go | 2 +- tests/dbtestdata/fakechain.go | 4 ++-- tests/integration.go | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bchain/coins/blockchain.go b/bchain/coins/blockchain.go index 38224311..7b39eae4 100644 --- a/bchain/coins/blockchain.go +++ b/bchain/coins/blockchain.go @@ -124,7 +124,7 @@ func NewBlockChain(coin string, configfile string, pushHandler func(bchain.Notif if err != nil { return nil, nil, err } - mempool, err := bc.CreateMempool() + mempool, err := bc.CreateMempool(bc) if err != nil { return nil, nil, err } @@ -148,8 +148,8 @@ func (c *blockChainWithMetrics) Initialize() error { return c.b.Initialize() } -func (c *blockChainWithMetrics) CreateMempool() (bchain.Mempool, error) { - return c.b.CreateMempool() +func (c *blockChainWithMetrics) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) { + return c.b.CreateMempool(chain) } func (c *blockChainWithMetrics) InitializeMempool(addrDescForOutpoint bchain.AddrDescForOutpointFunc, onNewTxAddr bchain.OnNewTxAddrFunc) error { diff --git a/bchain/coins/btc/bitcoinrpc.go b/bchain/coins/btc/bitcoinrpc.go index b3e17b75..ffda6650 100644 --- a/bchain/coins/btc/bitcoinrpc.go +++ b/bchain/coins/btc/bitcoinrpc.go @@ -131,9 +131,9 @@ func (b *BitcoinRPC) Initialize() error { } // CreateMempool creates mempool if not already created, however does not initialize it -func (b *BitcoinRPC) CreateMempool() (bchain.Mempool, error) { +func (b *BitcoinRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) { if b.Mempool == nil { - b.Mempool = bchain.NewMempoolBitcoinType(b, b.ChainConfig.MempoolWorkers, b.ChainConfig.MempoolSubWorkers) + b.Mempool = bchain.NewMempoolBitcoinType(chain, b.ChainConfig.MempoolWorkers, b.ChainConfig.MempoolSubWorkers) } return b.Mempool, nil } diff --git a/bchain/coins/eth/ethrpc.go b/bchain/coins/eth/ethrpc.go index 415174a4..5b0d3546 100644 --- a/bchain/coins/eth/ethrpc.go +++ b/bchain/coins/eth/ethrpc.go @@ -164,9 +164,9 @@ func (b *EthereumRPC) Initialize() error { } // CreateMempool creates mempool if not already created, however does not initialize it -func (b *EthereumRPC) CreateMempool() (bchain.Mempool, error) { +func (b *EthereumRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) { if b.Mempool == nil { - b.Mempool = bchain.NewMempoolEthereumType(b) + b.Mempool = bchain.NewMempoolEthereumType(chain) } return b.Mempool, nil } diff --git a/bchain/types.go b/bchain/types.go index 4c072574..4b3c1abd 100644 --- a/bchain/types.go +++ b/bchain/types.go @@ -209,7 +209,7 @@ type BlockChain interface { // initialize the block chain connector Initialize() error // create mempool but do not initialize it - CreateMempool() (Mempool, error) + CreateMempool(BlockChain) (Mempool, error) // initialize mempool, create ZeroMQ (or other) subscription InitializeMempool(AddrDescForOutpointFunc, OnNewTxAddrFunc) error // shutdown mempool, ZeroMQ and block chain connections diff --git a/server/public_test.go b/server/public_test.go index aa64044e..ccff606b 100644 --- a/server/public_test.go +++ b/server/public_test.go @@ -85,7 +85,7 @@ func setupPublicHTTPServer(t *testing.T) (*PublicServer, string) { glog.Fatal("fakechain: ", err) } - mempool, err := chain.CreateMempool() + mempool, err := chain.CreateMempool(chain) if err != nil { glog.Fatal("mempool: ", err) } diff --git a/tests/dbtestdata/fakechain.go b/tests/dbtestdata/fakechain.go index d64968c7..cee7c16b 100644 --- a/tests/dbtestdata/fakechain.go +++ b/tests/dbtestdata/fakechain.go @@ -17,8 +17,8 @@ func NewFakeBlockChain(parser bchain.BlockChainParser) (bchain.BlockChain, error return &fakeBlockChain{&bchain.BaseChain{Parser: parser}}, nil } -func (b *fakeBlockChain) CreateMempool() (bchain.Mempool, error) { - return bchain.NewMempoolBitcoinType(b, 1, 1), nil +func (b *fakeBlockChain) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) { + return bchain.NewMempoolBitcoinType(chain, 1, 1), nil } func (c *fakeBlockChain) Initialize() error { diff --git a/tests/integration.go b/tests/integration.go index 6d40b730..a33026b3 100644 --- a/tests/integration.go +++ b/tests/integration.go @@ -169,7 +169,7 @@ func initBlockChain(coinName string, cfg json.RawMessage) (bchain.BlockChain, bc return nil, nil, fmt.Errorf("BlockChain initialization failed: %s", err) } - mempool, err := cli.CreateMempool() + mempool, err := cli.CreateMempool(cli) if err != nil { return nil, nil, fmt.Errorf("Mempool creation failed: %s", err) }