BlockHeader

Documentation for eth_defi.event_reader.block_header.BlockHeader Python class.

class BlockHeader[source]

Describe block headers for a single block.

  • This data is used to check chain reorganisations

  • This data is used to store block number -> block timestamp map and resolve trades to their UTC time

Attributes summary

block_number

32-bit uint of he block number

block_hash

Block hash as 0x prefixed string

timestamp

32 bit uint UNIX UTC timestamp of the block

Methods summary

__init__(block_number, block_hash, timestamp)

from_pandas(df)

Decode saved Pandas input.

generate_headers(count[, start_block, ...])

Generate random block header data.

to_pandas(headers[, partition_size])

Convert columnar header data to Pandas.

block_number: int

32-bit uint of he block number

block_hash: str

Block hash as 0x prefixed string

Note that this might be converted to binary data later.

timestamp: int

32 bit uint UNIX UTC timestamp of the block

TODO: We might need float because high throughput chains like Solana have subsecond timestamps

static generate_headers(count, start_block=1, start_time=0, blocks_per_second=12)[source]

Generate random block header data.

Used for testing.

Returns

DataFrame indexed by block number

Parameters
  • count (int) –

  • start_block (int) –

  • start_time (float) –

  • blocks_per_second (float) –

Return type

Dict[str, list]

static to_pandas(headers, partition_size=None)[source]

Convert columnar header data to Pandas.

Note

Depends on Pandas, but because we have optional dependency do a lazy import.

Parameters
  • headers (Dict[str, list]) – Raw block data to write.

  • partition_size (Optional[int]) – Create a key “partition” which each contains partitioning_size blocks. E.g. 100_000.

Returns

static from_pandas(df)[source]

Decode saved Pandas input.

Return type

Dict[int, eth_defi.event_reader.block_header.BlockHeader]

__init__(block_number, block_hash, timestamp)
Parameters
  • block_number (int) –

  • block_hash (str) –

  • timestamp (int) –

Return type

None