Browse Source

Move get_utxos to session

patch-2
Neil Booth 7 years ago
parent
commit
c7f6f3ede6
  1. 9
      electrumx/server/controller.py
  2. 11
      electrumx/server/session.py

9
electrumx/server/controller.py

@ -156,8 +156,6 @@ class Controller(ServerBase):
height) height)
return self.header_cache[height] return self.header_cache[height]
# Helpers for RPC "blockchain" command handlers
async def get_history(self, hashX): async def get_history(self, hashX):
'''Get history asynchronously to reduce latency.''' '''Get history asynchronously to reduce latency.'''
if hashX in self.history_cache: if hashX in self.history_cache:
@ -174,10 +172,3 @@ class Controller(ServerBase):
history = await self.run_in_executor(job) history = await self.run_in_executor(job)
self.history_cache[hashX] = history self.history_cache[hashX] = history
return 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)

11
electrumx/server/session.py

@ -733,10 +733,17 @@ class ElectrumX(SessionBase):
return status 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): async def hashX_listunspent(self, hashX):
'''Return the list of UTXOs of a script hash, including mempool '''Return the list of UTXOs of a script hash, including mempool
effects.''' effects.'''
utxos = await self.controller.get_utxos(hashX) utxos = await self.get_utxos(hashX)
utxos = sorted(utxos) utxos = sorted(utxos)
utxos.extend(self.controller.mempool.get_utxos(hashX)) utxos.extend(self.controller.mempool.get_utxos(hashX))
spends = await self.controller.mempool.potential_spends(hashX) spends = await self.controller.mempool.potential_spends(hashX)
@ -793,7 +800,7 @@ class ElectrumX(SessionBase):
return await self.hashX_subscribe(hashX, address) return await self.hashX_subscribe(hashX, address)
async def get_balance(self, hashX): 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) confirmed = sum(utxo.value for utxo in utxos)
unconfirmed = self.controller.mempool_value(hashX) unconfirmed = self.controller.mempool_value(hashX)
return {'confirmed': confirmed, 'unconfirmed': unconfirmed} return {'confirmed': confirmed, 'unconfirmed': unconfirmed}

Loading…
Cancel
Save