tdo not raise BaseException - electrum - Electrum Bitcoin wallet (HTM) git clone https://git.parazyd.org/electrum (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules --- (DIR) commit 7b507905841df3f685b92b2381e9ea8838f4ac78 (DIR) parent 76e67daadd658eb647669bd8e595c0f72cc93086 (HTM) Author: SomberNight <somber.night@protonmail.com> Date: Sat, 7 Apr 2018 17:10:30 +0200 do not raise BaseException Diffstat: M contrib/build-osx/osx.spec | 2 +- M contrib/build-wine/deterministic.s… | 2 +- M contrib/deterministic-build/find_r… | 2 +- M contrib/make_download | 2 +- M electrum | 2 +- M lib/base_wizard.py | 4 ++-- M lib/blockchain.py | 10 +++++----- M lib/commands.py | 14 +++++++------- M lib/dnssec.py | 4 ++-- M lib/network.py | 6 +++--- M lib/paymentrequest.py | 12 ++++++------ M lib/plugins.py | 2 +- M lib/simple_config.py | 6 +++--- M lib/transaction.py | 4 ++-- M lib/util.py | 6 +++--- M lib/wallet.py | 16 ++++++++-------- M plugins/digitalbitbox/digitalbitbo… | 2 +- M plugins/keepkey/plugin.py | 2 +- M plugins/labels/labels.py | 4 ++-- M plugins/ledger/ledger.py | 2 +- M plugins/trustedcoin/trustedcoin.py | 2 +- 21 files changed, 53 insertions(+), 53 deletions(-) --- (DIR) diff --git a/contrib/build-osx/osx.spec b/contrib/build-osx/osx.spec t@@ -15,7 +15,7 @@ for i, x in enumerate(sys.argv): VERSION = sys.argv[i+1] break else: - raise BaseException('no version') + raise Exception('no version') electrum = os.path.abspath(".") + "/" block_cipher = None (DIR) diff --git a/contrib/build-wine/deterministic.spec b/contrib/build-wine/deterministic.spec t@@ -8,7 +8,7 @@ for i, x in enumerate(sys.argv): cmdline_name = sys.argv[i+1] break else: - raise BaseException('no name') + raise Exception('no name') PYTHON_VERSION = '3.5.4' PYHOME = 'c:/python' + PYTHON_VERSION (DIR) diff --git a/contrib/deterministic-build/find_restricted_dependencies.py b/contrib/deterministic-build/find_restricted_dependencies.py t@@ -23,7 +23,7 @@ for p in sys.stdin.read().split(): try: data = requests.get("https://pypi.org/pypi/{}/{}/json".format(p, v)).json()["info"] except ValueError: - raise BaseException("Package could not be found: {}=={}".format(p, v)) + raise Exception("Package could not be found: {}=={}".format(p, v)) try: for r in data["requires_dist"]: if ";" not in r: (DIR) diff --git a/contrib/make_download b/contrib/make_download t@@ -41,7 +41,7 @@ for k, n in files.items(): string = re.sub("<div id=\"%s\">(.*?)</div>"%k, '', string, flags=re.DOTALL + re.MULTILINE) continue if os.system("gpg --verify %s"%sigpath) != 0: - raise BaseException(sigpath) + raise Exception(sigpath) string = string.replace("##link_%s##"%k, link) (DIR) diff --git a/electrum b/electrum t@@ -351,7 +351,7 @@ if __name__ == '__main__': sys.argv[i] = sys.stdin.read() break else: - raise BaseException('Cannot get argument from stdin') + raise Exception('Cannot get argument from stdin') elif arg == '?': sys.argv[i] = input("Enter argument:") elif arg == ':': (DIR) diff --git a/lib/base_wizard.py b/lib/base_wizard.py t@@ -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 t@@ -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)) (DIR) diff --git a/lib/blockchain.py b/lib/blockchain.py t@@ -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 t@@ -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): (DIR) diff --git a/lib/commands.py b/lib/commands.py t@@ -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) t@@ -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): t@@ -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): t@@ -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') t@@ -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('') t@@ -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') t@@ -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) (DIR) diff --git a/lib/dnssec.py b/lib/dnssec.py t@@ -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) t@@ -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) (DIR) diff --git a/lib/network.py b/lib/network.py t@@ -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: t@@ -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 t@@ -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): (DIR) diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py t@@ -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 t@@ -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: t@@ -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): t@@ -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 (DIR) diff --git a/lib/plugins.py b/lib/plugins.py t@@ -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 (DIR) diff --git a/lib/simple_config.py b/lib/simple_config.py t@@ -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) t@@ -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: t@@ -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) (DIR) diff --git a/lib/transaction.py b/lib/transaction.py t@@ -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 t@@ -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: (DIR) diff --git a/lib/util.py b/lib/util.py t@@ -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 t@@ -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'] (DIR) diff --git a/lib/wallet.py b/lib/wallet.py t@@ -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 t@@ -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() t@@ -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 t@@ -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 t@@ -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: t@@ -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() (DIR) diff --git a/plugins/digitalbitbox/digitalbitbox.py b/plugins/digitalbitbox/digitalbitbox.py t@@ -107,7 +107,7 @@ class DigitalBitbox_Client(): xpub = serialize_xpub(xtype, c, cK, depth, fingerprint, child_number) return xpub else: - raise BaseException('no reply') + raise Exception('no reply') def dbb_has_password(self): (DIR) diff --git a/plugins/keepkey/plugin.py b/plugins/keepkey/plugin.py t@@ -344,7 +344,7 @@ class KeepKeyCompatiblePlugin(HW_PluginBase): elif addrtype == constants.net.ADDRTYPE_P2SH: txoutputtype.script_type = self.types.PAYTOSCRIPTHASH else: - raise BaseException('addrtype: ' + str(addrtype)) + raise Exception('addrtype: ' + str(addrtype)) txoutputtype.address = address return txoutputtype (DIR) diff --git a/plugins/labels/labels.py b/plugins/labels/labels.py t@@ -72,10 +72,10 @@ class LabelsPlugin(BasePlugin): kwargs['headers']['Content-Type'] = 'application/json' response = requests.request(method, url, **kwargs) if response.status_code != 200: - raise BaseException(response.status_code, response.text) + raise Exception(response.status_code, response.text) response = response.json() if "error" in response: - raise BaseException(response["error"]) + raise Exception(response["error"]) return response def do_request_safe(self, *args, **kwargs): (DIR) diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py t@@ -188,7 +188,7 @@ class Ledger_Client(): self.perform_hw1_preflight() except BTChipException as e: if (e.sw == 0x6d00 or e.sw == 0x6700): - raise BaseException(_("Device not in Bitcoin mode")) from e + raise Exception(_("Device not in Bitcoin mode")) from e raise e self.preflightDone = True (DIR) diff --git a/plugins/trustedcoin/trustedcoin.py b/plugins/trustedcoin/trustedcoin.py t@@ -406,7 +406,7 @@ class TrustedCoinPlugin(BasePlugin): xprv1, xpub1 = self.get_xkeys(seed, passphrase, "m/0'/") xprv2, xpub2 = self.get_xkeys(seed, passphrase, "m/1'/") else: - raise BaseException('unrecognized seed length: {} words'.format(n)) + raise Exception('unrecognized seed length: {} words'.format(n)) return xprv1, xpub1, xprv2, xpub2 def create_keystore(self, wizard, seed, passphrase):