org.fisco.bcos.web3j.abi.EventValues Java Examples

The following examples show how to use org.fisco.bcos.web3j.abi.EventValues. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbiUtil.java    From WeBASE-Front with Apache License 2.0 6 votes vote down vote up
/**
 * receiptParse.
 * 
 * @param receipt info
 * @param abiList info
 * @return
 */
public static Object receiptParse(TransactionReceipt receipt, List<AbiDefinition> abiList)
    throws FrontException {
    Map<String, Object> resultMap = new HashMap<>();
    List<Log> logList = receipt.getLogs();
    for (AbiDefinition abiDefinition : abiList) {
        String eventName = abiDefinition.getName();
        List<String> funcInputTypes = getFuncInputType(abiDefinition);
        List<TypeReference<?>> finalOutputs = outputFormat(funcInputTypes);
        Event event = new Event(eventName,finalOutputs);
        Object result = null;
        for (Log logInfo : logList) {
            EventValues eventValues = Contract.staticExtractEventParameters(event, logInfo);
            if (eventValues != null) {
                result = callResultParse(funcInputTypes, eventValues.getNonIndexedValues());
                break;
            }
        }
        if (result != null) {
            resultMap.put(eventName, result);
        }
    }
    return resultMap;
}
 
Example #2
Source File: ContractAbiUtil.java    From WeBASE-Transaction with Apache License 2.0 6 votes vote down vote up
/**
 * receiptParse.
 * 
 * @param receipt info
 * @param abiList info
 * @return
 */
public static Object receiptParse(TransactionReceipt receipt, List<AbiDefinition> abiList)
        throws BaseException {
    Map<String, Object> resultMap = new HashMap<>();
    List<Log> logList = receipt.getLogs();
    for (AbiDefinition abiDefinition : abiList) {
        String eventName = abiDefinition.getName();
        List<String> funcInputTypes = getFuncInputType(abiDefinition);
        List<TypeReference<?>> finalOutputs = outputFormat(funcInputTypes);
        Event event = new Event(eventName, finalOutputs);
        Object result = null;
        for (Log logInfo : logList) {
            EventValues eventValues = Contract.staticExtractEventParameters(event, logInfo);
            if (eventValues != null) {
                result = callResultParse(funcInputTypes, eventValues.getNonIndexedValues());
                break;
            }
        }
        if (result != null) {
            resultMap.put(eventName, result);
        }
    }
    return resultMap;
}
 
Example #3
Source File: Contract.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
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);
    }
 
Example #4
Source File: ContractAbiUtil.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example #5
Source File: Contract.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
protected List<EventValues> extractEventParameters(
        Event event, TransactionReceipt transactionReceipt) {
    return transactionReceipt
            .getLogs()
            .stream()
            .map(log -> extractEventParameters(event, log))
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example #6
Source File: Contract.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
protected EventValues extractEventParameters(Event event, Log log) {
    return staticExtractEventParameters(event, log);
}
 
Example #7
Source File: Contract.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
protected EventValuesWithLog extractEventParametersWithLog(Event event, Log log) {
    final EventValues eventValues = staticExtractEventParameters(event, log);
    return (eventValues == null) ? null : new EventValuesWithLog(eventValues, log);
}
 
Example #8
Source File: Contract.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private EventValuesWithLog(EventValues eventValues, Log log) {
    this.eventValues = eventValues;
    this.log = log;
}