From f9176955a37f661dea5f1ba931fdf7ffe900ee74 Mon Sep 17 00:00:00 2001 From: chenqin <490358423@qq.com> Date: Mon, 19 Aug 2024 18:09:23 +0800 Subject: [PATCH 1/3] internal contract type --- accounts/abi/abi_test.go | 8 ++++++++ accounts/abi/type.go | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index bc76df0dc264..8d7212c19483 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -1218,3 +1218,11 @@ 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"}]` + _, err := JSON(strings.NewReader(jsonData)) + if err != nil { + t.Fatal("ERROR:", err) + } +} \ No newline at end of file diff --git a/accounts/abi/type.go b/accounts/abi/type.go index d57fa3d4e667..fa89a6c1858d 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.Contains(internalType, "contract") { + typ.Size = 20 + typ.T = AddressTy + } else { + return Type{}, fmt.Errorf("unsupported arg type: %s", t) + } } return From dd8b5f1a96d45d2ea4f1f60c9a82f639f867d2d6 Mon Sep 17 00:00:00 2001 From: Martin HS Date: Mon, 19 Aug 2024 13:40:16 +0200 Subject: [PATCH 2/3] Update accounts/abi/type.go --- accounts/abi/type.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/abi/type.go b/accounts/abi/type.go index fa89a6c1858d..e59456f15af0 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -219,7 +219,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty typ.T = FunctionTy typ.Size = 24 default: - if strings.Contains(internalType, "contract") { + if strings.HasPrefix(internalType, "contract ") { typ.Size = 20 typ.T = AddressTy } else { From 7961289023e677665a4fce5d0c81f2d71b4fc696 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 20 Aug 2024 10:24:42 +0200 Subject: [PATCH 3/3] accounts/abi: go format --- accounts/abi/abi_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 8d7212c19483..dfcd0593937c 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -1219,10 +1219,9 @@ func TestUnpackRevert(t *testing.T) { } } -func TestInternalContractType(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"}]` - _, err := JSON(strings.NewReader(jsonData)) - if err != nil { - t.Fatal("ERROR:", err) + if _, err := JSON(strings.NewReader(jsonData)); err != nil { + t.Fatal(err) } -} \ No newline at end of file +}