public BlockchainEventFilterParams(BlockchainEvent eventType, UInt256[] txHashes)
 {
     EventType = eventType;
     // sorting the tx hashes for further optimization
     Array.Sort(txHashes, (x, y) => UInt256Utils.Compare(x, y));
     PendingTransactionList = new List <UInt256>(txHashes.ToList());
     PollingTime            = TimeUtils.CurrentTimeMillis();
 }
        public JArray SyncPendingTransaction(ulong id, BlockchainEventFilterParams filter, bool poll)
        {
            var results = new JArray();

            var pendingTx = filter.PendingTransactionList;
            var poolTx    = _transactionPool.Transactions.Keys.ToArray();

            Array.Sort(poolTx, (x, y) => UInt256Utils.Compare(x, y));

            // comparing two sorted list listA and listB in O(listA.Count + listB.Count)

            int iter = 0;

            foreach (var txHash in poolTx)
            {
                if (txHash is null)
                {
                    continue;
                }

                while (iter < pendingTx.Count && UInt256Utils.Compare(txHash, pendingTx[iter]) > 0)
                {
                    iter++;
                }
                if (iter == pendingTx.Count || UInt256Utils.Compare(txHash, pendingTx[iter]) < 0)
                {
                    results.Add(Web3DataFormatUtils.Web3Data(txHash));
                }
            }

            if (poll)
            {
                // Pending transaction list in filter must be sorted for further optimization
                filter.PendingTransactionList = new List <UInt256>(poolTx.ToList());
                filter.PollingTime            = TimeUtils.CurrentTimeMillis();
                _filters[id] = filter;
            }
            return(results);
        }