electrum

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

commit bc2a421d8776a8bc870a6e9521e004cd8e299b97
parent 76ff2f53c504b8dc9e7a5fce3e25634267e1ec02
Author: SomberNight <somber.night@protonmail.com>
Date:   Mon,  4 Feb 2019 14:51:04 +0100

network: clean up broadcast_transaction

Handle all exceptions in network.py, instead of in gui code.
Send some exceptions to crash reporter; previously gui code
would suppress them.

Diffstat:
Melectrum/network.py | 17+++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/electrum/network.py b/electrum/network.py @@ -43,7 +43,7 @@ from aiohttp import ClientResponse from . import util from .util import (PrintError, print_error, log_exceptions, ignore_exceptions, - bfh, SilentTaskGroup, make_aiohttp_session) + bfh, SilentTaskGroup, make_aiohttp_session, send_exception_to_crash_reporter) from .bitcoin import COIN from . import constants @@ -188,6 +188,13 @@ class TxBroadcastServerReturnedError(TxBroadcastError): str(self)) +class TxBroadcastUnknownError(TxBroadcastError): + def get_message_for_gui(self): + return "{}\n{}" \ + .format(_("Unknown error when broadcasting the transaction."), + _("Consider trying to connect to a different server, or updating Electrum.")) + + INSTANCE = None @@ -764,9 +771,15 @@ class Network(PrintError): try: out = await self.interface.session.send_request('blockchain.transaction.broadcast', [str(tx)], timeout=timeout) # note: both 'out' and exception messages are untrusted input from the server - except aiorpcx.jsonrpc.RPCError as e: + except (RequestTimedOut, asyncio.CancelledError, asyncio.TimeoutError): + raise # pass-through + except aiorpcx.jsonrpc.CodeMessageError as e: self.print_error(f"broadcast_transaction error: {repr(e)}") raise TxBroadcastServerReturnedError(self.sanitize_tx_broadcast_response(e.message)) from e + except BaseException as e: # intentional BaseException for sanity! + self.print_error(f"broadcast_transaction error2: {repr(e)}") + send_exception_to_crash_reporter(e) + raise TxBroadcastUnknownError() from e if out != tx.txid(): self.print_error(f"unexpected txid for broadcast_transaction: {out} != {tx.txid()}") raise TxBroadcastHashMismatch(_("Server returned unexpected transaction ID."))