From 65aaf52f4c92a3a0096bcb86717f5aca3056d97a Mon Sep 17 00:00:00 2001 From: chen4903 <108803001+chen4903@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:26:35 +0800 Subject: [PATCH] accounts/abi: handle ABIs with contract type parameter (#30315) convert parameter of type contract to the basic `address` type --------- Co-authored-by: Martin HS --- accounts/abi/abi_test.go | 7 +++++++ accounts/abi/type.go | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index bc76df0dc2..dfcd059393 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -1218,3 +1218,10 @@ func TestUnpackRevert(t *testing.T) { }) } } + +func TestInternalContractType(t *testing.T) { + jsonData := `[{"inputs":[{"components":[{"internalType":"uint256","name":"dailyLimit","type":"uint256"},{"internalType":"uint256","name":"txLimit","type":"uint256"},{"internalType":"uint256","name":"accountDailyLimit","type":"uint256"},{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"bool","name":"onlyWhitelisted","type":"bool"}],"internalType":"struct IMessagePassingBridge.BridgeLimits","name":"bridgeLimits","type":"tuple"},{"components":[{"internalType":"uint256","name":"lastTransferReset","type":"uint256"},{"internalType":"uint256","name":"bridged24Hours","type":"uint256"}],"internalType":"struct IMessagePassingBridge.AccountLimit","name":"accountDailyLimit","type":"tuple"},{"components":[{"internalType":"uint256","name":"lastTransferReset","type":"uint256"},{"internalType":"uint256","name":"bridged24Hours","type":"uint256"}],"internalType":"struct IMessagePassingBridge.BridgeDailyLimit","name":"bridgeDailyLimit","type":"tuple"},{"internalType":"contract INameService","name":"nameService","type":"INameService"},{"internalType":"bool","name":"isClosed","type":"bool"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"canBridge","outputs":[{"internalType":"bool","name":"isWithinLimit","type":"bool"},{"internalType":"string","name":"error","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint8","name":"decimals","type":"uint8"}],"name":"normalizeFrom18ToTokenDecimals","outputs":[{"internalType":"uint256","name":"normalized","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint8","name":"decimals","type":"uint8"}],"name":"normalizeFromTokenTo18Decimals","outputs":[{"internalType":"uint256","name":"normalized","type":"uint256"}],"stateMutability":"pure","type":"function"}]` + if _, err := JSON(strings.NewReader(jsonData)); err != nil { + t.Fatal(err) + } +} diff --git a/accounts/abi/type.go b/accounts/abi/type.go index d57fa3d4e6..e59456f15a 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -219,7 +219,12 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty typ.T = FunctionTy typ.Size = 24 default: - return Type{}, fmt.Errorf("unsupported arg type: %s", t) + if strings.HasPrefix(internalType, "contract ") { + typ.Size = 20 + typ.T = AddressTy + } else { + return Type{}, fmt.Errorf("unsupported arg type: %s", t) + } } return