public JArray GetLogs(ulong id, BlockchainEventFilterParams filter, bool poll) { if (poll) { filter.PollingTime = TimeUtils.CurrentTimeMillis(); _filters[id] = filter; } if ((filter.FromBlock is null) || (filter.ToBlock is null)) { return(new JArray()); } return(GetLogs((ulong)filter.FromBlock, (ulong)filter.ToBlock, filter.AddressList, filter.TopicLists)); }
public ulong Create(BlockchainEvent eventType, ulong?fromBlock, ulong?toBlock, List <UInt160> addresses, List <List <UInt256> > topics) { RemoveUnusedFilters(); _currentId++; if (eventType == BlockchainEvent.Logs) { _filters[_currentId] = new BlockchainEventFilterParams( eventType, fromBlock, toBlock, addresses, topics ); } else { Logger.LogError($"Implementation not found for filter type: {eventType}"); } return(_currentId); }
public ulong Create(BlockchainEvent eventType) { RemoveUnusedFilters(); _currentId++; if (eventType == BlockchainEvent.Block) { _filters[_currentId] = new BlockchainEventFilterParams( eventType, _stateManager.LastApprovedSnapshot.Blocks.GetTotalBlockHeight() ); } else if (eventType == BlockchainEvent.Transaction) { _filters[_currentId] = new BlockchainEventFilterParams( eventType, _transactionPool.Transactions.Keys.ToArray() ); } else { Logger.LogError($"Implementation not found for filter type: {eventType}"); } return(_currentId); }
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); }
public JArray SyncBlocks(ulong id, BlockchainEventFilterParams filter, bool poll) { var results = new JArray(); var lastSyncedBlock = filter.LastSyncedBlock; var highestBlock = _stateManager.LastApprovedSnapshot.Blocks.GetTotalBlockHeight(); for (var i = lastSyncedBlock; i < highestBlock; i++) { var block = _blockManager.GetByHeight(i); if (block is null) { continue; } results.Add(Web3DataFormatUtils.Web3Data(block !.Hash)); } if (poll) { filter.LastSyncedBlock = highestBlock; filter.PollingTime = TimeUtils.CurrentTimeMillis(); _filters[id] = filter; } return(results); }