Skip to content

Commit 8e52f7b

Browse files
chen4903holiman
authored andcommitted
accounts/abi: handle ABIs with contract type parameter (#30315)
convert parameter of type contract to the basic `address` type --------- Co-authored-by: Martin HS <[email protected]>
1 parent 6b509b1 commit 8e52f7b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

accounts/abi/abi_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -1218,3 +1218,10 @@ func TestUnpackRevert(t *testing.T) {
12181218
})
12191219
}
12201220
}
1221+
1222+
func TestInternalContractType(t *testing.T) {
1223+
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"}]`
1224+
if _, err := JSON(strings.NewReader(jsonData)); err != nil {
1225+
t.Fatal(err)
1226+
}
1227+
}

accounts/abi/type.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
219219
typ.T = FunctionTy
220220
typ.Size = 24
221221
default:
222-
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
222+
if strings.HasPrefix(internalType, "contract ") {
223+
typ.Size = 20
224+
typ.T = AddressTy
225+
} else {
226+
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
227+
}
223228
}
224229

225230
return

0 commit comments

Comments
 (0)