Class: Reth::JSONRPC::BlockFilter

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chain) ⇒ BlockFilter

Returns a new instance of BlockFilter.



226
227
228
229
# File 'lib/reth/jsonrpc/filter.rb', line 226

def initialize(chain)
  @chain = chain
  @latest_block = chain.head
end

Class Method Details

.create(chain) ⇒ Object



218
219
220
221
222
223
# File 'lib/reth/jsonrpc/filter.rb', line 218

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

Instance Method Details

#checkObject



231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/reth/jsonrpc/filter.rb', line 231

def check
  new_blocks = []
  block = @chain.head

  while block.number > @latest_block.number
    new_blocks.push block
    block = block.get_parent
  end

  puts "previous latest block not in current chain!" if block != @latest_block
  @latest_block = new_blocks.first if new_blocks.size > 0

  new_blocks.reverse
end