diff --git a/codex/bittorrent/manifest/decoding.nim b/codex/bittorrent/manifest/decoding.nim index ffc715c7..3e173a0d 100644 --- a/codex/bittorrent/manifest/decoding.nim +++ b/codex/bittorrent/manifest/decoding.nim @@ -1,4 +1,5 @@ import pkg/libp2p/cid +import pkg/libp2p/multihash import pkg/libp2p/protobuf/minprotobuf import pkg/questionable/results @@ -29,7 +30,7 @@ func decode*(_: type BitTorrentManifest, data: openArray[byte]): ?!BitTorrentMan pbInfo: ProtoBuffer length: uint64 pieceLength: uint32 - pieces: seq[BitTorrentPiece] + pieces: seq[MultiHash] piecesBytes: seq[seq[byte]] name: string cidBuf = newSeq[byte]() @@ -49,7 +50,7 @@ func decode*(_: type BitTorrentManifest, data: openArray[byte]): ?!BitTorrentMan var pbPiece = initProtoBuffer(piece) var dataBuf = newSeq[byte]() if pbPiece.getField(1, dataBuf).isErr: - return failure("Unable to decode `data` from BitTorrentPiece") + return failure("Unable to decode piece `data` to MultiHash") without mhash =? MultiHash.init(dataBuf).mapFailure, err: return failure(err.msg) pieces.add(mhash) diff --git a/codex/bittorrent/manifest/encoding.nim b/codex/bittorrent/manifest/encoding.nim index 445aa6f5..55eb2958 100644 --- a/codex/bittorrent/manifest/encoding.nim +++ b/codex/bittorrent/manifest/encoding.nim @@ -1,11 +1,12 @@ import pkg/libp2p/cid +import pkg/libp2p/multihash import pkg/libp2p/protobuf/minprotobuf import pkg/questionable/results import ./manifest -proc write(pb: var ProtoBuffer, field: int, value: BitTorrentPiece) = +proc write(pb: var ProtoBuffer, field: int, value: MultiHash) = var ipb = initProtoBuffer() ipb.write(1, value.data.buffer) ipb.finish() diff --git a/codex/bittorrent/manifest/manifest.nim b/codex/bittorrent/manifest/manifest.nim index 7e9b1148..643f8798 100644 --- a/codex/bittorrent/manifest/manifest.nim +++ b/codex/bittorrent/manifest/manifest.nim @@ -11,11 +11,10 @@ import ../../codextypes import ../bencoding type - BitTorrentPiece* = MultiHash BitTorrentInfo* = ref object length* {.serialize.}: uint64 pieceLength* {.serialize.}: uint32 - pieces* {.serialize.}: seq[BitTorrentPiece] + pieces* {.serialize.}: seq[MultiHash] name* {.serialize.}: ?string BitTorrentManifest* = ref object