From beeb60f3242ad12a6779190f7605e86b678ec93e Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Fri, 18 Nov 2016 21:41:27 +0900 Subject: [PATCH] Implement blockchain.address.get_mempool Fixes #26 --- server/protocol.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/server/protocol.py b/server/protocol.py index c5e1822..da6cbd5 100644 --- a/server/protocol.py +++ b/server/protocol.py @@ -415,17 +415,20 @@ class ElectrumX(Session): return {"block_height": height, "merkle": merkle_branch, "pos": pos} + def unconfirmed_history(self, hash168): + # Note unconfirmed history is unordered in electrum-server + # Height is -1 if unconfirmed txins, otherwise 0 + mempool = self.bp.mempool_transactions(hash168) + return [{'tx_hash': tx_hash, 'height': -unconfirmed, 'fee': fee} + for tx_hash, fee, unconfirmed in mempool] + async def get_history(self, hash168): - # Note history is ordered and mempool unordered in electrum-server - # For mempool, height is -1 if unconfirmed txins, otherwise 0 + # Note history is ordered but unconfirmed is unordered in e-s history = await self.async_get_history(hash168) - mempool = self.bp.mempool_transactions(hash168) + conf = [{'tx_hash': hash_to_str(tx_hash), 'height': height} + for tx_hash, height in history] - conf = tuple({'tx_hash': hash_to_str(tx_hash), 'height': height} - for tx_hash, height in history) - unconf = tuple({'tx_hash': tx_hash, 'height': -unconfirmed, 'fee': fee} - for tx_hash, fee, unconfirmed in mempool) - return conf + unconf + return conf + self.unconfirmed_history(hash168) def get_chunk(self, index): '''Return header chunk as hex. Index is a non-negative integer.''' @@ -476,7 +479,7 @@ class ElectrumX(Session): async def address_get_mempool(self, params): hash168 = self.extract_hash168(params) - raise self.RPCError('get_mempool is not yet implemented') + return self.unconfirmed_history(hash168) async def address_get_proof(self, params): hash168 = self.extract_hash168(params)