Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missed lib handling #295

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading