1
0

do not raise BaseException

This commit is contained in:
SomberNight
2018-04-07 17:10:30 +02:00
parent 76e67daadd
commit 7b50790584
21 changed files with 53 additions and 53 deletions

View File

@@ -69,7 +69,7 @@ class BaseWizard(object):
f = getattr(self, action)
f(*args)
else:
raise BaseException("unknown action", action)
raise Exception("unknown action", action)
def can_go_back(self):
return len(self.stack)>1
@@ -364,7 +364,7 @@ class BaseWizard(object):
self.load_2fa()
self.run('on_restore_seed', seed, is_ext)
else:
raise BaseException('Unknown seed type', self.seed_type)
raise Exception('Unknown seed type', self.seed_type)
def on_restore_bip39(self, seed, passphrase):
f = lambda x: self.run('on_bip43', seed, passphrase, str(x))

View File

@@ -156,14 +156,14 @@ class Blockchain(util.PrintError):
def verify_header(self, header, prev_hash, target):
_hash = hash_header(header)
if prev_hash != header.get('prev_block_hash'):
raise BaseException("prev hash mismatch: %s vs %s" % (prev_hash, header.get('prev_block_hash')))
raise Exception("prev hash mismatch: %s vs %s" % (prev_hash, header.get('prev_block_hash')))
if constants.net.TESTNET:
return
bits = self.target_to_bits(target)
if bits != header.get('bits'):
raise BaseException("bits mismatch: %s vs %s" % (bits, header.get('bits')))
raise Exception("bits mismatch: %s vs %s" % (bits, header.get('bits')))
if int('0x' + _hash, 16) > target:
raise BaseException("insufficient proof of work: %s vs target %s" % (int('0x' + _hash, 16), target))
raise Exception("insufficient proof of work: %s vs target %s" % (int('0x' + _hash, 16), target))
def verify_chunk(self, index, data):
num = len(data) // 80
@@ -306,10 +306,10 @@ class Blockchain(util.PrintError):
def bits_to_target(self, bits):
bitsN = (bits >> 24) & 0xff
if not (bitsN >= 0x03 and bitsN <= 0x1d):
raise BaseException("First part of bits should be in [0x03, 0x1d]")
raise Exception("First part of bits should be in [0x03, 0x1d]")
bitsBase = bits & 0xffffff
if not (bitsBase >= 0x8000 and bitsBase <= 0x7fffff):
raise BaseException("Second part of bits should be in [0x8000, 0x7fffff]")
raise Exception("Second part of bits should be in [0x8000, 0x7fffff]")
return bitsBase << (8 * (bitsN-3))
def target_to_bits(self, target):

View File

@@ -81,7 +81,7 @@ def command(s):
wallet = args[0].wallet
password = kwargs.get('password')
if c.requires_wallet and wallet is None:
raise BaseException("wallet not loaded. Use 'electrum daemon load_wallet'")
raise Exception("wallet not loaded. Use 'electrum daemon load_wallet'")
if c.requires_password and password is None and wallet.has_password():
return {'error': 'Password required' }
return func(*args, **kwargs)
@@ -125,7 +125,7 @@ class Commands:
@command('')
def create(self, segwit=False):
"""Create a new wallet"""
raise BaseException('Not a JSON-RPC command')
raise Exception('Not a JSON-RPC command')
@command('wn')
def restore(self, text):
@@ -133,7 +133,7 @@ class Commands:
public key, a master private key, a list of bitcoin addresses
or bitcoin private keys. If you want to be prompted for your
seed, type '?' or ':' (concealed) """
raise BaseException('Not a JSON-RPC command')
raise Exception('Not a JSON-RPC command')
@command('wp')
def password(self, password=None, new_password=None):
@@ -377,7 +377,7 @@ class Commands:
return None
out = self.wallet.contacts.resolve(x)
if out.get('type') == 'openalias' and self.nocheck is False and out.get('validated') is False:
raise BaseException('cannot verify alias', x)
raise Exception('cannot verify alias', x)
return out['address']
@command('n')
@@ -522,7 +522,7 @@ class Commands:
if raw:
tx = Transaction(raw)
else:
raise BaseException("Unknown transaction")
raise Exception("Unknown transaction")
return tx.as_dict()
@command('')
@@ -551,7 +551,7 @@ class Commands:
"""Return a payment request"""
r = self.wallet.get_payment_request(key, self.config)
if not r:
raise BaseException("Request not found")
raise Exception("Request not found")
return self._format_request(r)
#@command('w')
@@ -618,7 +618,7 @@ class Commands:
"Sign payment request with an OpenAlias"
alias = self.config.get('alias')
if not alias:
raise BaseException('No alias in your configuration')
raise Exception('No alias in your configuration')
alias_addr = self.wallet.contacts.resolve(alias)['address']
self.wallet.sign_payment_request(address, alias, alias_addr, password)

View File

@@ -199,7 +199,7 @@ def check_query(ns, sub, _type, keys):
elif answer[1].rdtype == dns.rdatatype.RRSIG:
rrset, rrsig = answer
else:
raise BaseException('No signature set in record')
raise Exception('No signature set in record')
if keys is None:
keys = {dns.name.from_text(sub):rrset}
dns.dnssec.validate(rrset, rrsig, keys)
@@ -248,7 +248,7 @@ def get_and_validate(ns, url, _type):
continue
break
else:
raise BaseException("DS does not match DNSKEY")
raise Exception("DS does not match DNSKEY")
# set key for next iteration
keys = {name: rrset}
# get TXT record (signed by zone)

View File

@@ -923,7 +923,7 @@ class Network(util.DaemonThread):
self.notify('updated')
else:
raise BaseException(interface.mode)
raise Exception(interface.mode)
# If not finished, get the next header
if next_height:
if interface.mode == 'catch_up' and interface.tip > next_height + 50:
@@ -1055,7 +1055,7 @@ class Network(util.DaemonThread):
self.switch_to_interface(i.server)
break
else:
raise BaseException('blockchain not found', index)
raise Exception('blockchain not found', index)
if self.interface:
server = self.interface.server
@@ -1074,7 +1074,7 @@ class Network(util.DaemonThread):
except queue.Empty:
raise util.TimeoutException(_('Server did not answer'))
if r.get('error'):
raise BaseException(r.get('error'))
raise Exception(r.get('error'))
return r.get('result')
def broadcast(self, tx, timeout=30):

View File

@@ -95,7 +95,7 @@ def get_payment_request(url):
data = None
error = "payment URL not pointing to a valid file"
else:
raise BaseException("unknown scheme", url)
raise Exception("unknown scheme", url)
pr = PaymentRequest(data, error)
return pr
@@ -340,9 +340,9 @@ def verify_cert_chain(chain):
x.check_date()
else:
if not x.check_ca():
raise BaseException("ERROR: Supplied CA Certificate Error")
raise Exception("ERROR: Supplied CA Certificate Error")
if not cert_num > 1:
raise BaseException("ERROR: CA Certificate Chain Not Provided by Payment Processor")
raise Exception("ERROR: CA Certificate Chain Not Provided by Payment Processor")
# if the root CA is not supplied, add it to the chain
ca = x509_chain[cert_num-1]
if ca.getFingerprint() not in ca_list:
@@ -352,7 +352,7 @@ def verify_cert_chain(chain):
root = ca_list[f]
x509_chain.append(root)
else:
raise BaseException("Supplied CA Not Found in Trusted CA Store.")
raise Exception("Supplied CA Not Found in Trusted CA Store.")
# verify the chain of signatures
cert_num = len(x509_chain)
for i in range(1, cert_num):
@@ -373,10 +373,10 @@ def verify_cert_chain(chain):
hashBytes = bytearray(hashlib.sha512(data).digest())
verify = pubkey.verify(sig, x509.PREFIX_RSA_SHA512 + hashBytes)
else:
raise BaseException("Algorithm not supported")
raise Exception("Algorithm not supported")
util.print_error(self.error, algo.getComponentByName('algorithm'))
if not verify:
raise BaseException("Certificate not Signed by Provided CA Certificate Chain")
raise Exception("Certificate not Signed by Provided CA Certificate Chain")
return x509_chain[0], ca

View File

@@ -403,7 +403,7 @@ class DeviceMgr(ThreadJob, PrintError):
def client_for_keystore(self, plugin, handler, keystore, force_pair):
self.print_error("getting client for keystore")
if handler is None:
raise BaseException(_("Handler not found for") + ' ' + plugin.name + '\n' + _("A library is probably missing."))
raise Exception(_("Handler not found for") + ' ' + plugin.name + '\n' + _("A library is probably missing."))
handler.update_status(False)
devices = self.scan_devices()
xpub = keystore.xpub

View File

@@ -107,7 +107,7 @@ class SimpleConfig(PrintError):
# Make directory if it does not yet exist.
if not os.path.exists(path):
if os.path.islink(path):
raise BaseException('Dangling link: ' + path)
raise Exception('Dangling link: ' + path)
os.mkdir(path)
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
@@ -190,7 +190,7 @@ class SimpleConfig(PrintError):
if cur_version > max_version:
return False
elif cur_version < min_version:
raise BaseException(
raise Exception(
('config upgrade: unexpected version %d (should be %d-%d)'
% (cur_version, min_version, max_version)))
else:
@@ -240,7 +240,7 @@ class SimpleConfig(PrintError):
dirpath = os.path.join(self.path, "wallets")
if not os.path.exists(dirpath):
if os.path.islink(dirpath):
raise BaseException('Dangling link: ' + dirpath)
raise Exception('Dangling link: ' + dirpath)
os.mkdir(dirpath)
os.chmod(dirpath, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

View File

@@ -583,7 +583,7 @@ class Transaction:
elif isinstance(raw, dict):
self.raw = raw['hex']
else:
raise BaseException("cannot initialize transaction", raw)
raise Exception("cannot initialize transaction", raw)
self._inputs = None
self._outputs = None
self.locktime = 0
@@ -747,7 +747,7 @@ class Transaction:
else:
witness = txin.get('witness', None)
if not witness:
raise BaseException('wrong txin type:', txin['type'])
raise Exception('wrong txin type:', txin['type'])
if self.is_txin_complete(txin) or estimate_size:
value_field = ''
else:

View File

@@ -565,12 +565,12 @@ def parse_URI(uri, on_pr=None):
if ':' not in uri:
if not bitcoin.is_address(uri):
raise BaseException("Not a bitcoin address")
raise Exception("Not a bitcoin address")
return {'address': uri}
u = urllib.parse.urlparse(uri)
if u.scheme != 'bitcoin':
raise BaseException("Not a bitcoin URI")
raise Exception("Not a bitcoin URI")
address = u.path
# python for android fails to parse query
@@ -587,7 +587,7 @@ def parse_URI(uri, on_pr=None):
out = {k: v[0] for k, v in pq.items()}
if address:
if not bitcoin.is_address(address):
raise BaseException("Invalid bitcoin address:" + address)
raise Exception("Invalid bitcoin address:" + address)
out['address'] = address
if 'amount' in out:
am = out['amount']

View File

@@ -132,7 +132,7 @@ def sweep_preparations(privkeys, network, imax=100):
# we also search for pay-to-pubkey outputs
find_utxos_for_privkey('p2pk', privkey, compressed)
if not inputs:
raise BaseException(_('No inputs found. (Note that inputs need to be confirmed)'))
raise Exception(_('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
@@ -145,9 +145,9 @@ def sweep(privkeys, network, config, recipient, fee=None, imax=100):
tx = Transaction.from_io(inputs, outputs)
fee = config.estimate_fee(tx.estimated_size())
if total - fee < 0:
raise BaseException(_('Not enough funds on address.') + '\nTotal: %d satoshis\nFee: %d'%(total, fee))
raise Exception(_('Not enough funds on address.') + '\nTotal: %d satoshis\nFee: %d'%(total, fee))
if total - fee < dust_threshold(network):
raise BaseException(_('Not enough funds on address.') + '\nTotal: %d satoshis\nFee: %d\nDust Threshold: %d'%(total, fee, dust_threshold(network)))
raise Exception(_('Not enough funds on address.') + '\nTotal: %d satoshis\nFee: %d\nDust Threshold: %d'%(total, fee, dust_threshold(network)))
outputs = [(TYPE_ADDRESS, recipient, total - fee)]
locktime = network.get_local_height()
@@ -1197,10 +1197,10 @@ class Abstract_Wallet(PrintError):
_type, data, value = o
if _type == TYPE_ADDRESS:
if not is_address(data):
raise BaseException("Invalid bitcoin address: {}".format(data))
raise Exception("Invalid bitcoin address: {}".format(data))
if value == '!':
if i_max is not None:
raise BaseException("More than one output set to spend max")
raise Exception("More than one output set to spend max")
i_max = i
# Avoid index-out-of-range with inputs[0] below
@@ -1239,7 +1239,7 @@ class Abstract_Wallet(PrintError):
elif callable(fixed_fee):
fee_estimator = fixed_fee
else:
raise BaseException('Invalid argument fixed_fee: %s' % fixed_fee)
raise Exception('Invalid argument fixed_fee: %s' % fixed_fee)
if i_max is None:
# Let the coin chooser select the coins to spend
@@ -1370,7 +1370,7 @@ class Abstract_Wallet(PrintError):
def bump_fee(self, tx, delta):
if tx.is_final():
raise BaseException(_('Cannot bump fee') + ': ' + _('transaction is final'))
raise Exception(_('Cannot bump fee') + ': ' + _('transaction is final'))
inputs = copy.deepcopy(tx.inputs())
outputs = copy.deepcopy(tx.outputs())
for txin in inputs:
@@ -1401,7 +1401,7 @@ class Abstract_Wallet(PrintError):
if delta > 0:
continue
if delta > 0:
raise BaseException(_('Cannot bump fee') + ': ' + _('could not find suitable outputs'))
raise Exception(_('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()