Browse Source

It was a mistake to use tuples

master
Neil Booth 8 years ago
parent
commit
6deb05ab6f
  1. 20
      server/daemon.py

20
server/daemon.py

@ -48,9 +48,9 @@ class Daemon(util.LoggedClass):
result = await resp.json() result = await resp.json()
if isinstance(result, list): if isinstance(result, list):
errs = tuple(item['error'] for item in result) errs = [item['error'] for item in result]
if not any(errs): if not any(errs):
return tuple(item['result'] for item in result) return [item['result'] for item in result]
if any(err.get('code') == self.WARMING_UP for err in errs if err): if any(err.get('code') == self.WARMING_UP for err in errs if err):
raise DaemonWarmingUpError raise DaemonWarmingUpError
raise DaemonError(errs) raise DaemonError(errs)
@ -105,18 +105,14 @@ class Daemon(util.LoggedClass):
return await self.send(payload) return await self.send(payload)
async def send_many(self, mp_iterable): async def send_many(self, mp_iterable):
'''Send several requests at once. '''Send several requests at once.'''
payload = [{'method': m, 'params': p} for m, p in mp_iterable]
The results are returned as a tuple.'''
payload = tuple({'method': m, 'params': p} for m, p in mp_iterable)
if payload: if payload:
return await self.send(payload) return await self.send(payload)
return () return []
async def send_vector(self, method, params_iterable): async def send_vector(self, method, params_iterable):
'''Send several requests of the same method. '''Send several requests of the same method.'''
The results are returned as a tuple.'''
return await self.send_many((method, params) return await self.send_many((method, params)
for params in params_iterable) for params in params_iterable)
@ -130,7 +126,7 @@ class Daemon(util.LoggedClass):
params_iterable = ((h, False) for h in hex_hashes) params_iterable = ((h, False) for h in hex_hashes)
blocks = await self.send_vector('getblock', params_iterable) blocks = await self.send_vector('getblock', params_iterable)
# Convert hex string to bytes # Convert hex string to bytes
return tuple(bytes.fromhex(block) for block in blocks) return [bytes.fromhex(block) for block in blocks]
async def mempool_hashes(self): async def mempool_hashes(self):
'''Return the hashes of the txs in the daemon's mempool.''' '''Return the hashes of the txs in the daemon's mempool.'''
@ -159,7 +155,7 @@ class Daemon(util.LoggedClass):
params_iterable = ((hex_hash, 0) for hex_hash in hex_hashes) params_iterable = ((hex_hash, 0) for hex_hash in hex_hashes)
txs = await self.send_vector('getrawtransaction', params_iterable) txs = await self.send_vector('getrawtransaction', params_iterable)
# Convert hex strings to bytes # Convert hex strings to bytes
return tuple(bytes.fromhex(tx) for tx in txs) return [bytes.fromhex(tx) for tx in txs]
async def sendrawtransaction(self, params): async def sendrawtransaction(self, params):
'''Broadcast a transaction to the network.''' '''Broadcast a transaction to the network.'''

Loading…
Cancel
Save