Class: Reth::JSONRPC::PendingTransactionFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/reth/jsonrpc/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chain) ⇒ PendingTransactionFilter

Returns a new instance of PendingTransactionFilter.



259
260
261
262
263
# File 'lib/reth/jsonrpc/filter.rb', line 259

def initialize(chain)
  @chain = chain
  @latest_block = @chain.head_candidate
  @reported_txs = []
end

Class Method Details

.create(chain) ⇒ Object



251
252
253
254
255
256
# File 'lib/reth/jsonrpc/filter.rb', line 251

def create(chain)
  f = new chain
  id = Filter.next_id
  Filter.map[id] = f
  id
end

Instance Method Details

#checkObject



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/reth/jsonrpc/filter.rb', line 265

def check
  head_candidate = @chain.head_candidate
  pending_txs = head_candidate.get_transactions
  new_txs = pending_txs.select {|tx| !@reported_txs.include?(tx.full_hash) }

  block = head_candidate.get_parent
  while block.number >= @latest_block.number
    block.get_transactions.reverse.each do |tx|
      new_txs.push(tx) unless @reported_txs.include?(tx.full_hash)
    end

    block = block.get_parent
  end

  @latest_block = head_candidate
  @reported_txs = pending_txs.map(&:full_hash)

  new_txs.reverse
end