Skip to content

Commit

Permalink
1.21.1 Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gabedonnan committed Feb 5, 2024
1 parent faf5343 commit 1a44ac7
Show file tree
Hide file tree
Showing 6 changed files with 427 additions and 365 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Features include:
- Private transaction and Bundle support for communication directly with block builders
- Automatic nonce and gas management for transactions
- Early-stage support for L2 chain specific functionality (Optimism P2P implemented for now)
- Automatic ABI decoding
- Typed function outputs for intuitive library use

### Implemented RPC methods
Expand Down Expand Up @@ -68,7 +69,7 @@ pythereum = {git = "https://github.com/gabedonnan/pythereum.git"}
or

```toml
pythereum = "^1.2.0"
pythereum = "^1.2.1"
```

If you would like to install the library via pypi instead of via this git repository.
Expand Down
15 changes: 9 additions & 6 deletions demo/listen_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Further copyright info available at the end of the file

import asyncio
from time import time

from pythereum import EthRPC, SubscriptionType
from dotenv import dotenv_values
Expand All @@ -15,22 +16,24 @@ async def listen_blocks(url):
Function to create a new_heads subscription, use the hash from each header received to get full block info.
That full block info is then used to get all transaction receipts from that given block.
"""
prev = 0
# Create EthRPC object with pool size of 2 (arbitrarily chosen, as it does not matter here)
erpc = EthRPC(url, 2, connection_max_payload_size=2**24)

# Start the socket pool, may take a while due to connection forming
await erpc.start_pool()

# Create + context manage new_heads subscription
async with erpc.subscribe(SubscriptionType.new_heads, 3) as sc:
async with erpc.subscribe(SubscriptionType.new_heads, 80) as sc:
# Loops forever over the received data from the subscription
async for header in sc.recv():
# Gets more block data from the hash received from the headers
block = await erpc.get_block_by_hash(header.hash, True)

# Iterates through the transactions found in retrieved data
for tx in block.transactions:
print(tx)
print((t0 := time()) - prev)
prev = t0
# block = await erpc.get_block_by_hash(header.hash, True)
# # Iterates through the transactions found in retrieved data
# for tx in block.transactions:
# print(tx)
# Gets and prints the receipts for each transaction
# r = await erpc.get_transaction_receipt(tx.hash)
# print(r)
Expand Down
Loading

0 comments on commit 1a44ac7

Please sign in to comment.