Browse Source

wallet: fix offline hw wallet signing when not specifying --offline

closes #5532
master
SomberNight 6 years ago
parent
commit
a10dc04b28
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 7
      electrum/interface.py
  2. 9
      electrum/network.py
  3. 15
      electrum/wallet.py

7
electrum/interface.py

@ -157,7 +157,10 @@ class NotificationSession(RPCSession):
self.interface.logger.debug(msg) self.interface.logger.debug(msg)
class GracefulDisconnect(Exception): class NetworkException(Exception): pass
class GracefulDisconnect(NetworkException):
log_level = logging.INFO log_level = logging.INFO
def __init__(self, *args, log_level=None, **kwargs): def __init__(self, *args, log_level=None, **kwargs):
@ -173,7 +176,7 @@ class RequestTimedOut(GracefulDisconnect):
class ErrorParsingSSLCert(Exception): pass class ErrorParsingSSLCert(Exception): pass
class ErrorGettingSSLCertFromServer(Exception): pass class ErrorGettingSSLCertFromServer(Exception): pass
class ConnectError(Exception): pass class ConnectError(NetworkException): pass
class _RSClient(RSClient): class _RSClient(RSClient):

9
electrum/network.py

@ -52,7 +52,8 @@ from . import blockchain
from . import bitcoin from . import bitcoin
from .blockchain import Blockchain, HEADER_SIZE from .blockchain import Blockchain, HEADER_SIZE
from .interface import (Interface, serialize_server, deserialize_server, from .interface import (Interface, serialize_server, deserialize_server,
RequestTimedOut, NetworkTimeout, BUCKET_NAME_OF_ONION_SERVERS) RequestTimedOut, NetworkTimeout, BUCKET_NAME_OF_ONION_SERVERS,
NetworkException)
from .version import PROTOCOL_VERSION from .version import PROTOCOL_VERSION
from .simple_config import SimpleConfig from .simple_config import SimpleConfig
from .i18n import _ from .i18n import _
@ -174,10 +175,10 @@ def deserialize_proxy(s: str) -> Optional[dict]:
return proxy return proxy
class BestEffortRequestFailed(Exception): pass class BestEffortRequestFailed(NetworkException): pass
class TxBroadcastError(Exception): class TxBroadcastError(NetworkException):
def get_message_for_gui(self): def get_message_for_gui(self):
raise NotImplementedError() raise NotImplementedError()
@ -205,7 +206,7 @@ class TxBroadcastUnknownError(TxBroadcastError):
_("Consider trying to connect to a different server, or updating Electrum.")) _("Consider trying to connect to a different server, or updating Electrum."))
class UntrustedServerReturnedError(Exception): class UntrustedServerReturnedError(NetworkException):
def __init__(self, *, original_exception): def __init__(self, *, original_exception):
self.original_exception = original_exception self.original_exception = original_exception

15
electrum/wallet.py

@ -61,7 +61,7 @@ from .address_synchronizer import (AddressSynchronizer, TX_HEIGHT_LOCAL,
from .paymentrequest import (PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED, from .paymentrequest import (PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED,
InvoiceStore) InvoiceStore)
from .contacts import Contacts from .contacts import Contacts
from .interface import RequestTimedOut from .interface import NetworkException
from .ecc_fast import is_using_fast_ecc from .ecc_fast import is_using_fast_ecc
from .mnemonic import Mnemonic from .mnemonic import Mnemonic
from .logging import get_logger from .logging import get_logger
@ -1060,7 +1060,7 @@ class Abstract_Wallet(AddressSynchronizer):
return True return True
return False return False
def get_input_tx(self, tx_hash, ignore_timeout=False): def get_input_tx(self, tx_hash, *, ignore_network_issues=False):
# First look up an input transaction in the wallet where it # First look up an input transaction in the wallet where it
# will likely be. If co-signing a transaction it may not have # will likely be. If co-signing a transaction it may not have
# all the input txs, in which case we ask the network. # all the input txs, in which case we ask the network.
@ -1069,9 +1069,10 @@ class Abstract_Wallet(AddressSynchronizer):
try: try:
raw_tx = self.network.run_from_another_thread( raw_tx = self.network.run_from_another_thread(
self.network.get_transaction(tx_hash, timeout=10)) self.network.get_transaction(tx_hash, timeout=10))
except RequestTimedOut as e: except NetworkException as e:
self.logger.info(f'getting input txn from network timed out for {tx_hash}') self.logger.info(f'got network error getting input txn. err: {repr(e)}. txid: {tx_hash}. '
if not ignore_timeout: f'if you are intentionally offline, consider using the --offline flag')
if not ignore_network_issues:
raise e raise e
else: else:
tx = Transaction(raw_tx) tx = Transaction(raw_tx)
@ -1082,8 +1083,8 @@ class Abstract_Wallet(AddressSynchronizer):
for txin in tx.inputs(): for txin in tx.inputs():
tx_hash = txin['prevout_hash'] tx_hash = txin['prevout_hash']
# segwit inputs might not be needed for some hw wallets # segwit inputs might not be needed for some hw wallets
ignore_timeout = Transaction.is_segwit_input(txin) ignore_network_issues = Transaction.is_segwit_input(txin)
txin['prev_tx'] = self.get_input_tx(tx_hash, ignore_timeout) txin['prev_tx'] = self.get_input_tx(tx_hash, ignore_network_issues=ignore_network_issues)
# add output info for hw wallets # add output info for hw wallets
info = {} info = {}
xpubs = self.get_master_public_keys() xpubs = self.get_master_public_keys()

Loading…
Cancel
Save