event_reader.lazy_timestamp_reader
Documentation for eth_defi.event_reader.lazy_timestamp_reader Python module.
Lazily load block timestamps and headers.
See extract_timestamps_json_rpc_lazy()
Functions
|
Create a cache container that instead of reading block timestamps upfront for the given range, only calls JSON-RPC API when requested |
Classes
Dictionary-like object to get block timestamps on-demand. |
|
Track block header fetching across multiple chunks. |
Exceptions
We tried to read a block outside out original given range. |
- exception OutOfSpecifiedRangeRead
Bases:
ExceptionWe tried to read a block outside out original given range.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class LazyTimestampContainer
Bases:
objectDictionary-like object to get block timestamps on-demand.
Lazily load any block timestamp over JSON-RPC API if we have not cached it yet.
See
extract_timestamps_json_rpc_lazy().TODO: This is not using middleware and fails to retry any failed JSON-RPC requests.
- Parameters
web3 – Connection
start_block – Start block range, inclusive
end_block – End block range, inclusive
- __init__(web3, start_block, end_block, callback=None)
- api_call_counter
How many API requets we have made
- update_block_hash(block_identifier)
Internal function to get block timestamp from JSON-RPC and store it in the cache.
- extract_timestamps_json_rpc_lazy(web3, start_block, end_block, fetch_boundaries=True)
Create a cache container that instead of reading block timestamps upfront for the given range, only calls JSON-RPC API when requested
Works on the cases where sparse event data is read over long block range Use slow JSON-RPC block headers call to get this information.
The reader is hash based. It is mainly meant to resolve eth_getLogs resulting block hashes to corresponding event timestamps.
This is a drop-in replacement for the dict returned by eager
eth_defi.reader.extract_timestamps_json_rpc()
Example:
# Allocate timestamp reader for blocks 1...100 timestamps = extract_timestamps_json_rpc_lazy(web3, 1, 100) # Get a hash of some block block_hash = web3.eth.get_block(5)["hash"] # Read timestamp for block 5 unix_time = timestamps[block_hash]
For more information see
eth_defi.reader.extract_timestamps_json_rpc()eth_defi.reorganisation_monitor.ReorganisationMonitor
- Returns
Wrapper object for block hash based timestamp access.
- Parameters
- Return type
eth_defi.event_reader.lazy_timestamp_reader.LazyTimestampContainer
- class TrackedLazyTimestampReader
Bases:
objectTrack block header fetching across multiple chunks.
Monitor expensive eth_getBlock JSON-RPC process via :py:method:`get_count`.
- __init__()