Search in sources :

Example 26 with TypeReference

use of org.fisco.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.

the class TransactionDecoder method decodeOutputReturnObject.

/**
 * @param input
 * @param output
 * @return
 * @throws BaseException
 */
public InputAndOutputResult decodeOutputReturnObject(String input, String output) throws BaseException {
    String updatedInput = addHexPrefixToString(input);
    String updatedOutput = addHexPrefixToString(output);
    // select abi
    AbiDefinition abiDefinition = selectAbiDefinition(updatedInput);
    // decode output
    List<NamedType> outputTypes = abiDefinition.getOutputs();
    List<TypeReference<?>> outputTypeReference = ContractAbiUtil.paramFormat(outputTypes);
    Function function = new Function(abiDefinition.getName(), null, outputTypeReference);
    List<Type> resultType = FunctionReturnDecoder.decode(updatedOutput, function.getOutputParameters());
    // set result to java bean
    List<ResultEntity> resultList = new ArrayList<>();
    for (int i = 0; i < outputTypes.size(); i++) {
        resultList.add(new ResultEntity(outputTypes.get(i).getName(), outputTypes.get(i).getType(), resultType.get(i)));
    }
    String methodSign = decodeMethodSign(abiDefinition);
    return new InputAndOutputResult(methodSign, FunctionEncoder.buildMethodId(methodSign), resultList);
}
Also used : NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) ArrayList(java.util.ArrayList) Function(org.fisco.bcos.web3j.abi.datatypes.Function) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Example 27 with TypeReference

use of org.fisco.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.

the class TransactionDecoder method decodeInputReturnObject.

/**
 * @param input
 * @return
 * @throws BaseException
 */
public InputAndOutputResult decodeInputReturnObject(String input) throws BaseException {
    String updatedInput = addHexPrefixToString(input);
    // select abi
    AbiDefinition abiDefinition = selectAbiDefinition(updatedInput);
    // decode input
    List<NamedType> inputTypes = abiDefinition.getInputs();
    List<TypeReference<?>> inputTypeReferences = ContractAbiUtil.paramFormat(inputTypes);
    Function function = new Function(abiDefinition.getName(), null, inputTypeReferences);
    List<Type> resultType = FunctionReturnDecoder.decode(updatedInput.substring(10), function.getOutputParameters());
    // set result to java bean
    List<ResultEntity> resultList = new ArrayList<ResultEntity>();
    for (int i = 0; i < inputTypes.size(); i++) {
        resultList.add(new ResultEntity(inputTypes.get(i).getName(), inputTypes.get(i).getType(), resultType.get(i)));
    }
    String methodSign = decodeMethodSign(abiDefinition);
    return new InputAndOutputResult(methodSign, FunctionEncoder.buildMethodId(methodSign), resultList);
}
Also used : NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) ArrayList(java.util.ArrayList) Function(org.fisco.bcos.web3j.abi.datatypes.Function) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Example 28 with TypeReference

use of org.fisco.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.

the class Contract method staticExtractEventParameters.

public static EventValues staticExtractEventParameters(Event event, Log log) {
    List<String> topics = log.getTopics();
    String encodedEventSignature = EventEncoder.encode(event);
    if (!topics.get(0).equals(encodedEventSignature)) {
        return null;
    }
    List<Type> indexedValues = new ArrayList<>();
    List<Type> nonIndexedValues = FunctionReturnDecoder.decode(log.getData(), event.getNonIndexedParameters());
    List<TypeReference<Type>> indexedParameters = event.getIndexedParameters();
    for (int i = 0; i < indexedParameters.size(); i++) {
        Type value = FunctionReturnDecoder.decodeIndexedValue(topics.get(i + 1), indexedParameters.get(i));
        indexedValues.add(value);
    }
    return new EventValues(indexedValues, nonIndexedValues);
}
Also used : EventValues(org.fisco.bcos.web3j.abi.EventValues) Type(org.fisco.bcos.web3j.abi.datatypes.Type) ArrayList(java.util.ArrayList) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Example 29 with TypeReference

use of org.fisco.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.

the class EvidenceVerify method getInsertEvidenceInput.

public Tuple8<String, String, String, String, byte[], BigInteger, byte[], byte[]> getInsertEvidenceInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_INSERTEVIDENCE, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
    }, new TypeReference<Utf8String>() {
    }, new TypeReference<Utf8String>() {
    }, new TypeReference<Address>() {
    }, new TypeReference<Bytes32>() {
    }, new TypeReference<Uint8>() {
    }, new TypeReference<Bytes32>() {
    }, new TypeReference<Bytes32>() {
    }));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple8<String, String, String, String, byte[], BigInteger, byte[], byte[]>((String) results.get(0).getValue(), (String) results.get(1).getValue(), (String) results.get(2).getValue(), (String) results.get(3).getValue(), (byte[]) results.get(4).getValue(), (BigInteger) results.get(5).getValue(), (byte[]) results.get(6).getValue(), (byte[]) results.get(7).getValue());
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) EncryptType(org.fisco.bcos.web3j.crypto.EncryptType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) TypeReference(org.fisco.bcos.web3j.abi.TypeReference) Tuple8(org.fisco.bcos.web3j.tuples.generated.Tuple8)

Example 30 with TypeReference

use of org.fisco.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.

the class Ok method getTransInput.

public Tuple1<BigInteger> getTransInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_TRANS, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
    }));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<BigInteger>((BigInteger) results.get(0).getValue());
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) EncryptType(org.fisco.bcos.web3j.crypto.EncryptType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Tuple1(org.fisco.bcos.web3j.tuples.generated.Tuple1) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Aggregations

TypeReference (org.fisco.bcos.web3j.abi.TypeReference)47 Type (org.fisco.bcos.web3j.abi.datatypes.Type)45 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)42 Function (org.fisco.bcos.web3j.abi.datatypes.Function)38 Tuple1 (org.fisco.bcos.web3j.tuples.generated.Tuple1)26 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)11 Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)10 ArrayList (java.util.ArrayList)9 NamedType (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType)9 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)8 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)8 Bytes32 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32)8 Address (org.fisco.bcos.web3j.abi.datatypes.Address)7 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)7 Test (org.junit.Test)7 Event (org.fisco.bcos.web3j.abi.datatypes.Event)6 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)6 Tuple2 (org.fisco.bcos.web3j.tuples.generated.Tuple2)6 List (java.util.List)5 DynamicArray (org.fisco.bcos.web3j.abi.datatypes.DynamicArray)5