obelisk

Electrum server using libbitcoin as its backend
git clone https://git.parazyd.org/obelisk
Log | Files | Refs | README | LICENSE

commit b9f545ba5ccef32b51b7cc5e32f95891716d0aa2
parent cfe0a0a83174c3c6630a321b8932c253119fade4
Author: parazyd <parazyd@dyne.org>
Date:   Mon, 19 Apr 2021 11:42:24 +0200

protocol: Convert scripthash status encoding and parting into functions.

Diffstat:
Mobelisk/protocol.py | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/obelisk/protocol.py b/obelisk/protocol.py @@ -107,6 +107,7 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 async def stop(self): """Destructor function""" self.log.debug("ElectrumProtocol.stop()") + self.stopped = True if self.bx: unsub_pool = [] for i in self.sh_subscriptions: # pragma: no cover @@ -122,8 +123,6 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 # for i in idxs: # del self.tasks[i] - self.stopped = True - async def recv(self, reader, writer): """Loop ran upon a connection which acts as a JSON-RPC handler""" recv_buf = bytearray() @@ -458,6 +457,12 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 return {"result": None} # TODO: Check how history4 acts for mempool/unconfirmed + status = ElectrumProtocol.__scripthash_status_from_history(history) + self.sh_subscriptions[scripthash]["status"] = status + return {"result": ElectrumProtocol.__scripthash_status_encode(status)} + + @staticmethod + def __scripthash_status_from_history(history): status = [] for i in history: if "received" in i: @@ -470,12 +475,10 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 hash_to_hex_str(i["spent"]["hash"]), i["spent"]["height"], )) - - self.sh_subscriptions[scripthash]["status"] = status - return {"result": ElectrumProtocol.__scripthash_status(status)} + return status @staticmethod - def __scripthash_status(status): + def __scripthash_status_encode(status): concat = "" for txid, height in status: concat += txid + ":%d:" % height