mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-25 08:43:07 +00:00
wip
This commit is contained in:
parent
4d8a4c2a24
commit
81a6eb13bc
0
codex/merkletree/backend.nim
Normal file
0
codex/merkletree/backend.nim
Normal file
28
codex/merkletree/backends/dsbackend.nim
Normal file
28
codex/merkletree/backends/dsbackend.nim
Normal 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)
|
||||
17
codex/merkletree/backends/merklestore.nim
Normal file
17
codex/merkletree/backends/merklestore.nim
Normal 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!")
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user