From 96b18cfce311cfbfb3b66a9d41f4d8e217a1be6f Mon Sep 17 00:00:00 2001 From: andri lim Date: Thu, 27 Dec 2018 09:59:06 +0700 Subject: [PATCH] add select_backend module --- nimbus/db/select_backend.nim | 10 ++++++++++ nimbus/nimbus.nim | 11 +---------- tests/persistBlockTestGen.nim | 11 +---------- tests/tracerTestGen.nim | 11 +---------- 4 files changed, 13 insertions(+), 30 deletions(-) create mode 100644 nimbus/db/select_backend.nim diff --git a/nimbus/db/select_backend.nim b/nimbus/db/select_backend.nim new file mode 100644 index 000000000..29680461c --- /dev/null +++ b/nimbus/db/select_backend.nim @@ -0,0 +1,10 @@ +const nimbus_db_backend {.strdefine.} = "rocksdb" + +when nimbus_db_backend == "sqlite": + import ./backends/sqlite_backend as database_backend +elif nimbus_db_backend == "rocksdb": + import ./backends/rocksdb_backend as database_backend +else: + import ./backends/lmdb_backend as database_backend + +export database_backend diff --git a/nimbus/nimbus.nim b/nimbus/nimbus.nim index c6fc46846..2e97dd9ed 100644 --- a/nimbus/nimbus.nim +++ b/nimbus/nimbus.nim @@ -8,22 +8,13 @@ # those terms. import - os, strutils, net, eth_common, db/[storage_types, db_chain], + os, strutils, net, eth_common, db/[storage_types, db_chain, select_backend], asyncdispatch2, json_rpc/rpcserver, eth_keys, chronicles, eth_p2p, eth_p2p/rlpx_protocols/[eth_protocol, les_protocol], eth_p2p/blockchain_sync, config, genesis, rpc/[common, p2p, debug, whisper], p2p/chain, eth_trie/db -const nimbus_db_backend {.strdefine.} = "rocksdb" - -when nimbus_db_backend == "sqlite": - import ../nimbus/db/backends/sqlite_backend -elif nimbus_db_backend == "rocksdb": - import ../nimbus/db/backends/rocksdb_backend -else: - import ../nimbus/db/backends/lmdb_backend - ## TODO: ## * No IPv6 support ## * No multiple bind addresses support diff --git a/tests/persistBlockTestGen.nim b/tests/persistBlockTestGen.nim index 11718be40..ff0fd9f00 100644 --- a/tests/persistBlockTestGen.nim +++ b/tests/persistBlockTestGen.nim @@ -1,18 +1,9 @@ import json, os, eth_common, stint, chronicles, byteutils, nimcrypto, rlp, - eth_trie/[db], ../nimbus/db/[db_chain, capturedb, storage_types], + eth_trie/[db], ../nimbus/db/[db_chain, capturedb, storage_types, select_backend], ../nimbus/[tracer, vm_types, config], ../nimbus/p2p/chain -const nimbus_db_backend {.strdefine.} = "rocksdb" - -when nimbus_db_backend == "sqlite": - import ../nimbus/db/backends/sqlite_backend -elif nimbus_db_backend == "rocksdb": - import ../nimbus/db/backends/rocksdb_backend -else: - import ../nimbus/db/backends/lmdb_backend - proc putCanonicalHead(chainDB: BaseChainDB, header: BlockHeader) = var headerHash = rlpHash(header) chainDB.db.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header)) diff --git a/tests/tracerTestGen.nim b/tests/tracerTestGen.nim index ec5297a33..b778ea4ef 100644 --- a/tests/tracerTestGen.nim +++ b/tests/tracerTestGen.nim @@ -1,17 +1,8 @@ import json, os, eth_common, stint, chronicles, byteutils, nimcrypto, - eth_trie/[db], ../nimbus/db/[db_chain, capturedb], + eth_trie/[db], ../nimbus/db/[db_chain, capturedb, select_backend], ../nimbus/[tracer, vm_types, config] -const nimbus_db_backend {.strdefine.} = "rocksdb" - -when nimbus_db_backend == "sqlite": - import ../nimbus/db/backends/sqlite_backend -elif nimbus_db_backend == "rocksdb": - import ../nimbus/db/backends/rocksdb_backend -else: - import ../nimbus/db/backends/lmdb_backend - proc dumpTest(chainDB: BaseChainDB, blockNumber: int) = let blockNumber = blockNumber.u256