From f3f0b274f2b8aad466b51448f2fbd2d2b8a4d1db Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 26 Sep 2019 22:19:04 -0400 Subject: expose the database interface --- eth/backend.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'eth') diff --git a/eth/backend.go b/eth/backend.go index 4281d96..d119e89 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -119,7 +119,7 @@ func (s *Ethereum) SetContractBackend(backend bind.ContractBackend) { // New creates a new Ethereum object (including the // initialisation of the common Ethereum object) -func New(ctx *node.ServiceContext, config *Config, cb *dummy.ConsensusCallbacks, mcb *miner.MinerCallbacks) (*Ethereum, error) { +func New(ctx *node.ServiceContext, config *Config, cb *dummy.ConsensusCallbacks, mcb *miner.MinerCallbacks, chainDb ethdb.Database) (*Ethereum, error) { // Ensure configuration values are compatible and sane if config.SyncMode == downloader.LightSync { return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum") @@ -137,10 +137,13 @@ func New(ctx *node.ServiceContext, config *Config, cb *dummy.ConsensusCallbacks, } log.Info("Allocated trie memory caches", "clean", common.StorageSize(config.TrieCleanCache)*1024*1024, "dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024) - // Assemble the Ethereum object - chainDb, err := ctx.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/") - if err != nil { - return nil, err + var err error + if chainDb == nil { + // Assemble the Ethereum object + chainDb, err = ctx.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/") + if err != nil { + return nil, err + } } chainConfig, genesisHash, genesisErr := mycore.SetupGenesisBlock(chainDb, config.Genesis) if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { -- cgit v1.2.3-70-g09d2