use of org.fisco.bcos.web3j.protocol.core.methods.response.Call in project web3sdk by FISCO-BCOS.
the class CallContract method call.
public CallResult call(String contractAddress, String funcName, Type... args) {
final Function function = new Function(funcName, Arrays.<Type>asList(args), Collections.<TypeReference<?>>emptyList());
String data = FunctionEncoder.encode(function);
Call ethCall;
try {
ethCall = web3j.call(Transaction.createEthCallTransaction(credentials.getAddress(), contractAddress, data), DefaultBlockParameterName.LATEST).send();
} catch (Exception e) {
return new CallResult(StatusCode.ExceptionCatched, e.getMessage(), "0x");
}
Call.CallOutput callOutput = ethCall.getValue();
if (callOutput != null) {
return new CallResult(callOutput.getStatus(), StatusCode.getStatusMessage(callOutput.getStatus()), callOutput.getOutput());
} else {
return new CallResult(StatusCode.ErrorInRPC, StatusCode.getStatusMessage(StatusCode.ErrorInRPC), "0x");
}
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.Call in project web3sdk by FISCO-BCOS.
the class Contract method executeCall.
/**
* Execute constant function call - i.e. a call that does not change state of the contract
*
* @param function to call
* @return {@link List} of values returned by function call
*/
private List<Type> executeCall(Function function) throws IOException {
String encodedFunction = FunctionEncoder.encode(function);
Call ethCall = web3j.call(Transaction.createEthCallTransaction(transactionManager.getFromAddress(), contractAddress, encodedFunction), defaultBlockParameter).send();
String value = ethCall.getValue().getOutput();
return FunctionReturnDecoder.decode(value, function.getOutputParameters());
}
Aggregations