Parsing Transaction Event Data

The Data Center Operator can call this function to parse the transaction events in the block.


    public <T extends BaseEventBean> void transactionData(BigInteger txTimestamp, List<EthBlock.TransactionResult> transactions, ArrayList<T> arrayList) throws Exception {
    for (EthBlock.TransactionResult<EthBlock.TransactionObject> transactionResult : transactions) {
        EthBlock.TransactionObject transaction = transactionResult.get();
        TransactionReceipt receipt = getTransactionReceipt(transaction.getHash());
        if (Objects.isNull(receipt)) {
            throw new SpartanException(ErrorMessage.IS_EMPTY, "transactionReceipt");
        }
        List<Log> logList = receipt.getLogs();
        for (Log log : logList) {
            // Get the contract for this event
            SpartanContract contract = SpartanContracts.stream().filter(t -> t.getContractAddress().equalsIgnoreCase(log.getAddress())).findAny().orElse(null);
            if (Objects.isNull(contract)) {
                logger.info(String.format("BlockNum:%s,Contract:%s,Non official contracts do not have statistical data...", transaction.getBlockNumber(), log.getAddress()));
                continue;
            }
            // contract info
            String contractAbi = contract.getContractAbi();
            String contractByteCode = contract.getContractBytecode();

            if (Strings.isEmpty(contractAbi) || Strings.isEmpty(contractByteCode)) {
                throw new SpartanException(ErrorMessage.IS_EMPTY, "contract info");
            }

            List<Log> logInfo = new ArrayList<>();
            logInfo.add(log);
            Map<String, List<List<EventResultEntity>>> map = analyzeEventLog(contractAbi, contractByteCode, JSONObject.toJSONString(logInfo));
            // Event to Object
            if (eventBeanMap.isEmpty()) {
                throw new SpartanException(ErrorMessage.IS_EMPTY, "contract info");
            }
            // Contract address of the event
            String contractAddress = log.getAddress();
            for (Map.Entry<String, Class> entry : eventBeanMap.entrySet()) {
                String keyWithAddress = entry.getKey();
                // Contract address
                String mapAddress = keyWithAddress.substring(0, contractAddress.length());
                // Function in the contract
                String mapFunction = keyWithAddress.substring(contractAddress.length());
                if (!(map.containsKey(mapFunction) && contractAddress.equalsIgnoreCase(mapAddress))) {
                    continue;
                }

                List<List<EventResultEntity>> eventLists = map.get(mapFunction);
                for (List<EventResultEntity> eventList : eventLists) {
                    try {
                        T eventBean = (T) assembleBeanByReflect(eventList, entry.getValue());
                        eventBean.setBlockHash(transaction.getBlockHash());
                        eventBean.setTransactionInfoBean(transaction);
                        eventBean.setBlockNumber(transaction.getBlockNumber().toString());
                        eventBean.setTimestamp(txTimestamp + "000");
                        arrayList.add(eventBean);
                    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException e) {
                        e.printStackTrace();
                        try {
                            throw e;
                        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException ex) {
                            ex.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}




Copyright © 2022 Red Date (Hong Kong) Technology Limited all right reserved,powered by Gitbook

results matching ""

    No results matching ""

    results matching ""

      No results matching ""