diff --git a/src/const.py b/src/const.py index f1b42c7..f02e346 100644 --- a/src/const.py +++ b/src/const.py @@ -1 +1,4 @@ +import json + WS_ADDR = "wss://ws.blockchain.info/coins" +SUB_MSG = json.dumps({"coin": "eth", "command": "subscribe", "entity": "confirmed_transaction"}) diff --git a/src/mempool.py b/src/mempool.py index e854dfb..f2e8eef 100644 --- a/src/mempool.py +++ b/src/mempool.py @@ -4,18 +4,23 @@ import threading import logging import websockets -from const import WS_ADDR +from const import WS_ADDR, SUB_MSG class WebSocketThread(threading.Thread): - def __init__(self, q, shutdown_event): + def __init__(self, q, shutdown_event, sub_msg=SUB_MSG): super().__init__() self.q = q self.shutdown_event = shutdown_event + self.sub_msg = sub_msg self.tx_count = 0 async def connect(self): async with websockets.connect(WS_ADDR) as ws: + logging.info("WebSocket connection established successfully") + await ws.send(self.sub_msg) + logging.info("Subscription message sent") + while not self.shutdown_event.is_set(): try: msg = await ws.recv()