Skip to content
Draft
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
20 changes: 14 additions & 6 deletions cciplib/ccip/bindings/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ func (c CrossChainAddress) ToCell() (*cell.Cell, error) {
return builder.EndCell(), nil
}

func (c *CrossChainAddress) LoadFromCell(s *cell.Slice) error {
func (c *CrossChainAddress) LoadFromCell(cell *cell.Cell) error {
s, err := cell.BeginParse()
if err != nil {
return fmt.Errorf("failed to begin parsing cell: %w", err)
}
if s.BitsLeft() < 8 {
return errors.New("crosschain address is too short")
}
Expand Down Expand Up @@ -236,7 +240,7 @@ func unpackArrayWithRefChaining[T any](root *cell.Cell) ([]T, error) {
break // move to next cell, do not decode this ref
}
var v T
if err := tlb.LoadFromCell(&v, ref.BeginParse()); err != nil {
if err := tlb.Parse(&v, ref); err != nil {
return nil, fmt.Errorf("failed to decode element: %w", err)
}
result = append(result, v)
Expand Down Expand Up @@ -357,7 +361,10 @@ func unpackArrayFromCell[T any](root *cell.Cell) ([]T, error) {
return nil, fmt.Errorf("cell chain depth %d exceeds maximum of %d cells", cellCount, MaxCellChainDepth)
}

s := curr.BeginParse()
s, err := curr.BeginParse()
if err != nil {
return nil, fmt.Errorf("failed to begin parsing cell: %w", err)
}
for s.BitsLeft() > 0 {
var v T
if err := tlb.LoadFromCell(&v, s); err != nil {
Expand All @@ -372,7 +379,6 @@ func unpackArrayFromCell[T any](root *cell.Cell) ([]T, error) {
}
// Use slice's remaining refs (after element refs are consumed), not cell's original refs.
// This correctly handles elements with ^ fields whose refs were consumed by tlb.LoadFromCell.
var err error
curr, err = loadChainRef(s)
if err != nil {
return nil, err
Expand Down Expand Up @@ -456,7 +462,10 @@ func unloadCellToByteArray(c *cell.Cell) ([]byte, error) {
return nil, fmt.Errorf("cell chain depth %d exceeds maximum of %d cells", cellCount, MaxCellChainDepth)
}

s := curr.BeginParse()
s, err := curr.BeginParse()
if err != nil {
return nil, fmt.Errorf("failed to begin parsing cell: %w", err)
}
for s.BitsLeft() > 0 {
part, err := s.LoadSlice(s.BitsLeft())
if err != nil {
Expand All @@ -472,7 +481,6 @@ func unloadCellToByteArray(c *cell.Cell) ([]byte, error) {
result = append(result, part...)
}

var err error
curr, err = loadChainRef(s)
if err != nil {
return nil, err
Expand Down
20 changes: 10 additions & 10 deletions cciplib/ccip/bindings/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCrossChainAddress_LoadFromCell(t *testing.T) {

c := builder.EndCell()
var addr CrossChainAddress
err = addr.LoadFromCell(c.BeginParse())
err = addr.LoadFromCell(c)

if tt.expectErr {
require.Error(t, err)
Expand All @@ -76,7 +76,7 @@ func TestCrossChainAddress_RoundTrip_Empty(t *testing.T) {
require.NoError(t, err)

var restored CrossChainAddress
err = restored.LoadFromCell(c.BeginParse())
err = restored.LoadFromCell(c)
require.NoError(t, err)
require.Empty(t, restored)
}
Expand All @@ -89,7 +89,7 @@ func TestCrossChainAddress_RoundTrip(t *testing.T) {
require.Equal(t, uint(56), c.BitsSize(), "CrossChainAddress should be 56 bits (7 bytes)")

var restored CrossChainAddress
err = restored.LoadFromCell(c.BeginParse())
err = restored.LoadFromCell(c)
require.NoError(t, err)

require.Equal(t, original, restored)
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestPackAndUnpack2DByteArrayToCell(t *testing.T) {
require.NoError(t, err, "ToCell should succeed - depth limits enforced during LoadFromCell")

var output SnakeRef[SnakeBytes]
err = tlb.LoadFromCell(&output, c.BeginParse())
err = tlb.Parse(&output, c)
require.NoError(t, err)
require.Len(t, tt.input, len(output), "array count mismatch")

Expand All @@ -250,7 +250,7 @@ func TestPackAndUnpack2DByteArrayToCell_CellStructure(t *testing.T) {

// Verify unpacking works correctly
var output SnakeRef[SnakeBytes]
err = tlb.LoadFromCell(&output, c.BeginParse())
err = tlb.Parse(&output, c)
require.NoError(t, err)
require.Len(t, arrays, len(output))

Expand All @@ -274,7 +274,7 @@ func TestPackAndUnpack2DByteArrayToCell_CellStructure(t *testing.T) {

// Verify unpacking works correctly
var output SnakeRef[SnakeBytes]
err = tlb.LoadFromCell(&output, c.BeginParse())
err = tlb.Parse(&output, c)
require.NoError(t, err)
require.Len(t, arrays, len(output))

Expand All @@ -299,7 +299,7 @@ func TestPackAndUnpack2DByteArrayToCell_CellStructure(t *testing.T) {
require.NoError(t, err)

var output SnakeRef[SnakeBytes]
err = tlb.LoadFromCell(&output, c.BeginParse())
err = tlb.Parse(&output, c)
require.NoError(t, err)
require.Equal(t, arrays, output)
})
Expand Down Expand Up @@ -497,15 +497,15 @@ func TestLoadCrossChainAddressWithoutPrefix_Validation(t *testing.T) {
builder := cell.BeginCell()
addr := []byte{0x01, 0x02, 0x03, 0x04, 0x05}
_ = builder.StoreSlice(addr, uint(len(addr))*8)
return builder.EndCell().BeginParse()
return builder.ToSlice()
},
expectErr: "",
},
{
name: "empty address",
setupFunc: func() *cell.Slice {
builder := cell.BeginCell()
return builder.EndCell().BeginParse()
return builder.ToSlice()
},
expectErr: "crosschain address is empty",
},
Expand All @@ -515,7 +515,7 @@ func TestLoadCrossChainAddressWithoutPrefix_Validation(t *testing.T) {
builder := cell.BeginCell()
addr := make([]byte, 65)
_ = builder.StoreSlice(addr, uint(len(addr))*8)
return builder.EndCell().BeginParse()
return builder.ToSlice()
},
expectErr: "exceeds maximum of 64 bytes",
},
Expand Down
4 changes: 2 additions & 2 deletions cciplib/ccip/bindings/feequoter/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var GetDestinationChainGasPrice = tvm.Getter[uint64, USDPerUnitGas]{
if err != nil {
return u, err
}
err = tlb.LoadFromCell(&u, c.BeginParse())
err = tlb.Parse(&u, c)
return u, err
}),
}
Expand All @@ -153,7 +153,7 @@ var GetTokenPrice = tvm.Getter[*address.Address, TimestampedPrice]{
Name: tokenPriceGetter,
Encoder: tvm.NewArgsEncoder(func(addr *address.Address) ([]any, error) {
// Encode address as a cell slice (as expected by the contract)
addrSlice := cell.BeginCell().MustStoreAddr(addr).EndCell().BeginParse()
addrSlice := cell.BeginCell().MustStoreAddr(addr).ToSlice()
return []any{addrSlice}, nil
}),
Decoder: tvm.NewResultDecoder(func(r *ton.ExecutionResult) (TimestampedPrice, error) {
Expand Down
2 changes: 1 addition & 1 deletion cciplib/ccip/bindings/ocr/commitreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestCommitReport_EncodingAndDecoding(t *testing.T) {

// Decode from cell
var decoded CommitReport
err = tlb.LoadFromCell(&decoded, newCell.BeginParse())
err = tlb.Parse(&decoded, newCell)
require.NoError(t, err)
require.Equal(t, c.Hash(), newCell.Hash())
require.Equal(t, commitReport, decoded)
Expand Down
4 changes: 2 additions & 2 deletions cciplib/ccip/bindings/ocr/executereport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestTokenAmounts(t *testing.T) {
})
require.NoError(t, err)
array := common.SnakeRef[Any2TVMTokenTransfer]{}
err = tlb.LoadFromCell(&array, tokenAmountsCell.BeginParse())
err = tlb.Parse(&array, tokenAmountsCell)
require.NoError(t, err)
require.Len(t, array, 6)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestExecute_EncodingAndDecoding(t *testing.T) {

// Decode from cell
var decoded ExecuteReport
err = tlb.LoadFromCell(&decoded, newCell.BeginParse())
err = tlb.Parse(&decoded, newCell)
require.NoError(t, err)
require.Equal(t, c.Hash(), newCell.Hash())
require.Len(t, decoded.Message.TokenAmounts, 3)
Expand Down
14 changes: 7 additions & 7 deletions cciplib/ccip/bindings/onramp/onramp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestGenericExtraArgsV2_TLBEncodeDecode(t *testing.T) {
require.NoError(t, err)

var decoded GenericExtraArgsV2
err = tlb.LoadFromCell(&decoded, c.BeginParse())
err = tlb.Parse(&decoded, c)
require.NoError(t, err)
require.Equal(t, orig.GasLimit, decoded.GasLimit)
require.Equal(t, orig.AllowOutOfOrderExecution, decoded.AllowOutOfOrderExecution)
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestSVMExtraArgsV1_ToCellAndLoadFromCell(t *testing.T) {
require.NoError(t, err)

var decoded SVMExtraArgsV1
err = tlb.LoadFromCell(&decoded, cell.BeginParse())
err = tlb.Parse(&decoded, cell)
require.NoError(t, err)
require.Equal(t, orig.ComputeUnits, decoded.ComputeUnits)
require.Equal(t, orig.AccountIsWritableBitmap, decoded.AccountIsWritableBitmap)
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestSuiExtraArgsV1_ToCellAndLoadFromCell(t *testing.T) {
require.NoError(t, err)

var decoded SuiExtraArgsV1
err = tlb.LoadFromCell(&decoded, cell.BeginParse())
err = tlb.Parse(&decoded, cell)
require.NoError(t, err)
require.Equal(t, orig.GasLimit, decoded.GasLimit)
require.Equal(t, orig.AllowOutOfOrderExecution, decoded.AllowOutOfOrderExecution)
Expand All @@ -155,7 +155,7 @@ func TestOwnable2Step(t *testing.T) {
cell, err := tlb.ToCell(orig)
require.NoError(t, err)
var decoded ownable2step.Storage
err = tlb.LoadFromCell(&decoded, cell.BeginParse())
err = tlb.Parse(&decoded, cell)
require.NoError(t, err)
require.Equal(t, orig.Owner, decoded.Owner)
require.Equal(t, orig.PendingOwner, decoded.PendingOwner)
Expand All @@ -167,7 +167,7 @@ func TestOwnable2Step(t *testing.T) {
}
cell, err = tlb.ToCell(orig2)
require.NoError(t, err)
err = tlb.LoadFromCell(&decoded, cell.BeginParse())
err = tlb.Parse(&decoded, cell)
require.NoError(t, err)
require.Equal(t, orig2.Owner, decoded.Owner)
require.Equal(t, orig2.PendingOwner, decoded.PendingOwner)
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestDestChainConfig(t *testing.T) {
c, err := tlb.ToCell(dc)
require.NoError(t, err)
var decoded DestChainConfig
err = tlb.LoadFromCell(&decoded, c.BeginParse())
err = tlb.Parse(&decoded, c)
require.NoError(t, err)
require.Equal(t, dc.Router, decoded.Router)
require.Equal(t, dc.SequenceNumber, decoded.SequenceNumber)
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestStorage(t *testing.T) {
c, err = tlb.ToCell(s)
require.NoError(t, err)
var decoded Storage
err = tlb.LoadFromCell(&decoded, c.BeginParse())
err = tlb.Parse(&decoded, c)
require.NoError(t, err)
require.Equal(t, s.ID, decoded.ID)
require.Equal(t, s.Ownable.Owner, decoded.Ownable.Owner)
Expand Down
2 changes: 1 addition & 1 deletion cciplib/ccip/codec/commitcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (cr *commitPluginCodecV1) Decode(ctx context.Context, bytes []byte) (ccipty
}

var report ocr.CommitReport
if err := tlb.LoadFromCell(&report, c.BeginParse()); err != nil {
if err := tlb.Parse(&report, c); err != nil {
return cciptypes.CommitPluginReport{}, fmt.Errorf("cannot decode commit report from cell: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions cciplib/ccip/codec/executecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (e *executePluginCodecV1) Decode(ctx context.Context, data []byte) (ccipocr

// TON supports single chain only, decode single ExecuteReport (not array)
var tonReport ocr.ExecuteReport
err = tlb.LoadFromCell(&tonReport, c.BeginParse())
err = tlb.Parse(&tonReport, c)
if err != nil {
return ccipocr3.ExecutePluginReport{}, fmt.Errorf("unpack execute report: %w", err)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (e *executePluginCodecV1) Decode(ctx context.Context, data []byte) (ccipocr
var tokenAmounts []ccipocr3.RampTokenAmount
for _, tokenAmount := range msg.TokenAmounts {
var extraData common.SnakeBytes
err = tlb.LoadFromCell(&extraData, tokenAmount.ExtraData.BeginParse())
err = tlb.Parse(&extraData, tokenAmount.ExtraData)
if err != nil {
return executeReport, fmt.Errorf("unpack extra data: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cciplib/ccip/codec/executecodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestExecutePluginCodecV1_TON(t *testing.T) {
c, err := cell.FromBOC(boc)
require.NoError(t, err)
var report ocr.ExecuteReport
err = tlb.LoadFromCell(&report, c.BeginParse())
err = tlb.Parse(&report, c)
require.NoError(t, err)
return report
}
Expand Down
8 changes: 6 additions & 2 deletions cciplib/ccip/codec/extradatacodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func (d extraDataDecoder) DecodeExtraArgsToMap(extraArgs ccipocr3.Bytes) (map[st
return nil, fmt.Errorf("failed to decode BOC: %w", err)
}

tag, err := c.BeginParse().LoadSlice(32)
s, err := c.BeginParse()
if err != nil {
return nil, fmt.Errorf("failed to begin parsing cell: %w", err)
}
tag, err := s.LoadSlice(32)
if err != nil {
return nil, fmt.Errorf("failed to load tag from cell: %w", err)
}
Expand All @@ -68,7 +72,7 @@ func (d extraDataDecoder) DecodeExtraArgsToMap(extraArgs ccipocr3.Bytes) (map[st
}

argsPtr := reflect.New(argsType)
if err = tlb.LoadFromCell(argsPtr.Interface(), c.BeginParse()); err != nil {
if err = tlb.Parse(argsPtr.Interface(), c); err != nil {
return nil, fmt.Errorf("failed to tlb load extra args from cell: %w", err)
}

Expand Down
6 changes: 3 additions & 3 deletions cciplib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ require (
github.com/smartcontractkit/chain-selectors v1.0.98
github.com/smartcontractkit/chainlink-common v0.11.2-0.20260407150650-8115835abd6e
github.com/stretchr/testify v1.11.1
github.com/xssnick/tonutils-go v1.14.1
github.com/xssnick/tonutils-go v1.18.0
golang.org/x/sync v0.22.0
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
filippo.io/edwards25519 v1.2.0 // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/btcsuite/btcutil v1.0.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -42,9 +42,9 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mostynb/zstdpool-freelist v0.0.0-20201229113212-927304c0c3b1 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/pierrec/lz4/v4 v4.1.27 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 // indirect
github.com/smartcontractkit/libocr v0.0.0-20250912173940-f3ab0246e23d // indirect
github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091 // indirect
github.com/stretchr/objx v0.5.2 // indirect
Expand Down
12 changes: 6 additions & 6 deletions cciplib/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading