nimbus-eth1/nimbus/db/capturedb.nim

42 lines
1.0 KiB
Nim
Raw Normal View History

2019-07-07 10:12:01 +00:00
import eth/trie/db, stew/ranges
2018-12-03 10:54:19 +00:00
type
CaptureFlags* {.pure.} = enum
PersistPut
PersistDel
DB = TrieDatabaseRef
BytesRange = Range[byte]
CaptureDB* = ref object of RootObj
srcDb: DB
dstDb: DB
flags: set[CaptureFlags]
proc get*(db: CaptureDB, key: openArray[byte]): seq[byte] =
result = db.dstDb.get(key)
if result.len != 0: return
result = db.srcDb.get(key)
2018-12-27 03:08:20 +00:00
if result.len != 0:
2018-12-27 02:47:34 +00:00
db.dstDb.put(key, result)
2018-12-03 10:54:19 +00:00
proc put*(db: CaptureDB, key, value: openArray[byte]) =
db.dstDb.put(key, value)
if CaptureFlags.PersistPut in db.flags:
db.srcDb.put(key, value)
proc contains*(db: CaptureDB, key: openArray[byte]): bool =
result = db.srcDb.contains(key)
2019-03-13 21:36:54 +00:00
doAssert(db.dstDb.contains(key) == result)
2018-12-03 10:54:19 +00:00
proc del*(db: CaptureDB, key: openArray[byte]) =
db.dstDb.del(key)
if CaptureFlags.PersistDel in db.flags:
db.srcDb.del(key)
proc newCaptureDB*(srcDb, dstDb: DB, flags: set[CaptureFlags] = {}): CaptureDB =
result.new()
result.srcDb = srcDb
result.dstDb = dstDb
result.flags = flags