Search in sources :

Example 1 with Call

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");
    }
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) Call(org.fisco.bcos.web3j.protocol.core.methods.response.Call) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 2 with Call

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());
}
Also used : RemoteCall(org.fisco.bcos.web3j.protocol.core.RemoteCall) Call(org.fisco.bcos.web3j.protocol.core.methods.response.Call)

Aggregations

Call (org.fisco.bcos.web3j.protocol.core.methods.response.Call)2 Function (org.fisco.bcos.web3j.abi.datatypes.Function)1 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)1 RemoteCall (org.fisco.bcos.web3j.protocol.core.RemoteCall)1