Skip to content

Commit 5f50dd5

Browse files
committed
Fix CallContract conversion for capaiblity
1 parent 6164491 commit 5f50dd5

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

pkg/capabilities/v2/chain-capabilities/evm/proto_helpers.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"fmt"
66
"time"
77

8+
valuespb "github.com/smartcontractkit/chainlink-common/pkg/values/pb"
9+
10+
"github.com/smartcontractkit/chainlink-common/pkg/chains/evm"
811
evmtypes "github.com/smartcontractkit/chainlink-common/pkg/types/chains/evm"
9-
valuespb "github.com/smartcontractkit/chainlink-protos/cre/go/values/pb"
1012
)
1113

1214
func ConvertAddressesFromProto(addresses [][]byte) []evmtypes.Address {
@@ -172,10 +174,20 @@ func ConvertCallMsgFromProto(protoMsg *CallMsg) (*evmtypes.CallMsg, error) {
172174
return nil, errEmptyMsg
173175
}
174176

177+
from, err := evm.ConvertOptionalAddressFromProto(protoMsg.From)
178+
if err != nil {
179+
return nil, fmt.Errorf("from address is invalid: %w", err)
180+
}
181+
182+
to, err := evm.ConvertAddressFromProto(protoMsg.GetTo())
183+
if err != nil {
184+
return nil, fmt.Errorf("to address is invalid: %w", err)
185+
}
186+
175187
return &evmtypes.CallMsg{
176-
From: evmtypes.Address(protoMsg.GetFrom()),
188+
From: from,
177189
Data: protoMsg.GetData(),
178-
To: evmtypes.Address(protoMsg.GetTo()),
190+
To: to,
179191
}, nil
180192
}
181193

pkg/chains/evm/proto_helpers.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,19 @@ func ConvertCallMsgFromProto(protoMsg *CallMsg) (*evmtypes.CallMsg, error) {
192192
if protoMsg == nil {
193193
return nil, errEmptyMsg
194194
}
195-
var from evmtypes.Address
196-
if len(protoMsg.From) != 0 {
197-
if len(protoMsg.From) != evmtypes.AddressLength {
198-
return nil, fmt.Errorf("invalid from address length: expected %d, got %d", evmtypes.AddressLength, len(protoMsg.From))
199-
}
200-
201-
from = evmtypes.Address(protoMsg.From)
195+
from, err := ConvertOptionalAddressFromProto(protoMsg.From)
196+
if err != nil {
197+
return nil, fmt.Errorf("from address is invalid: %w", err)
202198
}
203199

204-
if len(protoMsg.To) != evmtypes.AddressLength {
205-
return nil, fmt.Errorf("invalid to address length: expected %d, got %d", evmtypes.AddressLength, len(protoMsg.To))
200+
to, err := ConvertAddressFromProto(protoMsg.GetTo())
201+
if err != nil {
202+
return nil, fmt.Errorf("to address is invalid: %w", err)
206203
}
207204
return &evmtypes.CallMsg{
208205
From: from,
209206
Data: protoMsg.GetData(),
210-
To: evmtypes.Address(protoMsg.GetTo()),
207+
To: to,
211208
}, nil
212209
}
213210

@@ -573,6 +570,14 @@ func ConvertAddressFromProto(b []byte) (evmtypes.Address, error) {
573570
return evmtypes.Address(b), nil
574571
}
575572

573+
func ConvertOptionalAddressFromProto(b []byte) (evmtypes.Address, error) {
574+
if len(b) == 0 {
575+
return evmtypes.Address{}, nil // Return zero address if empty
576+
}
577+
578+
return ConvertAddressFromProto(b)
579+
}
580+
576581
func ConvertHashFromProto(b []byte) (evmtypes.Hash, error) {
577582
if len(b) != evmtypes.HashLength {
578583
return evmtypes.Hash{}, fmt.Errorf("invalid hash length: expected %d, got %d", evmtypes.HashLength, len(b))

0 commit comments

Comments
 (0)