make sure the broadcast tx thread always times out
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -204,7 +204,6 @@ class Abstract_Wallet(PrintError):
|
||||
self.up_to_date = False
|
||||
self.lock = threading.Lock()
|
||||
self.transaction_lock = threading.Lock()
|
||||
self.tx_event = threading.Event()
|
||||
|
||||
self.check_history()
|
||||
|
||||
@@ -1038,33 +1037,6 @@ class Abstract_Wallet(PrintError):
|
||||
if keypairs:
|
||||
tx.sign(keypairs)
|
||||
|
||||
|
||||
def sendtx(self, tx):
|
||||
# synchronous
|
||||
h = self.send_tx(tx)
|
||||
self.tx_event.wait()
|
||||
return self.receive_tx(h, tx)
|
||||
|
||||
def send_tx(self, tx):
|
||||
# asynchronous
|
||||
self.tx_event.clear()
|
||||
# fixme: this does not handle the case where server does not answer
|
||||
if not self.network.interface:
|
||||
raise BaseException("Not connected")
|
||||
self.network.send([('blockchain.transaction.broadcast', [str(tx)])], self.on_broadcast)
|
||||
return tx.hash()
|
||||
|
||||
def on_broadcast(self, r):
|
||||
self.tx_result = r.get('result')
|
||||
self.tx_event.set()
|
||||
|
||||
def receive_tx(self, tx_hash, tx):
|
||||
out = self.tx_result
|
||||
if out != tx_hash:
|
||||
return False, "error: " + out
|
||||
run_hook('receive_tx', tx, self)
|
||||
return True, out
|
||||
|
||||
def update_password(self, old_password, new_password):
|
||||
if new_password == '':
|
||||
new_password = None
|
||||
|
||||
Reference in New Issue
Block a user