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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations