Skip to content

Commit

Permalink
Fix boc.DeserializeBoc() when cells serialized with hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Dec 25, 2023
1 parent 96b610b commit 7bf6788
Show file tree
Hide file tree
Showing 4 changed files with 6,453 additions and 5 deletions.
8 changes: 4 additions & 4 deletions boc/boc.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ func deserializeCellData(cellData []byte, referenceIndexSize int) (*Cell, []int,
withHashes := (d1 & 0b10000) != 0
mask := levelMask(d1 >> 5)

if withHashes {
offset := mask.HashesCount() * (hashSize + depthSize)
cellData = cellData[offset:]
}
var cell *Cell
if isExotic {
// the first byte of an exotic cell stores the cell's type.
Expand All @@ -204,10 +208,6 @@ func deserializeCellData(cellData []byte, referenceIndexSize int) (*Cell, []int,
cell = NewCell()
cell.mask = mask
}
if withHashes {
offset := mask.HashesCount() * (hashSize + depthSize)
cellData = cellData[offset:]
}

if len(cellData) < dataBytesSize+referenceIndexSize*refNum {
return nil, nil, nil, errors.New("not enough bytes to encode cell data")
Expand Down
7 changes: 6 additions & 1 deletion boc/boc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ func TestDeserializeBoc(t *testing.T) {
resultFilename string
}{
{
resultFilename: "testdata/deserialize_block.json",
name: "block 1",
resultFilename: "testdata/deserialize-block-1.json",
},
{
name: "block 2",
resultFilename: "testdata/deserialize-block-2.json",
},
}
for _, tc := range testCases {
Expand Down
File renamed without changes.
Loading

0 comments on commit 7bf6788

Please sign in to comment.