Skip to content

Commit

Permalink
Fix missed lib handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Sep 12, 2024
1 parent 7a9f925 commit 24c37b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
12 changes: 11 additions & 1 deletion liteapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,17 @@ func (c *Client) GetBlock(ctx context.Context, blockID ton.BlockIDExt) (tlb.Bloc
if len(cells) != 1 {
return tlb.Block{}, boc.ErrNotSingleRoot
}
decoder := tlb.NewDecoder()
decoder := tlb.NewDecoder().WithLibraryResolver(func(hash tlb.Bits256) (*boc.Cell, error) {
localLibs, err := c.GetLibraries(ctx, []ton.Bits256{ton.Bits256(hash)})
if err != nil {
return nil, err
}
if len(localLibs) == 0 {
return nil, fmt.Errorf("library not found")
}
return localLibs[ton.Bits256(hash)], nil

})
var block tlb.Block
if err := decoder.Unmarshal(cells[0], &block); err != nil {
return tlb.Block{}, err
Expand Down
28 changes: 26 additions & 2 deletions tlb/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@ func decode(c *boc.Cell, tag string, val reflect.Value, decoder *Decoder) error
return err
}
if c.IsLibrary() {
return fmt.Errorf("library cell as a ref is not implemented")
if decoder.resolveLib == nil {
// use WithLibraryResolver to provide a library resolver
return fmt.Errorf("library cell decoding is not configured properly")
}
hash, err := c.Hash256()
if err != nil {
return err
}
cell, err := decoder.resolveLib(hash)
if err != nil {
return err
}
c = cell
}
if c.CellType() == boc.PrunedBranchCell {
return nil
Expand All @@ -134,7 +146,19 @@ func decode(c *boc.Cell, tag string, val reflect.Value, decoder *Decoder) error
return err
}
if c.IsLibrary() {
return fmt.Errorf("library cell as a ref is not implemented")
if decoder.resolveLib == nil {
// use WithLibraryResolver to provide a library resolver
return fmt.Errorf("library cell decoding is not configured properly")
}
hash, err := c.Hash256()
if err != nil {
return err
}
cell, err := decoder.resolveLib(hash)
if err != nil {
return err
}
c = cell
}
if c.CellType() == boc.PrunedBranchCell {
return nil
Expand Down

0 comments on commit 24c37b2

Please sign in to comment.