Search in sources :

Example 1 with Function

use of org.web3j.abi.datatypes.Function in project jbpm-work-items by kiegroup.

the class EthereumUtils method queryExistingContract.

public static Object queryExistingContract(Credentials credentials, Web3j web3j, String contractAddress, String contractMethodName, List<Type> contractMethodInputTypes, List<TypeReference<?>> contractMethodOutputTypes) throws Exception {
    Function function = getFunction(contractMethodName, contractMethodInputTypes, contractMethodOutputTypes);
    Transaction transaction = Transaction.createEthCallTransaction(credentials.getAddress(), contractAddress, getEncodedFunction(function));
    EthCall response = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).sendAsync().get();
    List<Type> responseTypeList = FunctionReturnDecoder.decode(response.getValue(), function.getOutputParameters());
    if (responseTypeList != null && responseTypeList.size() > 0) {
        return responseTypeList.get(0).getValue();
    } else {
        return null;
    }
}
Also used : Function(org.web3j.abi.datatypes.Function) Type(org.web3j.abi.datatypes.Type) Transaction(org.web3j.protocol.core.methods.request.Transaction) RawTransaction(org.web3j.crypto.RawTransaction) EthSendTransaction(org.web3j.protocol.core.methods.response.EthSendTransaction) EthCall(org.web3j.protocol.core.methods.response.EthCall)

Example 2 with Function

use of org.web3j.abi.datatypes.Function in project jbpm-work-items by kiegroup.

the class EthereumUtils method getFunction.

public static Function getFunction(String queryName, List<Type> queryInputTypes, List<TypeReference<?>> queryOutputTypes) {
    List<Type> inputParameters;
    if (queryInputTypes != null) {
        inputParameters = queryInputTypes;
    } else {
        inputParameters = new ArrayList<>();
    }
    List<TypeReference<?>> outputTypes;
    if (queryOutputTypes != null) {
        outputTypes = queryOutputTypes;
    } else {
        outputTypes = new ArrayList<>();
    }
    Function function = new Function(queryName, inputParameters, outputTypes);
    return function;
}
Also used : Function(org.web3j.abi.datatypes.Function) Type(org.web3j.abi.datatypes.Type) TypeReference(org.web3j.abi.TypeReference)

Aggregations

Function (org.web3j.abi.datatypes.Function)2 Type (org.web3j.abi.datatypes.Type)2 TypeReference (org.web3j.abi.TypeReference)1 RawTransaction (org.web3j.crypto.RawTransaction)1 Transaction (org.web3j.protocol.core.methods.request.Transaction)1 EthCall (org.web3j.protocol.core.methods.response.EthCall)1 EthSendTransaction (org.web3j.protocol.core.methods.response.EthSendTransaction)1