Skip to content

Commit 5b4326a

Browse files
authored
fix: delegation archive block ordering (#44)
In JS ucanto the variant block is the last block in the archive. The blockstore constructor prioritises the blocks passed as a slice over the blocks passed as an iterator so we need to create the blockstore with the block iterator and then add the variant block.
1 parent b44aaf7 commit 5b4326a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

core/delegation/delegation.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,18 @@ func Archive(d Delegation) io.Reader {
159159
return reader
160160
}
161161
// Create a new reader that contains the new block as well as the others.
162-
blks, err := blockstore.NewBlockReader(
163-
blockstore.WithBlocks([]ipld.Block{variant}),
164-
blockstore.WithBlocksIterator(d.Blocks()),
165-
)
162+
blks, err := blockstore.NewBlockStore(blockstore.WithBlocksIterator(d.Blocks()))
166163
if err != nil {
167164
reader, _ := io.Pipe()
168165
reader.CloseWithError(fmt.Errorf("creating new block reader: %s", err))
169166
return reader
170167
}
168+
err = blks.Put(variant)
169+
if err != nil {
170+
reader, _ := io.Pipe()
171+
reader.CloseWithError(fmt.Errorf("adding variant block: %s", err))
172+
return reader
173+
}
171174
return car.Encode([]ipld.Link{variant.Link()}, blks.Iterator())
172175
}
173176

0 commit comments

Comments
 (0)