diff --git a/electrumx/server/controller.py b/electrumx/server/controller.py index a393e5b..310d6fa 100644 --- a/electrumx/server/controller.py +++ b/electrumx/server/controller.py @@ -156,8 +156,6 @@ class Controller(ServerBase): height) return self.header_cache[height] - # Helpers for RPC "blockchain" command handlers - async def get_history(self, hashX): '''Get history asynchronously to reduce latency.''' if hashX in self.history_cache: @@ -174,10 +172,3 @@ class Controller(ServerBase): history = await self.run_in_executor(job) self.history_cache[hashX] = history return history - - async def get_utxos(self, hashX): - '''Get UTXOs asynchronously to reduce latency.''' - def job(): - return list(self.bp.get_utxos(hashX, limit=None)) - - return await self.run_in_executor(job) diff --git a/electrumx/server/session.py b/electrumx/server/session.py index c2cd164..6a3cbb5 100644 --- a/electrumx/server/session.py +++ b/electrumx/server/session.py @@ -733,10 +733,17 @@ class ElectrumX(SessionBase): return status + async def get_utxos(self, hashX): + '''Get UTXOs asynchronously to reduce latency.''' + def job(): + return list(self.bp.get_utxos(hashX, limit=None)) + + return await self.controller.run_in_executor(job) + async def hashX_listunspent(self, hashX): '''Return the list of UTXOs of a script hash, including mempool effects.''' - utxos = await self.controller.get_utxos(hashX) + utxos = await self.get_utxos(hashX) utxos = sorted(utxos) utxos.extend(self.controller.mempool.get_utxos(hashX)) spends = await self.controller.mempool.potential_spends(hashX) @@ -793,7 +800,7 @@ class ElectrumX(SessionBase): return await self.hashX_subscribe(hashX, address) async def get_balance(self, hashX): - utxos = await self.controller.get_utxos(hashX) + utxos = await self.get_utxos(hashX) confirmed = sum(utxo.value for utxo in utxos) unconfirmed = self.controller.mempool_value(hashX) return {'confirmed': confirmed, 'unconfirmed': unconfirmed}