Here is my contract:
pragma solidity ^0.4.17;
contract SignVerify {
function recoverAddr(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (address) {
return ecrecover(msgHash, v, r, s);
}
function isSigned(address _addr, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (bool) {
return ecrecover(msgHash, v, r, s) == _addr;
}
}
The corresponding java code generated by web3j (version 3.2.0) contains the following generated method for isSigned
.
public RemoteCall<TransactionReceipt> isSigned(String _addr, byte[] msgHash, BigInteger v, byte[] r, byte[] s) {
Function function = new Function(
"isSigned",
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_addr),
new org.web3j.abi.datatypes.generated.Bytes32(msgHash),
new org.web3j.abi.datatypes.generated.Uint8(v),
new org.web3j.abi.datatypes.generated.Bytes32(r),
new org.web3j.abi.datatypes.generated.Bytes32(s)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
Notice the Collections.<TypeReference<?>>emptyList()
? that is the output return types. Why is it an empty list?
In the well known Greeter example which returns a string that line becomes
Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {})
.
The web3j script to generate java code is pretty straight forward:
web3j solidity generate \
${dirName}/build/${fileName}.bin \
${dirName}/build/${fileName}.abi \
-p org.web3j.sample.contracts.generated \
-o ../../java/ > /dev/null
I tried using --javaTypes
and --solidtyTypes
with no change to generated code. My suspicion now is that web3j only generates return types for constant
functions on the contract.
Let me know if I can somehow get the return type(the boolean) from the TransactionReceipt
returned by the generated java method.