Search in sources :

Example 1 with EvtContract

use of org.aion.api.server.types.EvtContract in project aion by aionnetwork.

the class ApiAion0 method onBlock.

protected void onBlock(AionBlockSummary cbs) {
    Set<Long> keys = installedFilters.keySet();
    for (Long key : keys) {
        Fltr fltr = installedFilters.get(key);
        if (fltr.isExpired()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("<fltr key={} expired removed>", key);
            }
            installedFilters.remove(key);
        } else {
            List<AionTxReceipt> txrs = cbs.getReceipts();
            if (fltr.getType() == Fltr.Type.EVENT && !Optional.ofNullable(txrs).orElse(Collections.emptyList()).isEmpty()) {
                FltrCt _fltr = (FltrCt) fltr;
                for (AionTxReceipt txr : txrs) {
                    AionTransaction tx = txr.getTransaction();
                    AionAddress contractAddress = Optional.ofNullable(tx.getDestinationAddress()).orElse(TxUtil.calculateContractAddress(tx));
                    Integer cnt = 0;
                    txr.getLogInfoList().forEach(bi -> bi.copyOfTopics().forEach(lg -> {
                        if (_fltr.isFor(contractAddress, ByteUtil.toHexString(lg))) {
                            Block blk = (cbs).getBlock();
                            List<AionTransaction> txList = blk.getTransactionsList();
                            int insideCnt = 0;
                            for (AionTransaction t : txList) {
                                if (Arrays.equals(t.getTransactionHash(), tx.getTransactionHash())) {
                                    break;
                                }
                                insideCnt++;
                            }
                            EvtContract ec = new EvtContract(bi.copyOfAddress(), bi.copyOfData(), blk.getHash(), blk.getNumber(), cnt, ByteUtil.toHexString(lg), false, insideCnt, tx.getTransactionHash());
                            _fltr.add(ec);
                        }
                    }));
                }
            }
        }
    }
}
Also used : Funcs(org.aion.api.server.pb.Message.Funcs) Arrays(java.util.Arrays) ApiTxResponse(org.aion.api.server.ApiTxResponse) ArgTxCall(org.aion.api.server.types.ArgTxCall) Seal(org.aion.zero.impl.types.BlockHeader.Seal) Version(org.aion.zero.impl.Version) NodeWrapper(org.aion.zero.impl.sync.NodeWrapper) LRUMap(org.apache.commons.collections4.map.LRUMap) AionTxReceipt(org.aion.base.AionTxReceipt) ByteBuffer(java.nio.ByteBuffer) FltrCt(org.aion.api.server.types.FltrCt) AddressUtils(org.aion.util.types.AddressUtils) Map(java.util.Map) BigInteger(java.math.BigInteger) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) IApiAion(org.aion.api.server.IApiAion) AionAddress(org.aion.types.AionAddress) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Fltr(org.aion.api.server.types.Fltr) Keystore(org.aion.zero.impl.keystore.Keystore) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) ByteUtil(org.aion.util.bytes.ByteUtil) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) EvtTx(org.aion.api.server.types.EvtTx) EventCallback(org.aion.evtmgr.impl.callback.EventCallback) TxRecpt(org.aion.api.server.types.TxRecpt) ByteString(com.google.protobuf.ByteString) Objects(java.util.Objects) TxUtil(org.aion.base.TxUtil) EquihashMiner(org.aion.equihash.EquihashMiner) List(java.util.List) StringUtils(org.aion.util.string.StringUtils) Entry(java.util.Map.Entry) PendingTransactionState(org.aion.zero.impl.pendingState.PendingTransactionState) Optional(java.util.Optional) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) SyncInfo(org.aion.api.server.types.SyncInfo) EvtContract(org.aion.api.server.types.EvtContract) CfgAion(org.aion.zero.impl.config.CfgAion) AionHub(org.aion.zero.impl.blockchain.AionHub) Hash256(org.aion.util.types.Hash256) Servs(org.aion.api.server.pb.Message.Servs) IEvent(org.aion.evtmgr.IEvent) HashMap(java.util.HashMap) EventBlock(org.aion.evtmgr.impl.evt.EventBlock) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) AccountManager(org.aion.api.server.account.AccountManager) IAionChain(org.aion.zero.impl.blockchain.IAionChain) Retcode(org.aion.api.server.pb.Message.Retcode) StakingBlock(org.aion.zero.impl.types.StakingBlock) ApiAion(org.aion.api.server.ApiAion) IHandler(org.aion.evtmgr.IHandler) LongStream(java.util.stream.LongStream) ApiUtil(org.aion.api.server.ApiUtil) Hex(org.aion.util.conversions.Hex) Log(org.aion.types.Log) TxRecptLg(org.aion.api.server.types.TxRecptLg) EventExecuteService(org.aion.evtmgr.impl.es.EventExecuteService) CompiledContr(org.aion.api.server.types.CompiledContr) AionBlockchainImpl(org.aion.zero.impl.blockchain.AionBlockchainImpl) AbstractMap(java.util.AbstractMap) EMPTY_BYTE_ARRAY(org.aion.util.bytes.ByteUtil.EMPTY_BYTE_ARRAY) AionTxInfo(org.aion.zero.impl.types.AionTxInfo) AionTransaction(org.aion.base.AionTransaction) Collections(java.util.Collections) TxPendingStatus(org.aion.api.server.types.TxPendingStatus) JSONArray(org.json.JSONArray) AionAddress(org.aion.types.AionAddress) Fltr(org.aion.api.server.types.Fltr) EvtContract(org.aion.api.server.types.EvtContract) AionTransaction(org.aion.base.AionTransaction) FltrCt(org.aion.api.server.types.FltrCt) BigInteger(java.math.BigInteger) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) EventBlock(org.aion.evtmgr.impl.evt.EventBlock) StakingBlock(org.aion.zero.impl.types.StakingBlock) List(java.util.List) ArrayList(java.util.ArrayList) AionTxReceipt(org.aion.base.AionTxReceipt)

Aggregations

ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Collectors (java.util.stream.Collectors)1 LongStream (java.util.stream.LongStream)1