This commit is contained in:
Dmitriy Ryajov 2023-10-26 09:11:50 -06:00
parent 4d8a4c2a24
commit 81a6eb13bc
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
5 changed files with 51 additions and 2 deletions

View File

View File

@ -0,0 +1,28 @@
## Nim-Codex
## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
## at your option.
## This file may not be copied, modified, or distributed except according to
## those terms.
import ./merklestore
import pkg/datastore
import ../../namespaces
type
DataStoreBackend* = ref object of MerkleStore
store*: Datastore
method put*(
self: DataStoreBackend,
index, level: Natural,
hash: seq[byte]): Future[?!void] {.async.} =
success await self.store.put(index, hash)
method get*(self: DataStoreBackend, index, level: Natural): Future[!?seq[byte]] =
raiseAssert("Not implemented!")
func new*(_: type DataStoreBackend, store: Datastore): DataStoreBackend =
DataStoreBackend(store: store)

View File

@ -0,0 +1,17 @@
## Nim-Codex
## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
## at your option.
## This file may not be copied, modified, or distributed except according to
## those terms.
type
MerkleStore* = ref object of RootObj
method put*(self: MerkleStore, index, level: Natural, hash: seq[byte]): Future[?!void] =
raiseAssert("Not implemented!")
method get*(self: MerkleStore, index, level: Natural): Future[!?seq[byte]] =
raiseAssert("Not implemented!")

View File

@ -26,14 +26,14 @@ logScope:
topics = "codex merkletree"
type
MerkleTree* = object
MerkleTree* = ref object of RootObj
mcodec: MultiCodec # multicodec of the hash function
height: Natural # current height of the tree (levels - 1)
levels: Natural # number of levels in the tree (height + 1)
leafs: Natural # total number of leafs, if odd the last leaf will be hashed twice
length: Natural # corrected to even number of leafs in the tree
size: Natural # total number of nodes in the tree (corrected for odd leafs)
leafsIter: AsyncIter[seq[byte]] # leafs iterator of the tree
nodesIter: AsyncIter[seq[byte]] # nodes iterator of the tree
MerkleProof* = object
mcodec: MultiCodec
@ -135,6 +135,7 @@ func init*(
self = MerkleTree(
mcodec: mcodec,
leafs: leafs,
length: length,
size: size,
height: height,
levels: height - 1,

View File

@ -14,6 +14,9 @@ const
CodexBlockTotalNamespace* = CodexMetaNamespace & "/total" # number of blocks in the repo
CodexBlocksNamespace* = CodexRepoNamespace & "/blocks" # blocks namespace
CodexManifestNamespace* = CodexRepoNamespace & "/manifests" # manifest namespace
CodexMerkleTreeNamespace* = CodexRepoNamespace & "/trees" # merkle tree namespace
CodexMerkleTreeHeader* = # merkle tree header
CodexMerkleTreeNamespace & "/header"
CodexBlocksTtlNamespace* = # Cid TTL
CodexMetaNamespace & "/ttl"
CodexBlockProofNamespace* = # Cid and Proof