From e7601a23cd9a8f23a8da8e14aeddee3d0ff84554 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Wed, 6 Sep 2017 16:39:18 +0900 Subject: [PATCH] Implement other address methods for scripthash --- server/controller.py | 22 ++++++++++++++++++++++ server/session.py | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/server/controller.py b/server/controller.py index 3b62a05..d78a082 100644 --- a/server/controller.py +++ b/server/controller.py @@ -801,16 +801,31 @@ class Controller(util.LoggedClass): hashX = self.address_to_hashX(address) return await self.get_balance(hashX) + async def scripthash_get_balance(self, scripthash): + '''Return the confirmed and unconfirmed balance of a scripthash.''' + hashX = self.scripthash_to_hashX(scripthash) + return await self.get_balance(hashX) + async def address_get_history(self, address): '''Return the confirmed and unconfirmed history of an address.''' hashX = self.address_to_hashX(address) return await self.confirmed_and_unconfirmed_history(hashX) + async def scripthash_get_history(self, scripthash): + '''Return the confirmed and unconfirmed history of a scripthash.''' + hashX = self.scripthash_to_hashX(scripthash) + return await self.confirmed_and_unconfirmed_history(hashX) + async def address_get_mempool(self, address): '''Return the mempool transactions touching an address.''' hashX = self.address_to_hashX(address) return await self.unconfirmed_history(hashX) + async def scripthash_get_mempool(self, scripthash): + '''Return the mempool transactions touching a scripthash.''' + hashX = self.scripthash_to_hashX(scripthash) + return await self.unconfirmed_history(hashX) + async def address_get_proof(self, address): '''Return the UTXO proof of an address.''' hashX = self.address_to_hashX(address) @@ -823,6 +838,13 @@ class Controller(util.LoggedClass): 'height': utxo.height, 'value': utxo.value} for utxo in sorted(await self.get_utxos(hashX))] + async def scripthash_listunspent(self, scripthash): + '''Return the list of UTXOs of a scripthash.''' + hashX = self.scripthash_to_hashX(scripthash) + return [{'tx_hash': hash_to_str(utxo.tx_hash), 'tx_pos': utxo.tx_pos, + 'height': utxo.height, 'value': utxo.value} + for utxo in sorted(await self.get_utxos(hashX))] + def block_get_header(self, height): '''The deserialized header at a given height. diff --git a/server/session.py b/server/session.py index fc47e6b..ae75377 100644 --- a/server/session.py +++ b/server/session.py @@ -381,6 +381,11 @@ class ElectrumX(SessionBase): .format(version_str), JSONRPC.FATAL_ERROR) handlers = { + 'blockchain.address.get_balance': controller.address_get_balance, + 'blockchain.address.get_history': controller.address_get_history, + 'blockchain.address.get_mempool': controller.address_get_mempool, + 'blockcahin.address.get_proof': controller.address_get_proof, + 'blockchain.address.listunspent': controller.address_listunspent, 'blockchain.address.subscribe': self.address_subscribe, 'blockchain.block.get_chunk': self.block_get_chunk, 'blockchain.headers.subscribe': self.headers_subscribe, @@ -403,6 +408,14 @@ class ElectrumX(SessionBase): del handlers['blockchain.utxo.get_address'] # Add new handlers handlers.update({ + 'blockchain.scripthash.get_balance': + controller.scripthash_get_balance, + 'blockchain.scripthash.get_history': + controller.scripthash_get_history, + 'blockchain.scripthash.get_mempool': + controller.scripthash_get_mempool, + 'blockchain.scripthash.listunspent': + controller.scripthash_listunspent, 'blockchain.scripthash.subscribe': self.scripthash_subscribe, 'blockchain.transaction.broadcast': self.transaction_broadcast, 'blockchain.transaction.get': controller.transaction_get,