No project description provided
Project description
eth-blocky
Package providing date utilities for finding blocks.
With eth-blocky
, you can:
- Find the closest block to a given timestamp that happened before
- Find the closest block to a given timestamp that happened at the exact same time or after
Installation
pip install eth-blocky
Usage
Provide a timestamp for which you want to find the closest block, and as a result you will get the block object. For more information check out web3 docs
from eth_blocky import EthBlocky
client = EthBlocky(NODE_URL)
# 2021-03-11T12:00:00
timestamp = 1615464000
block = client.closest_block(timestamp, before=True)
print(block.number)
# 12017166
block = client.closest_block(timestamp)
print(block.number)
# 12017167
Method
eth-blocky
works as an optimized binary search.
Start with finding the first and latest block as the boundry. Left and right
block.
Steps:
- Get left and right block and their timestamps
- Calculate the average time for blocks to being mined in this time range
- Estimate distance from start block based on timestamps [1, 3, 10] -> 0.3
- Estimate wanted block based on distance
- Calculate potential error
- Repeat from step 1 with [estimated block - error, estimated block + error] as the left and right block
The process is repeated until left block is equal to right block.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
eth_blocky-0.2.3.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for eth_blocky-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6841ceab83101ab5449e3f3fcfca0ddcd9c1a549e3c4c16d5b719cf759719c3 |
|
MD5 | 56545441f7befeb553b0d6d5ea07f4dc |
|
BLAKE2b-256 | f0d94302ee7e913654b44ff24f8040c9bdc3b9d370cda08beb5580ea7a23bb9e |