electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 87b05e1c9e1b7163e5f100765656b26b96c8a144
parent c7833b8bc036cc4661edd3fa55d50c56833727e1
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed, 10 Oct 2018 15:56:41 +0200

network: change broadcast_transaction api

raise exceptions instead of weird return values
closes #4433

Diffstat:
Melectrum/gui/kivy/main_window.py | 11++++++++---
Melectrum/gui/qt/main_window.py | 8++++++--
Melectrum/gui/stdio.py | 11+++++------
Melectrum/gui/text.py | 12+++++-------
Melectrum/network.py | 12+++---------
5 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/electrum/gui/kivy/main_window.py b/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): diff --git a/electrum/gui/qt/main_window.py b/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() diff --git a/electrum/gui/stdio.py b/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") diff --git a/electrum/gui/text.py b/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 diff --git a/electrum/network.py b/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):