3232
3333BN_BASE_URL = 'wss://api.blocknative.com/v0'
3434BN_ETHEREUM = 'ethereum'
35+ BN_ETHEREUM_ID = 1
36+ BN_STREAM_CLASS_VERSION = '1.1'
3537
3638Callback = Callable [[dict , Callable ], None ]
3739
@@ -84,23 +86,23 @@ def as_dict(self) -> dict:
8486 }
8587
8688
87- @dataclass
8889class Stream :
8990 """Stream class used to connect to Blocknative's WebSocket API."""
9091
9192 api_key : str
9293 blockchain : str = BN_ETHEREUM
93- network_id : int = 1
94- version : str = '1'
94+ network_id : int = BN_ETHEREUM_ID
95+ version : str = BN_STREAM_CLASS_VERSION
9596 global_filters : List [dict ] = None
9697 valid_session : bool = True
97- _ws : WebSocketConnection = field (default = None , init = False )
98- _message_queue : Queue = field (default = Queue (), init = False )
98+ _ws : WebSocketConnection = None
99+ _message_queue : Queue = Queue ()
100+ _subscription_registry : Mapping [str , Subscription ] = {}
99101
100- # Registry of active subscriptions.
101- _subscription_registry : Mapping [ str , Subscription ] = field (
102- default_factory = dict , init = False
103- )
102+ def __init__ ( self , api_key : str , blockchain : str = BN_ETHEREUM , network_id : int = BN_ETHEREUM_ID ):
103+ self . api_key = api_key
104+ self . blockchain = blockchain
105+ self . network_id = network_id
104106
105107 def subscribe_address (
106108 self ,
@@ -156,7 +158,7 @@ def subscribe_txn(self, tx_hash: str, callback: Callback, status: str = 'sent'):
156158 if self ._is_connected ():
157159 self ._send_txn_watch_message (tx_hash , status )
158160
159- def connect (self , base_url :str = BN_BASE_URL ):
161+ def connect (self , base_url : str = BN_BASE_URL ):
160162 """Initializes the connection to the WebSocket server."""
161163 try :
162164 return trio .run (self ._connect , base_url )
@@ -170,8 +172,9 @@ def send_message(self, message: str):
170172 Args:
171173 message: The message to send.
172174 """
173- logging .debug ('Sending: {}' % message )
174175 self ._message_queue .put (message )
176+ logging .debug ('Sending: %s' , message )
177+
175178
176179 async def _message_dispatcher (self ):
177180 """In a loop: Polls send message queue for latest messages to send to server.
0 commit comments