Browse Source

network: change broadcast_transaction api

raise exceptions instead of weird return values
closes #4433
3.3.3.1
SomberNight 6 years ago
parent
commit
87b05e1c9e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/gui/kivy/main_window.py
  2. 8
      electrum/gui/qt/main_window.py
  3. 11
      electrum/gui/stdio.py
  4. 12
      electrum/gui/text.py
  5. 12
      electrum/network.py

11
electrum/gui/kivy/main_window.py

@ -887,9 +887,14 @@ class ElectrumWindow(App):
Clock.schedule_once(lambda dt: on_success(tx))
def _broadcast_thread(self, tx, on_complete):
ok, txid = self.network.run_from_another_thread(
self.network.broadcast_transaction(tx))
Clock.schedule_once(lambda dt: on_complete(ok, txid))
try:
self.network.run_from_another_thread(self.network.broadcast_transaction(tx))
except Exception as e:
ok, msg = False, repr(e)
else:
ok, msg = True, tx.txid()
Clock.schedule_once(lambda dt: on_complete(ok, msg))
def broadcast(self, tx, pr=None):
def on_complete(ok, msg):

8
electrum/gui/qt/main_window.py

@ -1639,8 +1639,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
if pr and pr.has_expired():
self.payment_request = None
return False, _("Payment request has expired")
status, msg = self.network.run_from_another_thread(
self.network.broadcast_transaction(tx))
try:
self.network.run_from_another_thread(self.network.broadcast_transaction(tx))
except Exception as e:
status, msg = False, repr(e)
else:
status, msg = True, tx.txid()
if pr and status is True:
self.invoices.set_paid(pr, tx.txid())
self.invoices.save()

11
electrum/gui/stdio.py

@ -203,15 +203,14 @@ class ElectrumGui:
self.wallet.labels[tx.txid()] = self.str_description
print(_("Please wait..."))
status, msg = self.network.run_from_another_thread(
self.network.broadcast_transaction(tx))
if status:
try:
self.network.run_from_another_thread(self.network.broadcast_transaction(tx))
except Exception as e:
print(repr(e))
else:
print(_('Payment sent.'))
#self.do_clear()
#self.update_contacts_tab()
else:
print(_('Error'))
def network_dialog(self):
print("use 'electrum setconfig server/proxy' to change your network settings")

12
electrum/gui/text.py

@ -367,16 +367,14 @@ class ElectrumGui:
self.wallet.labels[tx.txid()] = self.str_description
self.show_message(_("Please wait..."), getchar=False)
status, msg = self.network.run_from_another_thread(
self.network.broadcast_transaction(tx))
if status:
try:
self.network.run_from_another_thread(self.network.broadcast_transaction(tx))
except Exception as e:
self.show_message(repr(e))
else:
self.show_message(_('Payment sent.'))
self.do_clear()
#self.update_contacts_tab()
else:
self.show_message(_('Error'))
def show_message(self, message, getchar = True):
w = self.w

12
electrum/network.py

@ -676,16 +676,10 @@ class Network(PrintError):
@best_effort_reliable
async def broadcast_transaction(self, tx, timeout=10):
try:
out = await self.interface.session.send_request('blockchain.transaction.broadcast', [str(tx)], timeout=timeout)
except RequestTimedOut as e:
return False, "error: operation timed out"
except Exception as e:
return False, "error: " + str(e)
out = await self.interface.session.send_request('blockchain.transaction.broadcast', [str(tx)], timeout=timeout)
if out != tx.txid():
return False, "error: " + out
return True, out
raise Exception(out)
return out # txid
@best_effort_reliable
async def request_chunk(self, height, tip=None, *, can_return_early=False):

Loading…
Cancel
Save