1
0

Catch wallet file related exceptions in Qt wizard.

This commit is contained in:
SomberNight
2018-03-17 22:56:20 +01:00
parent 680df7d6b6
commit 61a45edee0
7 changed files with 63 additions and 38 deletions

View File

@@ -44,7 +44,8 @@ import sys
from .i18n import _
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
format_satoshis, NoDynamicFeeEstimates, TimeoutException)
format_satoshis, NoDynamicFeeEstimates, TimeoutException,
WalletFileException, BitcoinException)
from .bitcoin import *
from .version import *
@@ -131,6 +132,7 @@ def sweep_preparations(privkeys, network, imax=100):
find_utxos_for_privkey('p2pk', privkey, compressed)
if not inputs:
raise BaseException(_('No inputs found. (Note that inputs need to be confirmed)'))
# FIXME actually inputs need not be confirmed now, see https://github.com/kyuupichan/electrumx/issues/365
return inputs, keypairs
@@ -335,7 +337,7 @@ class Abstract_Wallet(PrintError):
addrs = self.get_receiving_addresses()
if len(addrs) > 0:
if not bitcoin.is_address(addrs[0]):
raise Exception('The addresses in this wallet are not bitcoin addresses.')
raise WalletFileException('The addresses in this wallet are not bitcoin addresses.')
def synchronize(self):
pass
@@ -1166,7 +1168,7 @@ class Abstract_Wallet(PrintError):
_type, data, value = o
if _type == TYPE_ADDRESS:
if not is_address(data):
raise BaseException("Invalid bitcoin address:" + data)
raise BaseException("Invalid bitcoin address: {}".format(data))
if value == '!':
if i_max is not None:
raise BaseException("More than one output set to spend max")
@@ -1339,7 +1341,7 @@ class Abstract_Wallet(PrintError):
def bump_fee(self, tx, delta):
if tx.is_final():
raise BaseException(_("Cannot bump fee: transaction is final"))
raise BaseException(_('Cannot bump fee') + ': ' + _('transaction is final'))
inputs = copy.deepcopy(tx.inputs())
outputs = copy.deepcopy(tx.outputs())
for txin in inputs:
@@ -1370,7 +1372,7 @@ class Abstract_Wallet(PrintError):
if delta > 0:
continue
if delta > 0:
raise BaseException(_('Cannot bump fee: could not find suitable outputs'))
raise BaseException(_('Cannot bump fee') + ': ' + _('could not find suitable outputs'))
locktime = self.get_local_height()
tx_new = Transaction.from_io(inputs, outputs, locktime=locktime)
tx_new.BIP_LI01_sort()
@@ -1944,14 +1946,14 @@ class Imported_Wallet(Simple_Wallet):
txin_type, pubkey = self.keystore.import_privkey(sec, pw)
except Exception:
neutered_privkey = str(sec)[:3] + '..' + str(sec)[-2:]
raise BaseException('Invalid private key', neutered_privkey)
raise BitcoinException('Invalid private key: {}'.format(neutered_privkey))
if txin_type in ['p2pkh', 'p2wpkh', 'p2wpkh-p2sh']:
if redeem_script is not None:
raise BaseException('Cannot use redeem script with', txin_type)
raise BitcoinException('Cannot use redeem script with script type {}'.format(txin_type))
addr = bitcoin.pubkey_to_address(txin_type, pubkey)
elif txin_type in ['p2sh', 'p2wsh', 'p2wsh-p2sh']:
if redeem_script is None:
raise BaseException('Redeem script required for', txin_type)
raise BitcoinException('Redeem script required for script type {}'.format(txin_type))
addr = bitcoin.redeem_script_to_address(txin_type, redeem_script)
else:
raise NotImplementedError(txin_type)