2023-05-14 17:43:01 +00:00
|
|
|
# nimbus-eth1
|
|
|
|
# Copyright (c) 2021 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.
|
|
|
|
|
2023-06-12 18:16:03 +00:00
|
|
|
## Constructors for Aristo DB
|
|
|
|
## ==========================
|
2023-05-14 17:43:01 +00:00
|
|
|
##
|
2023-06-12 18:16:03 +00:00
|
|
|
## For a backend-less constructor use `AristoDb(top: AristoLayerRef())`.
|
2023-05-14 17:43:01 +00:00
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
|
|
|
./aristo_init/[aristo_memory],
|
2023-06-12 18:16:03 +00:00
|
|
|
./aristo_desc,
|
|
|
|
./aristo_desc/aristo_types_private
|
2023-05-14 17:43:01 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-06-12 18:16:03 +00:00
|
|
|
proc init*(key: var HashKey; data: openArray[byte]): bool =
|
|
|
|
## Import argument `data` into `key` which must have length either `32`, or
|
|
|
|
## `0`. The latter case is equivalent to an all zero byte array of size `32`.
|
|
|
|
if data.len == 32:
|
|
|
|
(addr key.ByteArray32[0]).copyMem(unsafeAddr data[0], data.len)
|
|
|
|
return true
|
|
|
|
if data.len == 0:
|
|
|
|
key = VOID_HASH_KEY
|
|
|
|
return true
|
|
|
|
|
2023-06-09 11:17:37 +00:00
|
|
|
proc init*(T: type AristoDb): T =
|
2023-05-14 17:43:01 +00:00
|
|
|
## Constructor with memory backend.
|
2023-06-09 11:17:37 +00:00
|
|
|
T(top: AristoLayerRef(),
|
|
|
|
backend: memoryBackend())
|
2023-05-14 17:43:01 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|