2023-11-14 12:02:17 +00:00
|
|
|
## 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 pkg/upraises
|
|
|
|
|
|
|
|
push: {.upraises: [].}
|
|
|
|
|
|
|
|
import std/sugar
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/chronos/futures
|
|
|
|
import pkg/metrics
|
|
|
|
import pkg/questionable
|
|
|
|
import pkg/questionable/results
|
|
|
|
|
|
|
|
import ./blockstore
|
|
|
|
import ../utils/asynciter
|
|
|
|
import ../merkletree
|
|
|
|
|
2023-12-21 06:41:43 +00:00
|
|
|
proc putSomeProofs*(store: BlockStore, tree: CodexTree, iter: Iter[int]): Future[?!void] {.async.} =
|
2023-11-14 12:02:17 +00:00
|
|
|
without treeCid =? tree.rootCid, err:
|
|
|
|
return failure(err)
|
|
|
|
|
|
|
|
for i in iter:
|
|
|
|
if i notin 0..<tree.leavesCount:
|
|
|
|
return failure("Invalid leaf index " & $i & ", tree with cid " & $treeCid & " has " & $tree.leavesCount & " leaves")
|
|
|
|
|
|
|
|
without blkCid =? tree.getLeafCid(i), err:
|
|
|
|
return failure(err)
|
|
|
|
|
|
|
|
without proof =? tree.getProof(i), err:
|
|
|
|
return failure(err)
|
|
|
|
|
2024-01-08 22:52:46 +00:00
|
|
|
let res = await store.putCidAndProof(treeCid, i, blkCid, proof)
|
2023-11-14 12:02:17 +00:00
|
|
|
|
|
|
|
if err =? res.errorOption:
|
|
|
|
return failure(err)
|
2023-12-21 06:41:43 +00:00
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
success()
|
|
|
|
|
2023-12-21 06:41:43 +00:00
|
|
|
proc putSomeProofs*(store: BlockStore, tree: CodexTree, iter: Iter[Natural]): Future[?!void] =
|
2023-11-14 12:02:17 +00:00
|
|
|
store.putSomeProofs(tree, iter.map((i: Natural) => i.ord))
|
|
|
|
|
2023-12-21 06:41:43 +00:00
|
|
|
proc putAllProofs*(store: BlockStore, tree: CodexTree): Future[?!void] =
|
2024-05-15 15:59:14 +00:00
|
|
|
store.putSomeProofs(tree, newIter(0..<tree.leavesCount))
|