use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildParameterTypes.
static List<ParameterSpec> buildParameterTypes(List<AbiDefinition.NamedType> namedTypes) {
List<ParameterSpec> result = new ArrayList<>(namedTypes.size());
for (int i = 0; i < namedTypes.size(); i++) {
AbiDefinition.NamedType namedType = namedTypes.get(i);
String name = createValidParamName(namedType.getName(), i);
String type = namedTypes.get(i).getType();
namedType.setName(name);
result.add(ParameterSpec.builder(buildTypeName(type), name).build());
}
return result;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method getInputOutputFunctionName.
public static String getInputOutputFunctionName(AbiDefinition functionDefinition, boolean isOverLoad) {
if (!isOverLoad) {
return functionDefinition.getName();
}
List<NamedType> nameTypes = functionDefinition.getInputs();
String name = functionDefinition.getName();
for (int i = 0; i < nameTypes.size(); i++) {
AbiDefinition.NamedType.Type type = new AbiDefinition.NamedType.Type(nameTypes.get(i).getType());
name += Strings.capitaliseFirstLetter(type.getBaseName());
List<Integer> depths = type.getDepthArray();
for (int j = 0; j < depths.size(); j++) {
name += "Array";
if (0 != depths.get(j)) {
name += String.valueOf(depths.get(j));
}
}
}
if (logger.isDebugEnabled()) {
logger.debug(" name: {}, nameTypes: {}", name, nameTypes);
}
return name;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildEventFunctions.
List<MethodSpec> buildEventFunctions(AbiDefinition functionDefinition, TypeSpec.Builder classBuilder) throws ClassNotFoundException {
String functionName = functionDefinition.getName();
List<AbiDefinition.NamedType> inputs = functionDefinition.getInputs();
String responseClassName = Strings.capitaliseFirstLetter(functionName) + "EventResponse";
List<NamedTypeName> parameters = new ArrayList<>();
List<NamedTypeName> indexedParameters = new ArrayList<>();
List<NamedTypeName> nonIndexedParameters = new ArrayList<>();
for (AbiDefinition.NamedType namedType : inputs) {
NamedTypeName parameter = new NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()), namedType.isIndexed());
if (namedType.isIndexed()) {
indexedParameters.add(parameter);
} else {
nonIndexedParameters.add(parameter);
}
parameters.add(parameter);
}
classBuilder.addField(createEventDefinition(functionName, parameters));
classBuilder.addType(buildEventResponseObject(responseClassName, indexedParameters, nonIndexedParameters));
List<MethodSpec> methods = new ArrayList<>();
methods.add(buildEventTransactionReceiptFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters));
methods.add(buildRegisterEventLogPushFunction(functionName));
methods.add(buildDefaultRegisterEventLogPushFunction(functionName));
return methods;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.
the class TransactionDecoderTest method decodeMethodSign.
private static String decodeMethodSign(AbiDefinition abiDefinition) {
List<NamedType> inputTypes = abiDefinition.getInputs();
StringBuilder methodSign = new StringBuilder();
methodSign.append(abiDefinition.getName());
methodSign.append("(");
String params = inputTypes.stream().map(NamedType::getType).collect(Collectors.joining(","));
methodSign.append(params);
methodSign.append(")");
return methodSign.toString();
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType 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);
}
Aggregations