web3j
web3j copied to clipboard
Issue when generate contract java file using web3j.codegen
Issue_title
Issue when generating contract java file using web3j.codegen
Issue_description
Contract file java generated by web3j.codegen error, cannot compile.
java: incompatible types: inference variable T has incompatible bounds
equality constraints: java.util.List
upper bounds: org.web3j.abi.datatypes.Type
Enviroment & Tool
ubuntu 20.04 solc version: 0.8.14+commit.80d49f37.Linux.g++ web3j: core + codegen: 4.8.7
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.8.7</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>codegen</artifactId>
<version>4.8.7</version>
</dependency>
Step
- I use solc to generate abi & bin file from contract.sol. I have a function like
struct ContractInfo {
string contractCode;
uint256 quantity;
}
function getAllContract(address account) public override view returns (IBond.ContractInfo[] memory) {
string[] memory contracts = allAccounts[account].contracts;
IBond.ContractInfo[] memory data = new IBond.ContractInfo[](contracts.length);
for (uint i = 0; i < contracts.length; i++) {
data[i].contractCode = contracts[i];
data[i].quantity = balanceByContractCode[account][contracts[i]];
}
return data;
}
- Then I use a function from codegen to gen java file
SolidityFunctionWrapperGenerator generator = new SolidityFunctionWrapperGenerator(
new File(BIN_FILE), new File(ABI_FILE), new File(DEST_DIR), "Bond",
"middleware.contract", false, true, 20);
try {
generator.generate();
} catch (IOException e) {
logger.info("IOException: {}", e.getMessage());
} catch (ClassNotFoundException e) {
logger.info("ClassNotFoundException: {}", e.getMessage());
}
- The function generated for function getAllContract() in file java like
public RemoteFunctionCall<List> getAllContract(Address account) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_GETALLCONTRACT,
Arrays.<Type>asList(account),
Arrays.<TypeReference<?>>asList(new TypeReference<List<ContractInfo>>() {}));
return executeRemoteCallSingleValueReturn(function);
}
=> I found executeRemoteCallSingleValueReturn
return <T extends Type> RemoteFunctionCall<T>
, but List is a native type of Java, it's not extends from Type.
`
I also encountered this problem. No one knows how to solve it