1
0

make sure the broadcast tx thread always times out

This commit is contained in:
ThomasV
2016-02-25 08:55:06 +01:00
parent 463818b12d
commit 96f144eb03
6 changed files with 28 additions and 49 deletions

View File

@@ -824,7 +824,21 @@ class Network(util.DaemonThread):
def synchronous_get(self, request, timeout=100000000):
queue = Queue.Queue()
self.send([request], queue.put)
r = queue.get(True, timeout)
try:
r = queue.get(True, timeout)
except Queue.Empty:
raise BaseException('Server did not answer')
if r.get('error'):
raise BaseException(r.get('error'))
return r.get('result')
def broadcast(self, tx, timeout=10):
tx_hash = tx.hash()
try:
r = self.synchronous_get(('blockchain.transaction.broadcast', [str(tx)]), timeout)
except BaseException as e:
return False, "error: " + str(e)
result = r.get('result')
if out != tx_hash:
return False, "error: " + out
return True, out