use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition 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 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 in project web3sdk by FISCO-BCOS.
the class TransactionDecoder method selectAbiDefinition.
/**
* @param input
* @return
* @throws BaseException
*/
private AbiDefinition selectAbiDefinition(String input) throws BaseException {
String methodID = input.substring(0, 10);
AbiDefinition abiDefinition = methodIDMap.get(methodID);
if (abiDefinition == null) {
throw new BaseException(201203, String.format("the method is not found in abi, method id:[%s]", methodID));
}
return abiDefinition;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition in project web3sdk by FISCO-BCOS.
the class ContractAbiUtil method getFuncAbiDefinition.
/**
* @param contractAbi
* @return
*/
public static List<AbiDefinition> getFuncAbiDefinition(String contractAbi) {
List<AbiDefinition> result = new ArrayList<>();
try {
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
AbiDefinition[] abiDefinitions = objectMapper.readValue(contractAbi, AbiDefinition[].class);
for (AbiDefinition abiDefinition : abiDefinitions) {
if (TYPE_FUNCTION.equals(abiDefinition.getType()) || TYPE_CONSTRUCTOR.equals(abiDefinition.getType())) {
result.add(abiDefinition);
}
}
} catch (JsonProcessingException e) {
logger.warn(" invalid json, abi: {}, e: {} ", contractAbi, e);
}
return result;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildDeployMethods.
List<MethodSpec> buildDeployMethods(String className, TypeSpec.Builder classBuilder, List<AbiDefinition> functionDefinitions) {
boolean constructor = false;
List<MethodSpec> methodSpecs = new ArrayList<>();
for (AbiDefinition functionDefinition : functionDefinitions) {
if (functionDefinition.getType().equals("constructor")) {
constructor = true;
methodSpecs.add(buildDeploy(className, functionDefinition, Credentials.class, CREDENTIALS, true));
methodSpecs.add(buildDeploy(className, functionDefinition, TransactionManager.class, TRANSACTION_MANAGER, true));
methodSpecs.add(buildDeploy(className, functionDefinition, Credentials.class, CREDENTIALS, false));
methodSpecs.add(buildDeploy(className, functionDefinition, TransactionManager.class, TRANSACTION_MANAGER, false));
}
}
// constructor will not be specified in ABI file if its empty
if (!constructor) {
MethodSpec.Builder credentialsMethodBuilder = getDeployMethodSpec(className, Credentials.class, CREDENTIALS, true);
methodSpecs.add(buildDeployNoParams(credentialsMethodBuilder, className, CREDENTIALS, true));
MethodSpec.Builder credentialsMethodBuilderNoGasProvider = getDeployMethodSpec(className, Credentials.class, CREDENTIALS, false);
methodSpecs.add(buildDeployNoParams(credentialsMethodBuilderNoGasProvider, className, CREDENTIALS, false));
MethodSpec.Builder transactionManagerMethodBuilder = getDeployMethodSpec(className, TransactionManager.class, TRANSACTION_MANAGER, true);
methodSpecs.add(buildDeployNoParams(transactionManagerMethodBuilder, className, TRANSACTION_MANAGER, true));
MethodSpec.Builder transactionManagerMethodBuilderNoGasProvider = getDeployMethodSpec(className, TransactionManager.class, TRANSACTION_MANAGER, false);
methodSpecs.add(buildDeployNoParams(transactionManagerMethodBuilderNoGasProvider, className, TRANSACTION_MANAGER, false));
}
return methodSpecs;
}
Aggregations