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