Skip to content

Commit b98cb72

Browse files
authored
Merge pull request #39 from enviodev/py03-22-upgrade
Fix upgrade to v0.22 - Update the python client interop to remove broken `asdict`
2 parents 77b5505 + e51fc7b commit b98cb72

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

hypersync/__init__.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .hypersync import EventStream as _EventStream
77
from .hypersync import QueryResponseStream as _QueryResponseStream
88
from typing import Optional, Dict
9-
from dataclasses import dataclass, asdict
9+
from dataclasses import dataclass
1010
from strenum import StrEnum
1111

1212

@@ -241,7 +241,7 @@ class BlockField(StrEnum):
241241
NUMBER = "number"
242242
# The Keccak 256-bit hash of the block
243243
HASH = "hash"
244-
# The Keccak 256-bit hash of the parent blocks header, in its entirety; formally Hp.
244+
# The Keccak 256-bit hash of the parent block's header, in its entirety; formally Hp.
245245
PARENT_HASH = "parent_hash"
246246
# A 64-bit value which, combined with the mixhash, proves that a sufficient amount of computation has been carried
247247
# out on this block; formally Hn.
@@ -265,7 +265,7 @@ class BlockField(StrEnum):
265265
# be transferred; formally Hc.
266266
MINER = "miner"
267267
# A scalar value corresponding to the difficulty level of this block. This can be calculated
268-
# from the previous blocks difficulty level and the timestamp; formally Hd.
268+
# from the previous block's difficulty level and the timestamp; formally Hd.
269269
DIFFICULTY = "difficulty"
270270
# The cumulative sum of the difficulty of all blocks that have been mined in the Ethereum network since the
271271
# inception of the network It measures the overall security and integrity of the Ethereum network.
@@ -279,7 +279,7 @@ class BlockField(StrEnum):
279279
GAS_LIMIT = "gas_limit"
280280
# A scalar value equal to the total gas used in transactions in this block; formally Hg.
281281
GAS_USED = "gas_used"
282-
# A scalar value equal to the reasonable output of Unixs time() at this blocks inception; formally Hs.
282+
# A scalar value equal to the reasonable output of Unix's time() at this block's inception; formally Hs.
283283
TIMESTAMP = "timestamp"
284284
# Ommers/uncles header.
285285
UNCLES = "uncles"
@@ -323,7 +323,7 @@ class TransactionField(StrEnum):
323323
# A scalar value equal to the number of ancestor blocks. The genesis block has a number of
324324
# zero; formally Hi.
325325
BLOCK_NUMBER = "block_number"
326-
# The 160-bit address of the message calls sender
326+
# The 160-bit address of the message call's sender
327327
FROM = "from"
328328
# A scalar value equal to the maximum amount of gas that should be used in executing
329329
# this transaction. This is paid up-front, before any computation is done and may not be increased later;
@@ -342,12 +342,12 @@ class TransactionField(StrEnum):
342342
INPUT = "input"
343343
# A scalar value equal to the number of transactions sent by the sender; formally Tn.
344344
NONCE = "nonce"
345-
# The 160-bit address of the message calls recipient or, for a contract creation
345+
# The 160-bit address of the message call's recipient or, for a contract creation
346346
# transaction, ∅, used here to denote the only member of B0 ; formally Tt.
347347
TO = "to"
348348
# Index of the transaction in the block
349349
TRANSACTION_INDEX = "transaction_index"
350-
# A scalar value equal to the number of Wei to be transferred to the message calls recipient or,
350+
# A scalar value equal to the number of Wei to be transferred to the message call's recipient or,
351351
# in the case of contract creation, as an endowment to the newly created account; formally Tv.
352352
VALUE = "value"
353353
# Replay protection value based on chain_id. See EIP-155 for more info.
@@ -645,6 +645,10 @@ class StreamConfig:
645645
hex_output: Optional[HexOutput] = None
646646
# Maximum batch size that could be used during dynamic adjustment.
647647
batch_size: Optional[int] = None
648+
# Maximum batch size that could be used during dynamic adjustment.
649+
max_batch_size: Optional[int] = None
650+
# Minimum batch size that could be used during dynamic adjustment.
651+
min_batch_size: Optional[int] = None
648652
# Number of async threads that would be spawned to execute different block ranges of queries.
649653
concurrency: Optional[int] = None
650654
# Max number of blocks to fetch in a single request.
@@ -655,6 +659,10 @@ class StreamConfig:
655659
max_num_logs: Optional[int] = None
656660
# Max number of traces to fetch in a single request.
657661
max_num_traces: Optional[int] = None
662+
# Response bytes ceiling for dynamic batch size adjustment.
663+
response_bytes_ceiling: Optional[int] = None
664+
# Response bytes floor for dynamic batch size adjustment.
665+
response_bytes_floor: Optional[int] = None
658666

659667

660668
@dataclass
@@ -800,7 +808,7 @@ class HypersyncClient:
800808

801809
def __init__(self, config: ClientConfig):
802810
"""Creates a new client with the given configuration."""
803-
self.inner = _HypersyncClient(asdict(config))
811+
self.inner = _HypersyncClient(config)
804812

805813
async def get_height(self) -> int:
806814
"""Get the height of the hypersync server with retries."""
@@ -820,18 +828,18 @@ async def collect(self, query: Query, config: StreamConfig) -> QueryResponse:
820828
Each query runs until it reaches query.to, server height, any max_num_* query param,
821829
or execution timed out by server.
822830
"""
823-
return await self.inner.collect(asdict(query), asdict(config))
831+
return await self.inner.collect(query, config)
824832

825833
async def collect_events(self, query: Query, config: StreamConfig) -> EventResponse:
826834
"""Retrieves events through a stream using the provided query and stream configuration."""
827-
return await self.inner.collect_events(asdict(query), asdict(config))
835+
return await self.inner.collect_events(query, config)
828836

829837
async def collect_arrow(self, query: Query, config: StreamConfig) -> ArrowResponse:
830838
"""
831839
Retrieves blocks, transactions, traces, and logs in Arrow format through a stream using
832840
the provided query and stream configuration.
833841
"""
834-
return await self.inner.collect_arrow(asdict(query), asdict(config))
842+
return await self.inner.collect_arrow(query, config)
835843

836844
async def collect_parquet(
837845
self, path: str, query: Query, config: StreamConfig
@@ -840,37 +848,37 @@ async def collect_parquet(
840848
Writes parquet file getting data through a stream using the provided path, query,
841849
and stream configuration.
842850
"""
843-
return await self.inner.collect_parquet(path, asdict(query), asdict(config))
851+
return await self.inner.collect_parquet(path, query, config)
844852

845853
async def get(self, query: Query) -> QueryResponse:
846854
"""Executes query with retries and returns the response."""
847-
return await self.inner.get(asdict(query))
855+
return await self.inner.get(query)
848856

849857
async def get_events(self, query: Query) -> EventResponse:
850858
"""
851859
Add block, transaction and log fields selection to the query, executes it with retries
852860
and returns the response.
853861
"""
854-
return await self.inner.get_events(asdict(query))
862+
return await self.inner.get_events(query)
855863

856864
async def get_arrow(self, query: Query) -> ArrowResponse:
857865
"""Executes query with retries and returns the response in Arrow format."""
858-
return await self.inner.get_arrow(asdict(query))
866+
return await self.inner.get_arrow(query)
859867

860868
async def stream(self, query: Query, config: StreamConfig) -> QueryResponseStream:
861869
"""Spawns task to execute query and return data via a channel."""
862-
return await self.inner.stream(asdict(query), asdict(config))
870+
return await self.inner.stream(query, config)
863871

864872
async def stream_events(self, query: Query, config: StreamConfig) -> EventStream:
865873
"""
866874
Add block, transaction and log fields selection to the query and spawns task to execute it,
867875
returning data via a channel.
868876
"""
869-
return await self.inner.stream_events(asdict(query), asdict(config))
877+
return await self.inner.stream_events(query, config)
870878

871879
async def stream_arrow(self, query: Query, config: StreamConfig) -> ArrowStream:
872880
"""Spawns task to execute query and return data via a channel in Arrow format."""
873-
return await self.inner.stream_arrow(asdict(query), asdict(config))
881+
return await self.inner.stream_arrow(query, config)
874882

875883

876884
def preset_query_blocks_and_transactions(

0 commit comments

Comments
 (0)