use of org.fisco.bcos.web3j.abi.EventValues 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.abi.EventValues 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.EventValues 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;
}
use of org.fisco.bcos.web3j.abi.EventValues in project web3sdk by FISCO-BCOS.
the class ContractAbiUtil method decodeEvent.
/**
* @param log
* @param abiDefinition
* @return
* @throws BaseException
*/
public static EventValues decodeEvent(Log log, AbiDefinition abiDefinition) throws BaseException {
List<TypeReference<?>> finalOutputs = paramFormat(abiDefinition.getInputs());
Event event = new Event(abiDefinition.getName(), finalOutputs);
EventValues eventValues = Contract.staticExtractEventParameters(event, log);
return eventValues;
}
Aggregations