fix: add forgotten subscription message

This commit is contained in:
17ms 2024-07-01 21:06:25 +03:00
parent 571be9ed7b
commit f13d581c66
Signed by untrusted user who does not match committer: ae
GPG Key ID: 995EFD5C1B532B3E
2 changed files with 10 additions and 2 deletions

View File

@ -1 +1,4 @@
import json
WS_ADDR = "wss://ws.blockchain.info/coins" WS_ADDR = "wss://ws.blockchain.info/coins"
SUB_MSG = json.dumps({"coin": "eth", "command": "subscribe", "entity": "confirmed_transaction"})

View File

@ -4,18 +4,23 @@ import threading
import logging import logging
import websockets import websockets
from const import WS_ADDR from const import WS_ADDR, SUB_MSG
class WebSocketThread(threading.Thread): class WebSocketThread(threading.Thread):
def __init__(self, q, shutdown_event): def __init__(self, q, shutdown_event, sub_msg=SUB_MSG):
super().__init__() super().__init__()
self.q = q self.q = q
self.shutdown_event = shutdown_event self.shutdown_event = shutdown_event
self.sub_msg = sub_msg
self.tx_count = 0 self.tx_count = 0
async def connect(self): async def connect(self):
async with websockets.connect(WS_ADDR) as ws: 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(): while not self.shutdown_event.is_set():
try: try:
msg = await ws.recv() msg = await ws.recv()