2023-08-04 11:10:09 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
2023-09-26 09:21:13 +00:00
|
|
|
std/options,
|
2023-08-04 11:10:09 +00:00
|
|
|
eth/[common, trie/db],
|
2023-09-26 09:21:13 +00:00
|
|
|
"."/[base, core_apps, legacy_db]
|
2023-08-04 11:10:09 +00:00
|
|
|
|
|
|
|
export
|
|
|
|
common,
|
|
|
|
core_apps,
|
|
|
|
|
|
|
|
# Not all symbols from the object sources will be exported by default
|
|
|
|
CoreDbCaptFlags,
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbError,
|
2023-08-04 11:10:09 +00:00
|
|
|
CoreDbCaptRef,
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDbKvtRef,
|
2023-08-04 11:10:09 +00:00
|
|
|
CoreDbMptRef,
|
|
|
|
CoreDbPhkRef,
|
|
|
|
CoreDbRef,
|
|
|
|
CoreDbTxID,
|
|
|
|
CoreDbTxRef,
|
|
|
|
CoreDbType,
|
2023-09-26 09:21:13 +00:00
|
|
|
CoreDxCaptRef,
|
|
|
|
CoreDxKvtRef,
|
|
|
|
CoreDxMptRef,
|
|
|
|
CoreDxPhkRef,
|
|
|
|
CoreDxTxID,
|
|
|
|
CoreDxTxRef,
|
|
|
|
backend,
|
2023-08-04 11:10:09 +00:00
|
|
|
beginTransaction,
|
|
|
|
capture,
|
|
|
|
commit,
|
|
|
|
compensateLegacySetup,
|
|
|
|
contains,
|
|
|
|
dbType,
|
|
|
|
del,
|
|
|
|
dispose,
|
|
|
|
get,
|
|
|
|
getTransactionID,
|
2023-09-26 09:21:13 +00:00
|
|
|
isLegacy,
|
2023-08-04 11:10:09 +00:00
|
|
|
isPruning,
|
|
|
|
kvt,
|
|
|
|
mptPrune,
|
2023-09-26 09:21:13 +00:00
|
|
|
newCapture,
|
|
|
|
newMpt,
|
|
|
|
newMptPrune,
|
|
|
|
newPhkPrune,
|
|
|
|
newTransaction,
|
2023-08-04 11:10:09 +00:00
|
|
|
pairs,
|
|
|
|
parent,
|
|
|
|
phkPrune,
|
|
|
|
put,
|
|
|
|
recorder,
|
|
|
|
replicate,
|
|
|
|
rollback,
|
|
|
|
rootHash,
|
|
|
|
safeDispose,
|
|
|
|
setTransactionID,
|
2023-09-26 09:21:13 +00:00
|
|
|
toLegacy,
|
2023-08-04 11:10:09 +00:00
|
|
|
toMpt,
|
2023-09-26 09:21:13 +00:00
|
|
|
toPhk,
|
|
|
|
toTransactionID
|
2023-08-04 11:10:09 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public constructor
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc newCoreDbRef*(
|
|
|
|
db: TrieDatabaseRef;
|
|
|
|
): CoreDbRef
|
|
|
|
{.gcsafe, deprecated: "use newCoreDbRef(LegacyDbPersistent,<path>)".} =
|
|
|
|
## Legacy constructor.
|
|
|
|
##
|
|
|
|
## Note: Using legacy notation `newCoreDbRef()` rather than
|
|
|
|
## `CoreDbRef.init()` because of compiler coughing.
|
2023-09-26 09:21:13 +00:00
|
|
|
##
|
2023-08-04 11:10:09 +00:00
|
|
|
db.newLegacyPersistentCoreDbRef()
|
|
|
|
|
|
|
|
proc newCoreDbRef*(dbType: static[CoreDbType]): CoreDbRef =
|
|
|
|
## Constructor for volatile/memory type DB
|
|
|
|
##
|
|
|
|
## Note: Using legacy notation `newCoreDbRef()` rather than
|
|
|
|
## `CoreDbRef.init()` because of compiler coughing.
|
2023-09-26 09:21:13 +00:00
|
|
|
##
|
2023-08-04 11:10:09 +00:00
|
|
|
when dbType == LegacyDbMemory:
|
|
|
|
newLegacyMemoryCoreDbRef()
|
2023-09-26 09:21:13 +00:00
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
else:
|
|
|
|
{.error: "Unsupported dbType for memory newCoreDbRef()".}
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public template wrappers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
template shortTimeReadOnly*(id: CoreDxTxID|CoreDbTxID; body: untyped) =
|
|
|
|
proc action() =
|
2023-08-04 11:10:09 +00:00
|
|
|
body
|
|
|
|
id.shortTimeReadOnly action
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|