From 3d0a0b25cd0383bbc9d36a4c1bc0bebf1d440b20 Mon Sep 17 00:00:00 2001 From: tonykwok1992 Date: Sat, 15 Jun 2024 00:45:40 +0800 Subject: [PATCH 1/4] Big fix for codegen when Array of struct and struct used together Signed-off-by: tonykwok1992 --- .../codegen/SolidityFunctionWrapper.java | 15 +- .../SolidityFunctionWrapperGeneratorTest.java | 11 ++ .../ArrayOfStructAndStruct.sol | 21 +++ .../build/ArrayOfStructAndStruct.abi | 1 + .../build/ArrayOfStructAndStruct.bin | 1 + .../build/java/ArrayOfStructAndStruct.java | 148 ++++++++++++++++++ .../core/methods/response/AbiDefinition.java | 18 ++- 7 files changed, 205 insertions(+), 10 deletions(-) create mode 100644 codegen/src/test/resources/solidity/arrayofstructandstruct/ArrayOfStructAndStruct.sol create mode 100644 codegen/src/test/resources/solidity/arrayofstructandstruct/build/ArrayOfStructAndStruct.abi create mode 100644 codegen/src/test/resources/solidity/arrayofstructandstruct/build/ArrayOfStructAndStruct.bin create mode 100644 codegen/src/test/resources/solidity/arrayofstructandstruct/build/java/ArrayOfStructAndStruct.java diff --git a/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java b/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java index b29dd6c18..1127df072 100644 --- a/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java +++ b/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java @@ -129,7 +129,7 @@ public class SolidityFunctionWrapper extends Generator { private final boolean abiFuncs; private final int addressLength; - private final HashMap structClassNameMap = new HashMap<>(); + private final HashMap structClassNameMap = new HashMap<>(); private final List structsNamedTypeList = new ArrayList<>(); @@ -589,7 +589,7 @@ private static String getStructName(String internalType) { String tempStructName = fullStructName.substring(fullStructName.lastIndexOf(".") + 1); int arrayPos = tempStructName.indexOf("["); if (arrayPos > -1) { - tempStructName = tempStructName.substring(0, arrayPos); + tempStructName = tempStructName.substring(0, arrayPos); } final String structName = SourceVersion.isName(tempStructName) ? tempStructName : "_" + tempStructName; @@ -628,7 +628,7 @@ private NamedType normalizeNamedType(NamedType namedType) { @NotNull private List extractStructs( final List functionDefinitions) { - final HashMap structMap = new LinkedHashMap<>(); + final HashMap structMap = new LinkedHashMap<>(); functionDefinitions.stream() .flatMap( definition -> { @@ -641,7 +641,8 @@ private List extractStructs( }) .forEach( namedType -> { - structMap.put(namedType.structIdentifier(), namedType); + structMap.put( + namedType.flattenNamedType().structIdentifier(), namedType); extractNested(namedType).stream() .map(this::normalizeNamedType) .filter( @@ -650,7 +651,9 @@ private List extractStructs( .forEach( nestedNamedType -> structMap.put( - nestedNamedType.structIdentifier(), + nestedNamedType + .flattenNamedType() + .structIdentifier(), nestedNamedType)); }); @@ -2288,7 +2291,7 @@ public boolean isIndexed() { return namedType.isIndexed(); } - public int structIdentifier() { + public String structIdentifier() { return namedType.structIdentifier(); } } diff --git a/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java b/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java index 8c3e924d5..605bc45db 100644 --- a/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java +++ b/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java @@ -232,6 +232,17 @@ public void testArrayOfStructClassGenerationCompareJavaFile() throws Exception { compareJavaFile("ArrayOfStructClassGeneration", true); } + @Test + public void testArrayOfStructAndStructGeneration() throws Exception { + testCodeGeneration( + "arrayofstructandstruct", "ArrayOfStructAndStruct", JAVA_TYPES_ARG, false); + } + + @Test + public void testArrayOfStructAndStructCompareJavaFile() throws Exception { + compareJavaFile("ArrayOfStructAndStruct", true); + } + private void compareJavaFile(String inputFileName, boolean useBin) throws Exception { String contract = inputFileName.toLowerCase(); String packagePath = diff --git a/codegen/src/test/resources/solidity/arrayofstructandstruct/ArrayOfStructAndStruct.sol b/codegen/src/test/resources/solidity/arrayofstructandstruct/ArrayOfStructAndStruct.sol new file mode 100644 index 000000000..7f754db09 --- /dev/null +++ b/codegen/src/test/resources/solidity/arrayofstructandstruct/ArrayOfStructAndStruct.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + + +contract ArrayOfStructAndStruct { + + struct Foo { + bool dummy; + } + + constructor() { + + } + function test(Foo[2] calldata foos) external { + revert(); + } + + function testSingle(Foo calldata foo) external { + revert(); + } +} diff --git a/codegen/src/test/resources/solidity/arrayofstructandstruct/build/ArrayOfStructAndStruct.abi b/codegen/src/test/resources/solidity/arrayofstructandstruct/build/ArrayOfStructAndStruct.abi new file mode 100644 index 000000000..0da5ecba7 --- /dev/null +++ b/codegen/src/test/resources/solidity/arrayofstructandstruct/build/ArrayOfStructAndStruct.abi @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"components":[{"internalType":"bool","name":"dummy","type":"bool"}],"internalType":"struct ArrayOfStructAndStruct.Foo[2]","name":"foos","type":"tuple[2]"}],"name":"test","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"dummy","type":"bool"}],"internalType":"struct ArrayOfStructAndStruct.Foo","name":"foo","type":"tuple"}],"name":"testSingle","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/codegen/src/test/resources/solidity/arrayofstructandstruct/build/ArrayOfStructAndStruct.bin b/codegen/src/test/resources/solidity/arrayofstructandstruct/build/ArrayOfStructAndStruct.bin new file mode 100644 index 000000000..43f374cac --- /dev/null +++ b/codegen/src/test/resources/solidity/arrayofstructandstruct/build/ArrayOfStructAndStruct.bin @@ -0,0 +1 @@ +608060405234801561000f575f80fd5b5061014f8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c80631ae18a6414610038578063f0cd1e3b14610054575b5f80fd5b610052600480360381019061004d91906100a1565b610070565b005b61006e600480360381019061006991906100ee565b610074565b005b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f8190508260206002028201111561009b5761009a61007c565b5b92915050565b5f604082840312156100b6576100b5610078565b5b5f6100c384828501610080565b91505092915050565b5f80fd5b5f602082840312156100e5576100e46100cc565b5b81905092915050565b5f6020828403121561010357610102610078565b5b5f610110848285016100d0565b9150509291505056fea2646970667358221220deb8c438006301a2bb5f5ed22ad6516a4f075c63a360dad46a6571057187273164736f6c63430008140033 \ No newline at end of file diff --git a/codegen/src/test/resources/solidity/arrayofstructandstruct/build/java/ArrayOfStructAndStruct.java b/codegen/src/test/resources/solidity/arrayofstructandstruct/build/java/ArrayOfStructAndStruct.java new file mode 100644 index 000000000..93e170c46 --- /dev/null +++ b/codegen/src/test/resources/solidity/arrayofstructandstruct/build/java/ArrayOfStructAndStruct.java @@ -0,0 +1,148 @@ +package org.web3j.unittests.java; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.web3j.abi.TypeReference; +import org.web3j.abi.datatypes.Bool; +import org.web3j.abi.datatypes.Function; +import org.web3j.abi.datatypes.StaticStruct; +import org.web3j.abi.datatypes.Type; +import org.web3j.crypto.Credentials; +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.RemoteCall; +import org.web3j.protocol.core.RemoteFunctionCall; +import org.web3j.protocol.core.methods.response.TransactionReceipt; +import org.web3j.tx.Contract; +import org.web3j.tx.TransactionManager; +import org.web3j.tx.gas.ContractGasProvider; + +/** + *

Auto generated code. + *

Do not modify! + *

Please use the web3j command line tools, + * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the + * codegen module to update. + * + *

Generated with web3j version none. + */ +@SuppressWarnings("rawtypes") +public class ArrayOfStructAndStruct extends Contract { + public static final String BINARY = "608060405234801561000f575f80fd5b5061014f8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c80631ae18a6414610038578063f0cd1e3b14610054575b5f80fd5b610052600480360381019061004d91906100a1565b610070565b005b61006e600480360381019061006991906100ee565b610074565b005b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f8190508260206002028201111561009b5761009a61007c565b5b92915050565b5f604082840312156100b6576100b5610078565b5b5f6100c384828501610080565b91505092915050565b5f80fd5b5f602082840312156100e5576100e46100cc565b5b81905092915050565b5f6020828403121561010357610102610078565b5b5f610110848285016100d0565b9150509291505056fea2646970667358221220deb8c438006301a2bb5f5ed22ad6516a4f075c63a360dad46a6571057187273164736f6c63430008140033"; + + private static String librariesLinkedBinary; + + public static final String FUNC_TEST = "test"; + + public static final String FUNC_TESTSINGLE = "testSingle"; + + @Deprecated + protected ArrayOfStructAndStruct(String contractAddress, Web3j web3j, Credentials credentials, + BigInteger gasPrice, BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + protected ArrayOfStructAndStruct(String contractAddress, Web3j web3j, Credentials credentials, + ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, credentials, contractGasProvider); + } + + @Deprecated + protected ArrayOfStructAndStruct(String contractAddress, Web3j web3j, + TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + protected ArrayOfStructAndStruct(String contractAddress, Web3j web3j, + TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); + } + + public RemoteFunctionCall test(List foos) { + final Function function = new Function( + FUNC_TEST, + Arrays.asList(new org.web3j.abi.datatypes.generated.StaticArray2(Foo.class, foos)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteFunctionCall testSingle(Foo foo) { + final Function function = new Function( + FUNC_TESTSINGLE, + Arrays.asList(foo), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + @Deprecated + public static ArrayOfStructAndStruct load(String contractAddress, Web3j web3j, + Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return new ArrayOfStructAndStruct(contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + @Deprecated + public static ArrayOfStructAndStruct load(String contractAddress, Web3j web3j, + TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + return new ArrayOfStructAndStruct(contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + public static ArrayOfStructAndStruct load(String contractAddress, Web3j web3j, + Credentials credentials, ContractGasProvider contractGasProvider) { + return new ArrayOfStructAndStruct(contractAddress, web3j, credentials, contractGasProvider); + } + + public static ArrayOfStructAndStruct load(String contractAddress, Web3j web3j, + TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return new ArrayOfStructAndStruct(contractAddress, web3j, transactionManager, contractGasProvider); + } + + public static RemoteCall deploy(Web3j web3j, Credentials credentials, + ContractGasProvider contractGasProvider) { + return deployRemoteCall(ArrayOfStructAndStruct.class, web3j, credentials, contractGasProvider, getDeploymentBinary(), ""); + } + + public static RemoteCall deploy(Web3j web3j, + TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return deployRemoteCall(ArrayOfStructAndStruct.class, web3j, transactionManager, contractGasProvider, getDeploymentBinary(), ""); + } + + @Deprecated + public static RemoteCall deploy(Web3j web3j, Credentials credentials, + BigInteger gasPrice, BigInteger gasLimit) { + return deployRemoteCall(ArrayOfStructAndStruct.class, web3j, credentials, gasPrice, gasLimit, getDeploymentBinary(), ""); + } + + @Deprecated + public static RemoteCall deploy(Web3j web3j, + TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + return deployRemoteCall(ArrayOfStructAndStruct.class, web3j, transactionManager, gasPrice, gasLimit, getDeploymentBinary(), ""); + } + + public static void linkLibraries(List references) { + librariesLinkedBinary = linkBinaryWithReferences(BINARY, references); + } + + private static String getDeploymentBinary() { + if (librariesLinkedBinary != null) { + return librariesLinkedBinary; + } else { + return BINARY; + } + } + + public static class Foo extends StaticStruct { + public Boolean dummy; + + public Foo(Boolean dummy) { + super(new org.web3j.abi.datatypes.Bool(dummy)); + this.dummy = dummy; + } + + public Foo(Bool dummy) { + super(dummy); + this.dummy = dummy.getValue(); + } + } +} + diff --git a/core/src/main/java/org/web3j/protocol/core/methods/response/AbiDefinition.java b/core/src/main/java/org/web3j/protocol/core/methods/response/AbiDefinition.java index d08b1ad8c..12f17d830 100644 --- a/core/src/main/java/org/web3j/protocol/core/methods/response/AbiDefinition.java +++ b/core/src/main/java/org/web3j/protocol/core/methods/response/AbiDefinition.java @@ -275,12 +275,11 @@ public void setComponents(final List components) { this.components = components; } - public int structIdentifier() { + public String structIdentifier() { return ((internalType == null ? type : internalType.isEmpty() ? type : internalType) + components.stream() - .map(namedType -> String.valueOf(namedType.structIdentifier())) - .collect(Collectors.joining())) - .hashCode(); + .map(NamedType::structIdentifier) + .collect(Collectors.joining())); } public int nestedness() { @@ -299,6 +298,17 @@ public boolean isDynamic() { return components.stream().anyMatch(NamedType::isDynamic); } + public NamedType flattenNamedType() { + int arrayPos = this.type.indexOf("["); + if(arrayPos > 0) return new NamedType( + this.name, + this.type.substring(0, arrayPos), + this.components, + this.internalType.substring(0, this.internalType.indexOf("[")), + this.indexed); + return this; + } + @Override public boolean equals(Object o) { if (this == o) { From 5c49ed358ebe31f430ea4598b6d0d218db0c8c8c Mon Sep 17 00:00:00 2001 From: tonykwok1992 Date: Sun, 16 Jun 2024 16:38:11 +0800 Subject: [PATCH 2/4] separate array type handling Signed-off-by: tonykwok1992 --- .../codegen/SolidityFunctionWrapper.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java b/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java index 1127df072..2eeddf4e6 100644 --- a/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java +++ b/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java @@ -641,20 +641,34 @@ private List extractStructs( }) .forEach( namedType -> { - structMap.put( - namedType.flattenNamedType().structIdentifier(), namedType); + if (namedType.getType().startsWith("tuple[")) { + structMap.putIfAbsent( + namedType.flattenNamedType().structIdentifier(), namedType); + } else { + structMap.put(namedType.structIdentifier(), namedType); + } + extractNested(namedType).stream() .map(this::normalizeNamedType) .filter( nestedNamedStruct -> nestedNamedStruct.getType().startsWith("tuple")) .forEach( - nestedNamedType -> - structMap.put( + nestedNamedType -> { + if (nestedNamedType + .getType() + .startsWith("tuple[")) { + structMap.putIfAbsent( nestedNamedType .flattenNamedType() .structIdentifier(), - nestedNamedType)); + nestedNamedType); + } else { + structMap.put( + nestedNamedType.structIdentifier(), + nestedNamedType); + } + }); }); return structMap.values().stream() From 3085bf1a47e2219446f0a6a6dad42773c1ae2479 Mon Sep 17 00:00:00 2001 From: tonykwok1992 Date: Mon, 17 Jun 2024 16:00:39 +0800 Subject: [PATCH 3/4] Fix normalizedType Signed-off-by: tonykwok1992 --- .../codegen/SolidityFunctionWrapper.java | 44 ++++++++----------- .../core/methods/response/AbiDefinition.java | 11 ----- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java b/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java index 2eeddf4e6..0559fca03 100644 --- a/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java +++ b/codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java @@ -587,10 +587,6 @@ private List buildStructTypes(final List functionDefini private static String getStructName(String internalType) { final String fullStructName = internalType.substring(internalType.lastIndexOf(" ") + 1); String tempStructName = fullStructName.substring(fullStructName.lastIndexOf(".") + 1); - int arrayPos = tempStructName.indexOf("["); - if (arrayPos > -1) { - tempStructName = tempStructName.substring(0, arrayPos); - } final String structName = SourceVersion.isName(tempStructName) ? tempStructName : "_" + tempStructName; return structName; @@ -611,6 +607,7 @@ private String adjustToNativeTypeIfNecessary(NamedType component) { } private NamedType normalizeNamedType(NamedType namedType) { + // dynamic array if (namedType.getType().endsWith("[]") && namedType.getInternalType().endsWith("[]")) { return new NamedType( namedType.getName(), @@ -620,6 +617,18 @@ private NamedType normalizeNamedType(NamedType namedType) { .getInternalType() .substring(0, namedType.getInternalType().length() - 2), namedType.isIndexed()); + } else if (namedType.getType().startsWith("tuple[") + && namedType.getInternalType().contains("[") + && namedType.getInternalType().endsWith("]")) { // static array + + return new NamedType( + namedType.getName(), + namedType.getType().substring(0, namedType.getType().indexOf("[")), + namedType.getComponents(), + namedType + .getInternalType() + .substring(0, namedType.getInternalType().indexOf("[")), + namedType.isIndexed()); } else { return namedType; } @@ -637,38 +646,21 @@ private List extractStructs( parameters.addAll(definition.getOutputs()); return parameters.stream() .map(this::normalizeNamedType) - .filter(namedType -> namedType.getType().startsWith("tuple")); + .filter(namedType -> namedType.getType().equals("tuple")); }) .forEach( namedType -> { - if (namedType.getType().startsWith("tuple[")) { - structMap.putIfAbsent( - namedType.flattenNamedType().structIdentifier(), namedType); - } else { - structMap.put(namedType.structIdentifier(), namedType); - } - + structMap.put(namedType.structIdentifier(), namedType); extractNested(namedType).stream() .map(this::normalizeNamedType) .filter( nestedNamedStruct -> - nestedNamedStruct.getType().startsWith("tuple")) + nestedNamedStruct.getType().equals("tuple")) .forEach( - nestedNamedType -> { - if (nestedNamedType - .getType() - .startsWith("tuple[")) { - structMap.putIfAbsent( - nestedNamedType - .flattenNamedType() - .structIdentifier(), - nestedNamedType); - } else { + nestedNamedType -> structMap.put( nestedNamedType.structIdentifier(), - nestedNamedType); - } - }); + nestedNamedType)); }); return structMap.values().stream() diff --git a/core/src/main/java/org/web3j/protocol/core/methods/response/AbiDefinition.java b/core/src/main/java/org/web3j/protocol/core/methods/response/AbiDefinition.java index 12f17d830..e13d61295 100644 --- a/core/src/main/java/org/web3j/protocol/core/methods/response/AbiDefinition.java +++ b/core/src/main/java/org/web3j/protocol/core/methods/response/AbiDefinition.java @@ -298,17 +298,6 @@ public boolean isDynamic() { return components.stream().anyMatch(NamedType::isDynamic); } - public NamedType flattenNamedType() { - int arrayPos = this.type.indexOf("["); - if(arrayPos > 0) return new NamedType( - this.name, - this.type.substring(0, arrayPos), - this.components, - this.internalType.substring(0, this.internalType.indexOf("[")), - this.indexed); - return this; - } - @Override public boolean equals(Object o) { if (this == o) { From a77cc2b00882f7070570af000a0c3f783dc028a4 Mon Sep 17 00:00:00 2001 From: tonykwok1992 Date: Mon, 17 Jun 2024 16:25:26 +0800 Subject: [PATCH 4/4] Add test for fixing more issue Signed-off-by: tonykwok1992 --- .../SolidityFunctionWrapperGeneratorTest.java | 11 ++ .../StaticArrayOfStructsInStruct.sol | 19 ++ .../build/StaticArrayOfStructsInStruct.abi | 1 + .../build/StaticArrayOfStructsInStruct.bin | 1 + .../java/StaticArrayOfStructsInStruct.java | 167 ++++++++++++++++++ 5 files changed, 199 insertions(+) create mode 100644 codegen/src/test/resources/solidity/staticarrayofstructsinstruct/StaticArrayOfStructsInStruct.sol create mode 100644 codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/StaticArrayOfStructsInStruct.abi create mode 100644 codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/StaticArrayOfStructsInStruct.bin create mode 100644 codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/java/StaticArrayOfStructsInStruct.java diff --git a/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java b/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java index 605bc45db..ddbefe684 100644 --- a/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java +++ b/codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java @@ -243,6 +243,17 @@ public void testArrayOfStructAndStructCompareJavaFile() throws Exception { compareJavaFile("ArrayOfStructAndStruct", true); } + @Test + public void testStaticArrayOfStructsInStructGeneration() throws Exception { + testCodeGeneration( + "staticarrayofstructsinstruct", "StaticArrayOfStructsInStruct", JAVA_TYPES_ARG, false); + } + + @Test + public void testStaticArrayOfStructsInStructGenerationCompareJavaFile() throws Exception { + compareJavaFile("StaticArrayOfStructsInStruct", true); + } + private void compareJavaFile(String inputFileName, boolean useBin) throws Exception { String contract = inputFileName.toLowerCase(); String packagePath = diff --git a/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/StaticArrayOfStructsInStruct.sol b/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/StaticArrayOfStructsInStruct.sol new file mode 100644 index 000000000..439f2f9e4 --- /dev/null +++ b/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/StaticArrayOfStructsInStruct.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + + +contract StaticArrayOfStructsInStruct { + + struct Player { + address addr; + uint256 timeLeft; + } + struct Config{ + uint64 index; + Player[2] players; + } + + function test(Config calldata config) external { + revert(); + } +} diff --git a/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/StaticArrayOfStructsInStruct.abi b/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/StaticArrayOfStructsInStruct.abi new file mode 100644 index 000000000..7df02f132 --- /dev/null +++ b/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/StaticArrayOfStructsInStruct.abi @@ -0,0 +1 @@ +[{"inputs":[{"components":[{"internalType":"uint64","name":"index","type":"uint64"},{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"timeLeft","type":"uint256"}],"internalType":"struct StaticArrayOfStructsInStruct.Player[2]","name":"players","type":"tuple[2]"}],"internalType":"struct StaticArrayOfStructsInStruct.Config","name":"config","type":"tuple"}],"name":"test","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/StaticArrayOfStructsInStruct.bin b/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/StaticArrayOfStructsInStruct.bin new file mode 100644 index 000000000..465f012b8 --- /dev/null +++ b/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/StaticArrayOfStructsInStruct.bin @@ -0,0 +1 @@ +608060405234801561000f575f80fd5b5060c58061001c5f395ff3fe6080604052348015600e575f80fd5b50600436106026575f3560e01c80639acc3bf114602a575b5f80fd5b60406004803603810190603c91906069565b6042565b005b5f80fd5b5f80fd5b5f80fd5b5f60a08284031215606057605f604a565b5b81905092915050565b5f60a08284031215607b57607a6046565b5b5f608684828501604e565b9150509291505056fea2646970667358221220a67d48af17079065cb181167be61364e31cd9d588c89b4a1ca7ceb1a9bf640a864736f6c63430008140033 \ No newline at end of file diff --git a/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/java/StaticArrayOfStructsInStruct.java b/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/java/StaticArrayOfStructsInStruct.java new file mode 100644 index 000000000..416052448 --- /dev/null +++ b/codegen/src/test/resources/solidity/staticarrayofstructsinstruct/build/java/StaticArrayOfStructsInStruct.java @@ -0,0 +1,167 @@ +package org.web3j.unittests.java; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.web3j.abi.TypeReference; +import org.web3j.abi.datatypes.Address; +import org.web3j.abi.datatypes.Function; +import org.web3j.abi.datatypes.StaticStruct; +import org.web3j.abi.datatypes.Type; +import org.web3j.abi.datatypes.generated.StaticArray2; +import org.web3j.abi.datatypes.generated.Uint256; +import org.web3j.abi.datatypes.generated.Uint64; +import org.web3j.abi.datatypes.reflection.Parameterized; +import org.web3j.crypto.Credentials; +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.RemoteCall; +import org.web3j.protocol.core.RemoteFunctionCall; +import org.web3j.protocol.core.methods.response.TransactionReceipt; +import org.web3j.tx.Contract; +import org.web3j.tx.TransactionManager; +import org.web3j.tx.gas.ContractGasProvider; + +/** + *

Auto generated code. + *

Do not modify! + *

Please use the web3j command line tools, + * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the + * codegen module to update. + * + *

Generated with web3j version none. + */ +@SuppressWarnings("rawtypes") +public class StaticArrayOfStructsInStruct extends Contract { + public static final String BINARY = "608060405234801561000f575f80fd5b5060c58061001c5f395ff3fe6080604052348015600e575f80fd5b50600436106026575f3560e01c80639acc3bf114602a575b5f80fd5b60406004803603810190603c91906069565b6042565b005b5f80fd5b5f80fd5b5f80fd5b5f60a08284031215606057605f604a565b5b81905092915050565b5f60a08284031215607b57607a6046565b5b5f608684828501604e565b9150509291505056fea2646970667358221220a67d48af17079065cb181167be61364e31cd9d588c89b4a1ca7ceb1a9bf640a864736f6c63430008140033"; + + private static String librariesLinkedBinary; + + public static final String FUNC_TEST = "test"; + + @Deprecated + protected StaticArrayOfStructsInStruct(String contractAddress, Web3j web3j, + Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + protected StaticArrayOfStructsInStruct(String contractAddress, Web3j web3j, + Credentials credentials, ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, credentials, contractGasProvider); + } + + @Deprecated + protected StaticArrayOfStructsInStruct(String contractAddress, Web3j web3j, + TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + protected StaticArrayOfStructsInStruct(String contractAddress, Web3j web3j, + TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); + } + + public RemoteFunctionCall test(Config config) { + final Function function = new Function( + FUNC_TEST, + Arrays.asList(config), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + @Deprecated + public static StaticArrayOfStructsInStruct load(String contractAddress, Web3j web3j, + Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return new StaticArrayOfStructsInStruct(contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + @Deprecated + public static StaticArrayOfStructsInStruct load(String contractAddress, Web3j web3j, + TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + return new StaticArrayOfStructsInStruct(contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + public static StaticArrayOfStructsInStruct load(String contractAddress, Web3j web3j, + Credentials credentials, ContractGasProvider contractGasProvider) { + return new StaticArrayOfStructsInStruct(contractAddress, web3j, credentials, contractGasProvider); + } + + public static StaticArrayOfStructsInStruct load(String contractAddress, Web3j web3j, + TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return new StaticArrayOfStructsInStruct(contractAddress, web3j, transactionManager, contractGasProvider); + } + + public static RemoteCall deploy(Web3j web3j, + Credentials credentials, ContractGasProvider contractGasProvider) { + return deployRemoteCall(StaticArrayOfStructsInStruct.class, web3j, credentials, contractGasProvider, getDeploymentBinary(), ""); + } + + @Deprecated + public static RemoteCall deploy(Web3j web3j, + Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return deployRemoteCall(StaticArrayOfStructsInStruct.class, web3j, credentials, gasPrice, gasLimit, getDeploymentBinary(), ""); + } + + public static RemoteCall deploy(Web3j web3j, + TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return deployRemoteCall(StaticArrayOfStructsInStruct.class, web3j, transactionManager, contractGasProvider, getDeploymentBinary(), ""); + } + + @Deprecated + public static RemoteCall deploy(Web3j web3j, + TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + return deployRemoteCall(StaticArrayOfStructsInStruct.class, web3j, transactionManager, gasPrice, gasLimit, getDeploymentBinary(), ""); + } + + public static void linkLibraries(List references) { + librariesLinkedBinary = linkBinaryWithReferences(BINARY, references); + } + + private static String getDeploymentBinary() { + if (librariesLinkedBinary != null) { + return librariesLinkedBinary; + } else { + return BINARY; + } + } + + public static class Player extends StaticStruct { + public String addr; + + public BigInteger timeLeft; + + public Player(String addr, BigInteger timeLeft) { + super(new org.web3j.abi.datatypes.Address(160, addr), + new org.web3j.abi.datatypes.generated.Uint256(timeLeft)); + this.addr = addr; + this.timeLeft = timeLeft; + } + + public Player(Address addr, Uint256 timeLeft) { + super(addr, timeLeft); + this.addr = addr.getValue(); + this.timeLeft = timeLeft.getValue(); + } + } + + public static class Config extends StaticStruct { + public BigInteger index; + + public List players; + + public Config(BigInteger index, List players) { + super(new org.web3j.abi.datatypes.generated.Uint64(index), + new org.web3j.abi.datatypes.generated.StaticArray2(Player.class, players)); + this.index = index; + this.players = players; + } + + public Config(Uint64 index, + @Parameterized(type = Player.class) StaticArray2 players) { + super(index, players); + this.index = index.getValue(); + this.players = players.getValue(); + } + } +} +