fix treehash generation

This commit is contained in:
Dmitriy Ryajov 2022-01-10 20:42:05 -06:00
parent 47a0d4ef7a
commit 419020ef6b
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 11 additions and 10 deletions

View File

@ -79,9 +79,6 @@ proc cid*(b: var BlocksManifest): ?!Cid =
var var
stack: seq[MultiHash] stack: seq[MultiHash]
if stack.len == 1:
stack.add((? EmptyDigests[b.version][b.hcodec].catch))
for cid in b.blocks: for cid in b.blocks:
stack.add(? cid.mhash.mapFailure) stack.add(? cid.mhash.mapFailure)
@ -95,7 +92,11 @@ proc cid*(b: var BlocksManifest): ?!Cid =
stack.add(mh) stack.add(mh)
if stack.len == 1: if stack.len == 1:
let cid = ? Cid.init(b.version, b.codec, stack[0]).mapFailure let cid = ? Cid.init(
b.version,
b.codec,
(? EmptyDigests[b.version][b.hcodec].catch))
.mapFailure
b.htree = cid.some b.htree = cid.some
return cid.success return cid.success

View File

@ -28,17 +28,17 @@ suite "Manifest":
fail() fail()
let let
checksum = @[18.byte, 32, 14, 78, 178, 161, checksum = @[18.byte, 32, 227, 176, 196, 66, 152,
50, 175, 26, 57, 68, 6, 163, 128, 252, 28, 20, 154, 251, 244, 200, 153,
19, 131, 212, 203, 93, 98, 219, 111, 185, 36, 39, 174, 65, 228, 100,
34, 243, 217, 132, 191, 86, 255, 155, 147, 76, 164, 149, 153, 27, 120,
171, 160, 77, 167, 91, 145] 82, 184, 85]
var mh: MultiHash var mh: MultiHash
check MultiHash.decode(checksum, mh).get() > 0 check MultiHash.decode(checksum, mh).get() > 0
let checkSumCid = Cid.init(manifest.version, manifest.codec, mh).get() let checkSumCid = Cid.init(manifest.version, manifest.codec, mh).get()
check checkSumCid == !(manifest.cid) check checkSumCid == manifest.cid.get()
test "Should encode/decode to/from manifest": test "Should encode/decode to/from manifest":
let let