use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType 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.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.
the class TransactionDecoder method decodeEventLogReturnObject.
/**
* @param log
* @return LogResult
* @throws BaseException
*/
public LogResult decodeEventLogReturnObject(Log log) throws BaseException {
// decode log
List<AbiDefinition> abiDefinitions = ContractAbiUtil.getEventAbiDefinitions(abi);
LogResult result = new LogResult();
for (AbiDefinition abiDefinition : abiDefinitions) {
// String eventName = decodeMethodSign(abiDefinition);
String eventSignature = EventEncoder.buildEventSignature(decodeMethodSign(abiDefinition));
List<String> topics = log.getTopics();
if ((null == topics) || topics.isEmpty() || !topics.get(0).equals(eventSignature)) {
continue;
}
EventValues eventValued = ContractAbiUtil.decodeEvent(log, abiDefinition);
if (null != eventValued) {
List<EventResultEntity> resultEntityList = new ArrayList<EventResultEntity>();
List<NamedType> inputs = abiDefinition.getInputs();
List<NamedType> indexedInputs = inputs.stream().filter(NamedType::isIndexed).collect(Collectors.toList());
List<NamedType> nonIndexedInputs = inputs.stream().filter(p -> !p.isIndexed()).collect(Collectors.toList());
for (int i = 0; i < indexedInputs.size(); i++) {
EventResultEntity eventEntity = new EventResultEntity(indexedInputs.get(i).getName(), indexedInputs.get(i).getType(), true, eventValued.getIndexedValues().get(i));
resultEntityList.add(eventEntity);
}
for (int i = 0; i < nonIndexedInputs.size(); i++) {
EventResultEntity eventEntity = new EventResultEntity(nonIndexedInputs.get(i).getName(), nonIndexedInputs.get(i).getType(), false, eventValued.getNonIndexedValues().get(i));
resultEntityList.add(eventEntity);
}
// result.setEventName(eventName);
result.setLogParams(resultEntityList);
result.setLog(log);
logger.debug(" event log result: {}", result);
return result;
}
}
return null;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.
the class ContractAbiUtil method getFuncOutputType.
/**
* @param abiDefinition
* @return
*/
public static List<String> getFuncOutputType(AbiDefinition abiDefinition) {
List<String> outputList = new ArrayList<>();
List<NamedType> outputs = abiDefinition.getOutputs();
for (NamedType output : outputs) {
outputList.add(output.getType());
}
return outputList;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method createMappedParameterTypes.
private String createMappedParameterTypes(AbiDefinition.NamedType namedType) {
String name = namedType.getName();
String type = namedType.getType();
AbiDefinition.NamedType.Type innerType = new AbiDefinition.NamedType.Type(type);
ParameterSpec parameterSpec = ParameterSpec.builder(buildTypeName(type), name).build();
if (parameterSpec.type instanceof ParameterizedTypeName) {
List<TypeName> typeNames = ((ParameterizedTypeName) parameterSpec.type).typeArguments;
if (typeNames.size() != 1) {
throw new UnsupportedOperationException("Only a single parameterized type is supported");
} else {
String parameterSpecType = parameterSpec.type.toString();
TypeName typeName = typeNames.get(0);
String typeMapInput = typeName + ".class";
if (typeName instanceof ParameterizedTypeName) {
List<TypeName> typeArguments = ((ParameterizedTypeName) typeName).typeArguments;
if (typeArguments.size() != 1) {
throw new UnsupportedOperationException("Only a single parameterized type is supported");
}
TypeName innerTypeName = typeArguments.get(0);
parameterSpecType = ((ParameterizedTypeName) parameterSpec.type).rawType.toString();
typeMapInput = ((ParameterizedTypeName) typeName).rawType + ".class, " + innerTypeName + ".class";
}
if (innerType.dynamicArray()) {
// dynamic array
return parameterSpec.name + ".isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty" + "(\"" + type + "\"):" + "new " + parameterSpecType + "(\n" + " org.fisco.bcos.web3j.abi.Utils.typeMap(" + parameterSpec.name + ", " + typeMapInput + "))";
} else {
// static array
return "new " + parameterSpecType + "(\n" + " org.fisco.bcos.web3j.abi.Utils.typeMap(" + parameterSpec.name + ", " + typeMapInput + "))";
}
}
} else {
return "new " + parameterSpec.type + "(" + parameterSpec.name + ")";
}
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.
the class TransactionDecoder method decodeEventReturnObject.
public Tuple2<AbiDefinition, List<EventResultEntity>> decodeEventReturnObject(Log log) throws BaseException, IOException {
Tuple2<AbiDefinition, List<EventResultEntity>> result = null;
// decode log
List<AbiDefinition> abiDefinitions = ContractAbiUtil.getEventAbiDefinitions(abi);
for (AbiDefinition abiDefinition : abiDefinitions) {
String eventSignature = EventEncoder.buildEventSignature(decodeMethodSign(abiDefinition));
List<String> topics = log.getTopics();
if ((null == topics) || topics.isEmpty() || !topics.get(0).equals(eventSignature)) {
continue;
}
EventValues eventValued = ContractAbiUtil.decodeEvent(log, abiDefinition);
if (null != eventValued) {
List<EventResultEntity> resultEntityList = new ArrayList<EventResultEntity>();
List<NamedType> inputs = abiDefinition.getInputs();
List<NamedType> indexedInputs = inputs.stream().filter(NamedType::isIndexed).collect(Collectors.toList());
List<NamedType> nonIndexedInputs = inputs.stream().filter(p -> !p.isIndexed()).collect(Collectors.toList());
for (int i = 0; i < indexedInputs.size(); i++) {
EventResultEntity eventEntity = new EventResultEntity(indexedInputs.get(i).getName(), indexedInputs.get(i).getType(), true, eventValued.getIndexedValues().get(i));
resultEntityList.add(eventEntity);
}
for (int i = 0; i < nonIndexedInputs.size(); i++) {
EventResultEntity eventEntity = new EventResultEntity(nonIndexedInputs.get(i).getName(), nonIndexedInputs.get(i).getType(), false, eventValued.getNonIndexedValues().get(i));
resultEntityList.add(eventEntity);
}
result = new Tuple2<AbiDefinition, List<EventResultEntity>>(abiDefinition, resultEntityList);
break;
}
}
return result;
}
Aggregations