Skip to content

Commit 07633cd

Browse files
tonykwok1992Julius278
authored andcommitted
Make getABI_* calls static (LFDT-web3j#2079)
Signed-off-by: tonykwok1992 <[email protected]> Signed-off-by: Julius Lauterbach <[email protected]>
1 parent 45540b9 commit 07633cd

File tree

6 files changed

+125
-11
lines changed

6 files changed

+125
-11
lines changed

codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ List<MethodSpec> buildFunctions(
15061506
// Create function that returns the ABI encoding of the Solidity function call.
15071507
if (abiFuncs) {
15081508
functionName = "getABI_" + functionName;
1509-
methodBuilder = MethodSpec.methodBuilder(functionName).addModifiers(Modifier.PUBLIC);
1509+
methodBuilder = MethodSpec.methodBuilder(functionName).addModifiers(Modifier.PUBLIC).addModifiers(Modifier.STATIC);
15101510
addParameters(methodBuilder, functionDefinition.getInputs());
15111511
buildAbiFunction(functionDefinition, methodBuilder, inputParams, useUpperCase);
15121512
results.add(methodBuilder.build());

codegen/src/test/java/org/web3j/codegen/SolidityFunctionWrapperGeneratorTest.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ public void testGetFileNoExtension() {
6060
assertEquals("file", getFileNameNoExtension("file.txt"));
6161
}
6262

63+
@Test
64+
public void testAbiFuncsGeneration() throws Exception {
65+
testCodeGeneration(emptyList(),"abifuncs", "AbiFuncs", JAVA_TYPES_ARG, true, false, true);
66+
testCodeGeneration(emptyList(),"abifuncs", "AbiFuncs", SOLIDITY_TYPES_ARG, true, false, true);
67+
}
68+
69+
@Test
70+
public void testAbiFuncsCompareJavaFileTest() throws Exception {
71+
compareJavaFile("AbiFuncs", false, true);
72+
}
73+
6374
@Test
6475
public void testGreeterGeneration() throws Exception {
6576
testCodeGenerationJvmTypes("greeter", "Greeter");
@@ -143,12 +154,12 @@ public void testStructOnlyInArray() throws Exception {
143154

144155
@Test
145156
public void testStructOnlyInArrayCompareJavaFile() throws Exception {
146-
compareJavaFile("OnlyInArrayStruct", false);
157+
compareJavaFile("OnlyInArrayStruct", false, false);
147158
}
148159

149160
@Test
150161
public void testArraysInStructCompareJavaFileTest() throws Exception {
151-
compareJavaFile("ArraysInStruct", false);
162+
compareJavaFile("ArraysInStruct", false, false);
152163
}
153164

154165
@Test
@@ -199,12 +210,12 @@ public void testEventParametersNoNamed() throws Exception {
199210

200211
@Test
201212
public void testEventParametersNoNamedCompareJavaFile() throws Exception {
202-
compareJavaFile("EventParameters", false);
213+
compareJavaFile("EventParameters", false, false);
203214
}
204215

205216
@Test
206217
public void testDeployMethodGenerated() throws Exception {
207-
compareJavaFile("MetaCoin", true);
218+
compareJavaFile("MetaCoin", true, false);
208219
}
209220

210221
@Test
@@ -215,7 +226,7 @@ public void testSameInnerStructName() throws Exception {
215226

216227
@Test
217228
public void testSameInnerStructNameCompareJavaFile() throws Exception {
218-
compareJavaFile("SameInnerStructName", true);
229+
compareJavaFile("SameInnerStructName", true, false);
219230
}
220231

221232
@Test
@@ -229,7 +240,7 @@ public void testArrayOfStructClassGeneration() throws Exception {
229240

230241
@Test
231242
public void testArrayOfStructClassGenerationCompareJavaFile() throws Exception {
232-
compareJavaFile("ArrayOfStructClassGeneration", true);
243+
compareJavaFile("ArrayOfStructClassGeneration", true, false);
233244
}
234245

235246
@Test
@@ -240,7 +251,7 @@ public void testArrayOfStructAndStructGeneration() throws Exception {
240251

241252
@Test
242253
public void testArrayOfStructAndStructCompareJavaFile() throws Exception {
243-
compareJavaFile("ArrayOfStructAndStruct", true);
254+
compareJavaFile("ArrayOfStructAndStruct", true, false);
244255
}
245256

246257
@Test
@@ -251,14 +262,14 @@ public void testStaticArrayOfStructsInStructGeneration() throws Exception {
251262

252263
@Test
253264
public void testStaticArrayOfStructsInStructGenerationCompareJavaFile() throws Exception {
254-
compareJavaFile("StaticArrayOfStructsInStruct", true);
265+
compareJavaFile("StaticArrayOfStructsInStruct", true, false);
255266
}
256267

257-
private void compareJavaFile(String inputFileName, boolean useBin) throws Exception {
268+
private void compareJavaFile(String inputFileName, boolean useBin, boolean abiFuncs) throws Exception {
258269
String contract = inputFileName.toLowerCase();
259270
String packagePath =
260271
generateCode(
261-
emptyList(), contract, inputFileName, JAVA_TYPES_ARG, useBin, false, false);
272+
emptyList(), contract, inputFileName, JAVA_TYPES_ARG, useBin, false, abiFuncs);
262273
File fileActual = new File(tempDirPath, packagePath + "/" + inputFileName + ".java");
263274
File fileExpected =
264275
new File(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pragma solidity >= 0.8.7;
2+
3+
contract AbiFuncs {
4+
5+
6+
function hi(uint256 x) public {
7+
8+
}
9+
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"hi","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
608060405234801561000f575f80fd5b5060d38061001c5f395ff3fe6080604052348015600e575f80fd5b50600436106026575f3560e01c80634cf1b41d14602a575b5f80fd5b60406004803603810190603c91906077565b6042565b005b50565b5f80fd5b5f819050919050565b6059816049565b81146062575f80fd5b50565b5f813590506071816052565b92915050565b5f6020828403121560895760886045565b5b5f6094848285016065565b9150509291505056fea2646970667358221220e788c40f4c54add124e8c2662f9bc92e122a1ea722846a0a855e1ffb68cbdac564736f6c63430008140033
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.web3j.unittests.java;
2+
3+
import java.math.BigInteger;
4+
import java.util.Arrays;
5+
import java.util.Collections;
6+
import org.web3j.abi.TypeReference;
7+
import org.web3j.abi.datatypes.Function;
8+
import org.web3j.abi.datatypes.Type;
9+
import org.web3j.crypto.Credentials;
10+
import org.web3j.protocol.Web3j;
11+
import org.web3j.protocol.core.RemoteFunctionCall;
12+
import org.web3j.protocol.core.methods.response.TransactionReceipt;
13+
import org.web3j.tx.Contract;
14+
import org.web3j.tx.TransactionManager;
15+
import org.web3j.tx.gas.ContractGasProvider;
16+
17+
/**
18+
* <p>Auto generated code.
19+
* <p><strong>Do not modify!</strong>
20+
* <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
21+
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
22+
* <a href="https://github.com/web3j/web3j/tree/main/codegen">codegen module</a> to update.
23+
*
24+
* <p>Generated with web3j version none.
25+
*/
26+
@SuppressWarnings("rawtypes")
27+
public class AbiFuncs extends Contract {
28+
public static final String BINARY = "Bin file was not provided";
29+
30+
public static final String FUNC_HI = "hi";
31+
32+
@Deprecated
33+
protected AbiFuncs(String contractAddress, Web3j web3j, Credentials credentials,
34+
BigInteger gasPrice, BigInteger gasLimit) {
35+
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
36+
}
37+
38+
protected AbiFuncs(String contractAddress, Web3j web3j, Credentials credentials,
39+
ContractGasProvider contractGasProvider) {
40+
super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
41+
}
42+
43+
@Deprecated
44+
protected AbiFuncs(String contractAddress, Web3j web3j, TransactionManager transactionManager,
45+
BigInteger gasPrice, BigInteger gasLimit) {
46+
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
47+
}
48+
49+
protected AbiFuncs(String contractAddress, Web3j web3j, TransactionManager transactionManager,
50+
ContractGasProvider contractGasProvider) {
51+
super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
52+
}
53+
54+
public RemoteFunctionCall<TransactionReceipt> hi(BigInteger x) {
55+
final Function function = new Function(
56+
FUNC_HI,
57+
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(x)),
58+
Collections.<TypeReference<?>>emptyList());
59+
return executeRemoteCallTransaction(function);
60+
}
61+
62+
public static String getABI_hi(BigInteger x) {
63+
final Function function = new Function(
64+
FUNC_HI,
65+
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(x)),
66+
Collections.<TypeReference<?>>emptyList());
67+
return org.web3j.abi.FunctionEncoder.encode(function);
68+
}
69+
70+
@Deprecated
71+
public static AbiFuncs load(String contractAddress, Web3j web3j, Credentials credentials,
72+
BigInteger gasPrice, BigInteger gasLimit) {
73+
return new AbiFuncs(contractAddress, web3j, credentials, gasPrice, gasLimit);
74+
}
75+
76+
@Deprecated
77+
public static AbiFuncs load(String contractAddress, Web3j web3j,
78+
TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
79+
return new AbiFuncs(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
80+
}
81+
82+
public static AbiFuncs load(String contractAddress, Web3j web3j, Credentials credentials,
83+
ContractGasProvider contractGasProvider) {
84+
return new AbiFuncs(contractAddress, web3j, credentials, contractGasProvider);
85+
}
86+
87+
public static AbiFuncs load(String contractAddress, Web3j web3j,
88+
TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
89+
return new AbiFuncs(contractAddress, web3j, transactionManager, contractGasProvider);
90+
}
91+
}

0 commit comments

Comments
 (0)