Search in sources :

Example 31 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type 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 32 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type 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 33 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type 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 34 with Type

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

the class RevertResolver method tryResolveRevertMessage.

/**
 * @param status
 * @param output
 * @return
 */
public static Tuple2<Boolean, String> tryResolveRevertMessage(String status, String output) {
    if (!hasRevertMessage(status, output)) {
        return new Tuple2<>(false, null);
    }
    try {
        // 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030497373756572526f6c653a2063616c6c657220646f6573206e6f742068617665207468652049737375657220726f6c6500000000000000000000000000000000
        String rawOutput = Numeric.containsHexPrefix(output) ? output.substring(RevertMethodWithHexPrefix.length()) : output.substring(RevertMethod.length());
        List<Type> result = FunctionReturnDecoder.decode(rawOutput, revertFunction.getOutputParameters());
        if (result.get(0) instanceof Utf8String) {
            String message = ((Utf8String) result.get(0)).getValue();
            if (logger.isDebugEnabled()) {
                logger.debug(" ABI: {} , RevertMessage: {}", output, message);
            }
            return new Tuple2<>(true, message);
        }
    } catch (Exception e) {
        logger.warn(" ABI: {}, e: {}", output, e);
    }
    return new Tuple2<>(false, null);
}
Also used : Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Tuple2(org.fisco.bcos.web3j.tuples.generated.Tuple2) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 35 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type 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)

Aggregations

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