tConnect ElectrumProtocol with ZeroMQ Client. - obelisk - Electrum server using libbitcoin as its backend HTML git clone https://git.parazyd.org/obelisk DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR commit 2d336652b6b4fa2c55e32d5afca2b9b4f55fc5fa DIR parent bae345a9b95dff3ae89ec354a12b6bab8182c7d6 HTML Author: parazyd <parazyd@dyne.org> Date: Wed, 7 Apr 2021 17:00:39 +0200 Connect ElectrumProtocol with ZeroMQ Client. Diffstat: M electrumobelisk/protocol.py | 5 +++++ M electrumobelisk/zeromq.py | 22 ++++++---------------- 2 files changed, 11 insertions(+), 16 deletions(-) --- DIR diff --git a/electrumobelisk/protocol.py b/electrumobelisk/protocol.py t@@ -17,6 +17,8 @@ import asyncio import json +from zeromq import Client + VERSION = 0.0 DONATION_ADDR = "bc1q7an9p5pz6pjwjk4r48zke2yfaevafzpglg26mz" t@@ -38,6 +40,9 @@ class ElectrumProtocol(asyncio.Protocol): self.log = log self.endpoints = endpoints self.server_cfg = server_cfg + self.loop = asyncio.get_event_loop() + # Consider renaming bx to something else + self.bx = Client(log, endpoints, self.loop) if chain == "mainnet": self.genesis = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" DIR diff --git a/electrumobelisk/zeromq.py b/electrumobelisk/zeromq.py t@@ -172,16 +172,10 @@ class RequestCollection: class Client: - """This class represents a connection to a libbitcoin server. - hostname -- the server DNS name to connect to - ports -- a dictionary containing four keys; query/heartbeat/block/tx - """ - - # def __init__(self, hostname, ports, settings=ClientSettings()): - def __init__(self, hostname, ports, loop): - self._hostname = hostname - self._ports = ports - # self._settings = settings + """This class represents a connection to a libbitcoin server.""" + def __init__(self, log, endpoints, loop): + self.log = log + self._endpoints = endpoints self._settings = ClientSettings(loop=loop) self._query_socket = self._create_query_socket() self._block_socket = self._create_block_socket() t@@ -198,7 +192,7 @@ class Client: zmq.SUB, # pylint: disable=E1101 io_loop=self._settings._loop, # pylint: disable=W0212 ) - socket.connect(self.__server_url(self._hostname, self._ports["block"])) + socket.connect(self._endpoints["block"]) socket.setsockopt_string(zmq.SUBSCRIBE, "") # pylint: disable=E1101 return socket t@@ -207,7 +201,7 @@ class Client: zmq.DEALER, # pylint: disable=E1101 io_loop=self._settings._loop, # pylint: disable=W0212 ) - socket.connect(self.__server_url(self._hostname, self._ports["query"])) + socket.connect(self._endpoints["query"]) return socket async def _subscription_request(self, command, data): t@@ -240,7 +234,3 @@ class Client: assert response.command == request.command assert response.request_id == request.id_ return response.error_code, response.data - - @staticmethod - def __server_url(hostname, port): - return "tcp://" + hostname + ":" + str(port)