1
0

move synchronous_get to network.py, fix get_balance script

This commit is contained in:
ThomasV
2013-10-03 10:05:01 +02:00
parent f93bc5951c
commit 7a5016ec42
5 changed files with 31 additions and 30 deletions

View File

@@ -101,7 +101,7 @@ class Commands:
def getaddresshistory(self, addr):
h = self.wallet.get_history(addr)
if h is None: h = self.wallet.interface.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
if h is None: h = self.network.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
return h
def listunspent(self):

View File

@@ -532,23 +532,6 @@ class Interface(threading.Thread):
return self.unanswered_requests == {}
def synchronous_get(self, requests, timeout=100000000):
# todo: use generators, unanswered_requests should be a list of arrays...
queue = Queue.Queue()
ids = self.send(requests, lambda i,r: queue.put(r))
id2 = ids[:]
res = {}
while ids:
r = queue.get(True, timeout)
_id = r.get('id')
if _id in ids:
ids.remove(_id)
res[_id] = r.get('result')
out = []
for _id in id2:
out.append(res[_id])
return out
def start(self, queue):
self.queue = queue

View File

@@ -226,9 +226,26 @@ class Network(threading.Thread):
with self.lock: return self.running
def synchronous_get(self, requests, timeout=100000000):
queue = Queue.Queue()
ids = self.interface.send(requests, lambda i,r: queue.put(r))
id2 = ids[:]
res = {}
while ids:
r = queue.get(True, timeout)
_id = r.get('id')
if _id in ids:
ids.remove(_id)
res[_id] = r.get('result')
out = []
for _id in id2:
out.append(res[_id])
return out
def retrieve_transaction(self, tx_hash, tx_height=0):
import transaction
r = self.interface.synchronous_get([ ('blockchain.transaction.get',[tx_hash, tx_height]) ])[0]
r = self.synchronous_get([ ('blockchain.transaction.get',[tx_hash, tx_height]) ])[0]
if r:
return transaction.Transaction(r)

View File

@@ -1374,7 +1374,7 @@ class Wallet:
# assert not self.is_mine(_addr)
ext_requests.append( ('blockchain.address.get_history', [_addr]) )
ext_h = self.network.interface.synchronous_get(ext_requests)
ext_h = self.network.synchronous_get(ext_requests)
print_error("sync:", ext_requests, ext_h)
height = None
for h in ext_h: