tzeromq/fetch_balance: Return a tuple of confirmed/unconfirmed. - 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 eec7afe359164f0bb0aab3df1a46c90e21c1dceb
DIR parent 6bdd6ef5754fa88ddcb3736fbd9acd8a37db2e58
HTML Author: parazyd <parazyd@dyne.org>
Date: Mon, 19 Apr 2021 10:56:29 +0200
zeromq/fetch_balance: Return a tuple of confirmed/unconfirmed.
Diffstat:
M obelisk/protocol.py | 3 +--
M obelisk/zeromq.py | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
---
DIR diff --git a/obelisk/protocol.py b/obelisk/protocol.py
t@@ -354,8 +354,7 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902
self.log.debug("Got error: %s", repr(_ec))
return JsonRPCError.internalerror()
- # TODO: confirmed/unconfirmed, see what's happening in libbitcoin
- ret = {"confirmed": data, "unconfirmed": 0}
+ ret = {"confirmed": data[0], "unconfirmed": data[1]}
return {"result": ret}
async def scripthash_get_history(self, writer, query): # pylint: disable=W0613
DIR diff --git a/obelisk/zeromq.py b/obelisk/zeromq.py
t@@ -401,8 +401,23 @@ class Client:
return error_code, None
utxo = Client.__receives_without_spends(history)
- return error_code, functools.reduce(
- lambda accumulator, point: accumulator + point["value"], utxo, 0)
+
+ return error_code, (
+ # confirmed
+ functools.reduce(
+ lambda accumulator, point: accumulator + point["value"]
+ if point["received"]["height"] != 4294967295 else 0,
+ utxo,
+ 0,
+ ),
+ # unconfirmed
+ functools.reduce(
+ lambda accumulator, point: accumulator + point["value"]
+ if point["received"]["height"] == 4294967295 else 0,
+ utxo,
+ 0,
+ ),
+ )
async def fetch_utxo(self, scripthash):
"""Find UTXO for given scripthash"""