6
6
from .hypersync import EventStream as _EventStream
7
7
from .hypersync import QueryResponseStream as _QueryResponseStream
8
8
from typing import Optional , Dict
9
- from dataclasses import dataclass , asdict
9
+ from dataclasses import dataclass
10
10
from strenum import StrEnum
11
11
12
12
@@ -241,7 +241,7 @@ class BlockField(StrEnum):
241
241
NUMBER = "number"
242
242
# The Keccak 256-bit hash of the block
243
243
HASH = "hash"
244
- # The Keccak 256-bit hash of the parent block’ s header, in its entirety; formally Hp.
244
+ # The Keccak 256-bit hash of the parent block' s header, in its entirety; formally Hp.
245
245
PARENT_HASH = "parent_hash"
246
246
# A 64-bit value which, combined with the mixhash, proves that a sufficient amount of computation has been carried
247
247
# out on this block; formally Hn.
@@ -265,7 +265,7 @@ class BlockField(StrEnum):
265
265
# be transferred; formally Hc.
266
266
MINER = "miner"
267
267
# A scalar value corresponding to the difficulty level of this block. This can be calculated
268
- # from the previous block’ s difficulty level and the timestamp; formally Hd.
268
+ # from the previous block' s difficulty level and the timestamp; formally Hd.
269
269
DIFFICULTY = "difficulty"
270
270
# The cumulative sum of the difficulty of all blocks that have been mined in the Ethereum network since the
271
271
# inception of the network It measures the overall security and integrity of the Ethereum network.
@@ -279,7 +279,7 @@ class BlockField(StrEnum):
279
279
GAS_LIMIT = "gas_limit"
280
280
# A scalar value equal to the total gas used in transactions in this block; formally Hg.
281
281
GAS_USED = "gas_used"
282
- # A scalar value equal to the reasonable output of Unix’ s time() at this block’ s inception; formally Hs.
282
+ # A scalar value equal to the reasonable output of Unix' s time() at this block' s inception; formally Hs.
283
283
TIMESTAMP = "timestamp"
284
284
# Ommers/uncles header.
285
285
UNCLES = "uncles"
@@ -323,7 +323,7 @@ class TransactionField(StrEnum):
323
323
# A scalar value equal to the number of ancestor blocks. The genesis block has a number of
324
324
# zero; formally Hi.
325
325
BLOCK_NUMBER = "block_number"
326
- # The 160-bit address of the message call’ s sender
326
+ # The 160-bit address of the message call' s sender
327
327
FROM = "from"
328
328
# A scalar value equal to the maximum amount of gas that should be used in executing
329
329
# 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):
342
342
INPUT = "input"
343
343
# A scalar value equal to the number of transactions sent by the sender; formally Tn.
344
344
NONCE = "nonce"
345
- # The 160-bit address of the message call’ s recipient or, for a contract creation
345
+ # The 160-bit address of the message call' s recipient or, for a contract creation
346
346
# transaction, ∅, used here to denote the only member of B0 ; formally Tt.
347
347
TO = "to"
348
348
# Index of the transaction in the block
349
349
TRANSACTION_INDEX = "transaction_index"
350
- # A scalar value equal to the number of Wei to be transferred to the message call’ s recipient or,
350
+ # A scalar value equal to the number of Wei to be transferred to the message call' s recipient or,
351
351
# in the case of contract creation, as an endowment to the newly created account; formally Tv.
352
352
VALUE = "value"
353
353
# Replay protection value based on chain_id. See EIP-155 for more info.
@@ -645,6 +645,10 @@ class StreamConfig:
645
645
hex_output : Optional [HexOutput ] = None
646
646
# Maximum batch size that could be used during dynamic adjustment.
647
647
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
648
652
# Number of async threads that would be spawned to execute different block ranges of queries.
649
653
concurrency : Optional [int ] = None
650
654
# Max number of blocks to fetch in a single request.
@@ -655,6 +659,10 @@ class StreamConfig:
655
659
max_num_logs : Optional [int ] = None
656
660
# Max number of traces to fetch in a single request.
657
661
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
658
666
659
667
660
668
@dataclass
@@ -800,7 +808,7 @@ class HypersyncClient:
800
808
801
809
def __init__ (self , config : ClientConfig ):
802
810
"""Creates a new client with the given configuration."""
803
- self .inner = _HypersyncClient (asdict ( config ) )
811
+ self .inner = _HypersyncClient (config )
804
812
805
813
async def get_height (self ) -> int :
806
814
"""Get the height of the hypersync server with retries."""
@@ -820,18 +828,18 @@ async def collect(self, query: Query, config: StreamConfig) -> QueryResponse:
820
828
Each query runs until it reaches query.to, server height, any max_num_* query param,
821
829
or execution timed out by server.
822
830
"""
823
- return await self .inner .collect (asdict ( query ), asdict ( config ) )
831
+ return await self .inner .collect (query , config )
824
832
825
833
async def collect_events (self , query : Query , config : StreamConfig ) -> EventResponse :
826
834
"""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 )
828
836
829
837
async def collect_arrow (self , query : Query , config : StreamConfig ) -> ArrowResponse :
830
838
"""
831
839
Retrieves blocks, transactions, traces, and logs in Arrow format through a stream using
832
840
the provided query and stream configuration.
833
841
"""
834
- return await self .inner .collect_arrow (asdict ( query ), asdict ( config ) )
842
+ return await self .inner .collect_arrow (query , config )
835
843
836
844
async def collect_parquet (
837
845
self , path : str , query : Query , config : StreamConfig
@@ -840,37 +848,37 @@ async def collect_parquet(
840
848
Writes parquet file getting data through a stream using the provided path, query,
841
849
and stream configuration.
842
850
"""
843
- return await self .inner .collect_parquet (path , asdict ( query ), asdict ( config ) )
851
+ return await self .inner .collect_parquet (path , query , config )
844
852
845
853
async def get (self , query : Query ) -> QueryResponse :
846
854
"""Executes query with retries and returns the response."""
847
- return await self .inner .get (asdict ( query ) )
855
+ return await self .inner .get (query )
848
856
849
857
async def get_events (self , query : Query ) -> EventResponse :
850
858
"""
851
859
Add block, transaction and log fields selection to the query, executes it with retries
852
860
and returns the response.
853
861
"""
854
- return await self .inner .get_events (asdict ( query ) )
862
+ return await self .inner .get_events (query )
855
863
856
864
async def get_arrow (self , query : Query ) -> ArrowResponse :
857
865
"""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 )
859
867
860
868
async def stream (self , query : Query , config : StreamConfig ) -> QueryResponseStream :
861
869
"""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 )
863
871
864
872
async def stream_events (self , query : Query , config : StreamConfig ) -> EventStream :
865
873
"""
866
874
Add block, transaction and log fields selection to the query and spawns task to execute it,
867
875
returning data via a channel.
868
876
"""
869
- return await self .inner .stream_events (asdict ( query ), asdict ( config ) )
877
+ return await self .inner .stream_events (query , config )
870
878
871
879
async def stream_arrow (self , query : Query , config : StreamConfig ) -> ArrowStream :
872
880
"""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 )
874
882
875
883
876
884
def preset_query_blocks_and_transactions (
0 commit comments