Skip to content

Commit

Permalink
pass through Cid Codec to buildCid method
Browse files Browse the repository at this point in the history
  • Loading branch information
kevodwyer committed Oct 20, 2023
1 parent 2f4e892 commit 65490c6
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ public CompletableFuture<BlockMetadata> getBlockMetadata(Cid block) {
});
}

private void cacheBlockMetadata(byte[] block, boolean isRaw) {
Cid cid = hashToCid(block, isRaw);
private void cacheBlockMetadata(byte[] block, Cid.Codec codec) {
Cid cid = hashToCid(block, codec);
metadata.put(cid, block);
}

private Cid hashToCid(byte[] input, boolean isRaw) {
return buildCid(Hash.sha256(input), isRaw);
private Cid hashToCid(byte[] input, Cid.Codec codec) {
return buildCid(Hash.sha256(input), codec);
}

private Cid buildCid(byte[] sha256, boolean isRaw) {
return Cid.buildCidV1(isRaw ? Cid.Codec.Raw : Cid.Codec.DagCbor, Multihash.Type.sha2_256, sha256);
private Cid buildCid(byte[] sha256, Cid.Codec codec) {
return Cid.buildCidV1(codec, Multihash.Type.sha2_256, sha256);
}

@Override
public CompletableFuture<Optional<byte[]>> get(Cid hash) {
return target.get(hash).thenApply(bopt -> {
bopt.ifPresent(b -> cacheBlockMetadata(b, hash.codec == Cid.Codec.Raw));
bopt.ifPresent(b -> cacheBlockMetadata(b, hash.codec));
return bopt;
});
}
Expand Down

0 comments on commit 65490c6

Please sign in to comment.