nimbus-eth1/nimbus/db/aristo/aristo_init/rocks_db/rdb_get.nim

44 lines
1.3 KiB
Nim
Raw Normal View History

# nimbus-eth1
# Copyright (c) 2023 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.
## Rocks DB fetch data record
## ==========================
{.push raises: [].}
import
eth/common,
rocksdb,
results,
"../.."/[aristo_constants, aristo_desc],
./rdb_desc
# ------------------------------------------------------------------------------
# Public functions
# ------------------------------------------------------------------------------
proc get*(
rdb: RdbInst;
key: openArray[byte],
): Result[Blob,(AristoError,string)] =
var res: Blob
let onData: DataProc = proc(data: openArray[byte]) =
res = @data
let rc = rdb.store.get(key, onData)
if rc.isErr:
return err((RdbBeDriverGetError,rc.error))
if not rc.value:
res = EmptyBlob
ok res
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------