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

@ -698,7 +698,7 @@ class ElectrumWindow(App):
Clock.schedule_once(lambda dt: on_success(tx))
def _broadcast_thread(self, tx, on_complete):
ok, txid = self.wallet.sendtx(tx)
ok, txid = self.network.broadcast(tx)
Clock.schedule_once(lambda dt: on_complete(ok, txid))
def broadcast(self, tx, pr=None):

View File

@ -1321,14 +1321,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def broadcast_thread():
# non-GUI thread
pr = self.payment_request
if pr is None:
return self.wallet.sendtx(tx)
if pr.has_expired():
if pr and pr.has_expired():
self.payment_request = None
return False, _("Payment request has expired")
status, msg = self.wallet.sendtx(tx)
if not status:
return False, msg
status, msg = self.network.broadcast(tx)
if pr and status is True:
pr.set_paid(tx.hash())
self.invoices.save()
self.payment_request = None

View File

@ -195,10 +195,8 @@ class ElectrumGui:
if self.str_description:
self.wallet.labels[tx.hash()] = self.str_description
h = self.wallet.send_tx(tx)
print(_("Please wait..."))
self.wallet.tx_event.wait()
status, msg = self.wallet.receive_tx( h, tx )
status, msg = self.network.broadcast(tx)
if status:
print(_('Payment sent.'))

View File

@ -337,10 +337,8 @@ class ElectrumGui:
if self.str_description:
self.wallet.labels[tx.hash()] = self.str_description
h = self.wallet.send_tx(tx)
self.show_message(_("Please wait..."), getchar=False)
self.wallet.tx_event.wait()
status, msg = self.wallet.receive_tx( h, tx )
status, msg = self.network.broadcast(tx)
if status:
self.show_message(_('Payment sent.'))

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)
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

View File

@ -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