Move get_utxos to session

This commit is contained in:
Neil Booth 2018-07-17 22:12:41 +08:00
parent c712d4be32
commit c7f6f3ede6
2 changed files with 9 additions and 11 deletions

View File

@ -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)

View File

@ -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}