From 423ed773052cfa7a66ab5dcfae3227b089f39169 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Wed, 6 Nov 2013 18:02:14 +0100 Subject: [PATCH 01/12] allow to connect to one server only This changeset allow to disable block headers retrieval from multiple servers. --- electrum | 1 + lib/network.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/electrum b/electrum index eae7687e..4bac95f2 100755 --- a/electrum +++ b/electrum @@ -84,6 +84,7 @@ def arg_parser(): parser.add_option("-u", "--usb", dest="bitkey", action="store_true", help="Turn on support for hardware wallets (EXPERIMENTAL)") parser.add_option("-G", "--gap", dest="gap_limit", default=None, help="gap limit") parser.add_option("-W", "--password", dest="password", default=None, help="set password for usage with commands (currently only implemented for create command, do not use it for longrunning gui session since the password is visible in /proc)") + parser.add_option("-1", "--oneserver", action="store_true", dest="oneserver", default=False, help="connect to one server only") return parser def print_help(parser): diff --git a/lib/network.py b/lib/network.py index dbbd4047..13f5a868 100644 --- a/lib/network.py +++ b/lib/network.py @@ -22,7 +22,6 @@ DEFAULT_SERVERS = { } -NUM_SERVERS = 8 def filter_protocol(servers, p): @@ -45,6 +44,7 @@ class Network(threading.Thread): self.daemon = True self.config = SimpleConfig(config) if type(config) == type({}) else config self.lock = threading.Lock() + self.num_server = 8 if not self.config.get('oneserver') else 0 self.blockchain = Blockchain(self.config, self) self.interfaces = {} self.queue = Queue.Queue() @@ -154,7 +154,7 @@ class Network(threading.Thread): self.start_interface(self.default_server) self.interface = self.interfaces[self.default_server] - for i in range(NUM_SERVERS): + for i in range(self.num_server): self.start_random_interface() if not self.interface: @@ -282,7 +282,7 @@ class Network(threading.Thread): try: i = self.queue.get(timeout = 30 if self.interfaces else 3) except Queue.Empty: - if len(self.interfaces) < NUM_SERVERS: + if len(self.interfaces) < self.num_server: self.start_random_interface() continue From 6458c0f591193ef26e9ef765129aed8081c806b5 Mon Sep 17 00:00:00 2001 From: thomasv Date: Fri, 8 Nov 2013 11:17:40 +0100 Subject: [PATCH 02/12] don't show actinos that require private key if the wallet has no seed --- gui/qt/main_window.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index aefa8dff..e3c6c1ea 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -1124,8 +1124,9 @@ class ElectrumWindow(QMainWindow): menu.addAction(_("Copy to clipboard"), lambda: self.app.clipboard().setText(addr)) menu.addAction(_("QR code"), lambda: self.show_qrcode("bitcoin:" + addr, _("Address")) ) menu.addAction(_("Edit label"), lambda: self.edit_label(True)) - menu.addAction(_("Private key"), lambda: self.show_private_key(addr)) - menu.addAction(_("Sign message"), lambda: self.sign_message(addr)) + if self.wallet.seed: + menu.addAction(_("Private key"), lambda: self.show_private_key(addr)) + menu.addAction(_("Sign message"), lambda: self.sign_message(addr)) if addr in self.wallet.imported_keys: menu.addAction(_("Remove from wallet"), lambda: self.delete_imported_key(addr)) From ef1c2c7760c033e67cd95e1c247060173fb410b9 Mon Sep 17 00:00:00 2001 From: Andy Weidenbaum Date: Fri, 8 Nov 2013 03:31:18 -0800 Subject: [PATCH 03/12] concealed flag for restore sequence --- electrum | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/electrum b/electrum index eae7687e..8cdabcb1 100755 --- a/electrum +++ b/electrum @@ -71,6 +71,7 @@ def arg_parser(): parser.add_option("-g", "--gui", dest="gui", help="User interface: qt, lite, gtk, text or stdio") parser.add_option("-w", "--wallet", dest="wallet_path", help="wallet path (default: electrum.dat)") parser.add_option("-o", "--offline", action="store_true", dest="offline", default=False, help="remain offline") + parser.add_option("-C", "--concealed", action="store_true", dest="concealed", default=False, help="don't echo seed to console when restoring") parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses") parser.add_option("-l", "--labels", action="store_true", dest="show_labels", default=False, help="show the labels of listed addresses") parser.add_option("-f", "--fee", dest="tx_fee", default=None, help="set tx fee") @@ -209,7 +210,8 @@ if __name__ == '__main__': if gap: wallet.change_gap_limit(int(gap)) if cmd.name == 'restore': - seed = raw_input("seed:") + import getpass + seed = getpass.getpass(prompt = "seed:", stream = None) if options.concealed else raw_input("seed:") try: seed.decode('hex') except: From 48bd2557b7a55ac524d211bcc781f95c02681d34 Mon Sep 17 00:00:00 2001 From: thomasv Date: Fri, 8 Nov 2013 12:35:27 +0100 Subject: [PATCH 04/12] fix: store seed version --- lib/wallet.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/wallet.py b/lib/wallet.py index 26a95154..e8c72745 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -347,6 +347,7 @@ class Wallet: if not c0: self.seed_version = 4 + self.storage.put('seed_version', self.seed_version, True) self.create_old_account(K0) return @@ -355,6 +356,7 @@ class Wallet: "m/0'/": (c0, K0, cK0), } self.storage.put('master_public_keys', self.master_public_keys, True) + self.storage.put('seed_version', self.seed_version, True) self.create_account('1','Main account') From 30934b69db6a5e6ae2059dc09b539c47f1d5549d Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 9 Nov 2013 08:15:46 +0100 Subject: [PATCH 05/12] call check_seed in get_seed --- lib/account.py | 2 +- lib/wallet.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/account.py b/lib/account.py index bf12ae13..a220de82 100644 --- a/lib/account.py +++ b/lib/account.py @@ -106,7 +106,7 @@ class OldAccount(Account): curve = SECP256k1 secexp = self.stretch_key(seed) master_private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 ) - master_public_key = master_private_key.get_verifying_key().to_string().encode('hex') + master_public_key = master_private_key.get_verifying_key().to_string() if master_public_key != self.mpk: print_error('invalid password (mpk)') raise BaseException('Invalid password') diff --git a/lib/wallet.py b/lib/wallet.py index 26a95154..937cd8bc 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -678,9 +678,9 @@ class Wallet: s = pw_decode(self.seed, password) if self.seed_version == 4: seed = s + self.accounts[0].check_seed(seed) else: seed = mnemonic_hash(s) - #todo: #self.sequences[0].check_seed(seed) return seed From ba9782eec66ec887ced6932d279c81a3f9048b06 Mon Sep 17 00:00:00 2001 From: "Eagle[TM]" Date: Sun, 10 Nov 2013 01:26:06 +0100 Subject: [PATCH 06/12] Update default server list (disable servers with failed/expired certs) --- lib/network.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/network.py b/lib/network.py index dbbd4047..82bdcb42 100644 --- a/lib/network.py +++ b/lib/network.py @@ -7,7 +7,7 @@ from blockchain import Blockchain DEFAULT_PORTS = {'t':'50001', 's':'50002', 'h':'8081', 'g':'8082'} DEFAULT_SERVERS = { - 'electrum.coinwallet.me': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, + #'electrum.coinwallet.me': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, 'electrum.hachre.de': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, 'electrum.novit.ro': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, 'electrum.stepkrav.pw': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, @@ -16,8 +16,8 @@ DEFAULT_SERVERS = { 'electrum.drollette.com': {'h': '5000', 's': '50002', 't': '50001', 'g': '8082'}, 'btc.it-zone.org': {'h': '80', 's': '110', 't': '50001', 'g': '443'}, 'btc.medoix.com': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - 'spv.nybex.com': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - 'electrum.pdmc.net': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, + 'electrum.stupidfoot.com': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, + #'electrum.pdmc.net': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, 'electrum.be': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'} } From 8ece295f2ee0e575407e81651f5d5c17ac1f884b Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 9 Nov 2013 20:17:22 -0800 Subject: [PATCH 07/12] ignore gui/icons_rc.py --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f7aa8743..40fce2e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ ####-*.patch +gui/icons_rc.py lib/icons_rc.py *.pyc *.swp From f0eb0eccde5665dc9f1116ad0b5ec2f20fea9fa8 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 9 Nov 2013 20:21:02 -0800 Subject: [PATCH 08/12] replace BaseException with Exception --- electrum | 2 +- gui/android.py | 2 +- gui/gtk.py | 2 +- gui/qt/lite_window.py | 4 ++-- gui/qt/main_window.py | 12 ++++++------ gui/stdio.py | 2 +- gui/text.py | 2 +- lib/account.py | 2 +- lib/bitcoin.py | 10 +++++----- lib/commands.py | 10 +++++----- lib/interface.py | 2 +- lib/util.py | 2 +- lib/wallet.py | 22 +++++++++++----------- plugins/aliases.py | 2 +- plugins/qrscanner.py | 8 ++++---- 15 files changed, 42 insertions(+), 42 deletions(-) diff --git a/electrum b/electrum index 8cdabcb1..32c54115 100755 --- a/electrum +++ b/electrum @@ -103,7 +103,7 @@ def run_command(cmd, password = None, args = []): cmd_runner.password = password try: result = func(*args[1:]) - except BaseException, e: + except Exception as e: import traceback traceback.print_exc(file=sys.stdout) sys.exit(1) diff --git a/gui/android.py b/gui/android.py index e254a462..800dc326 100644 --- a/gui/android.py +++ b/gui/android.py @@ -458,7 +458,7 @@ def pay_to(recipient, amount, fee, label): try: tx = wallet.mktx( [(recipient, amount)], password, fee) - except BaseException, e: + except Exception as e: modal_dialog('error', e.message) droid.dialogDismiss() return diff --git a/gui/gtk.py b/gui/gtk.py index e7a3a0f5..7120af39 100644 --- a/gui/gtk.py +++ b/gui/gtk.py @@ -807,7 +807,7 @@ class ElectrumWindow: try: tx = self.wallet.mktx( [(to_address, amount)], password, fee ) - except BaseException, e: + except Exception as e: self.show_message(str(e)) return diff --git a/gui/qt/lite_window.py b/gui/qt/lite_window.py index 3f243708..5131ae01 100644 --- a/gui/qt/lite_window.py +++ b/gui/qt/lite_window.py @@ -750,7 +750,7 @@ class MiniActuator: try: tx = self.g.wallet.mktx([(dest_address, amount)], password, fee) - except BaseException as error: + except Exception as error: QMessageBox.warning(parent_window, _('Error'), str(error), _('OK')) return False @@ -778,7 +778,7 @@ class MiniActuator: with open(fileName,'w') as f: f.write(json.dumps(tx.as_dict(),indent=4) + '\n') QMessageBox.information(QWidget(), _('Unsigned transaction created'), _("Unsigned transaction was saved to file:") + " " +fileName, _('OK')) - except BaseException as e: + except Exception as e: QMessageBox.warning(QWidget(), _('Error'), _('Could not write transaction to file: %s' % e), _('OK')) return True diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index e3c6c1ea..57f8307a 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -889,7 +889,7 @@ class ElectrumWindow(QMainWindow): try: tx = self.wallet.mktx_from_account( [(to_address, amount)], password, fee, self.current_account) - except BaseException, e: + except Exception as e: traceback.print_exc(file=sys.stdout) self.show_message(str(e)) return @@ -1635,7 +1635,7 @@ class ElectrumWindow(QMainWindow): if not address: return try: pk_list = self.wallet.get_private_key(address, password) - except BaseException, e: + except Exception as e: self.show_message(str(e)) return QMessageBox.information(self, _('Private key'), _('Address')+ ': ' + address + '\n\n' + _('Private key') + ': ' + '\n'.join(pk_list), _('OK')) @@ -1648,7 +1648,7 @@ class ElectrumWindow(QMainWindow): try: sig = self.wallet.sign_message(str(address.text()), message, password) signature.setText(sig) - except BaseException, e: + except Exception as e: self.show_message(str(e)) def sign_message(self, address): @@ -1840,7 +1840,7 @@ class ElectrumWindow(QMainWindow): try: tx = self.wallet.make_unsigned_transaction(outputs, None, None) - except BaseException, e: + except Exception as e: self.show_message(str(e)) return @@ -1893,7 +1893,7 @@ class ElectrumWindow(QMainWindow): export_error_label = _("Electrum was unable to produce a private key-export.") QMessageBox.critical(None, _("Unable to create csv"), export_error_label + "\n" + str(reason)) - except BaseException, e: + except Exception as e: self.show_message(str(e)) return @@ -1946,7 +1946,7 @@ class ElectrumWindow(QMainWindow): for key in text: try: addr = self.wallet.import_key(key, password) - except BaseException as e: + except Exception as e: badkeys.append(key) continue if not addr: diff --git a/gui/stdio.py b/gui/stdio.py index f252a8af..517f8bb2 100644 --- a/gui/stdio.py +++ b/gui/stdio.py @@ -198,7 +198,7 @@ class ElectrumGui: try: tx = self.wallet.mktx( [(self.str_recipient, amount)], password, fee) - except BaseException, e: + except Exception as e: print(str(e)) return diff --git a/gui/text.py b/gui/text.py index 437ce356..d9b95206 100644 --- a/gui/text.py +++ b/gui/text.py @@ -309,7 +309,7 @@ class ElectrumGui: try: tx = self.wallet.mktx( [(self.str_recipient, amount)], password, fee) - except BaseException, e: + except Exception as e: self.show_message(str(e)) return diff --git a/lib/account.py b/lib/account.py index a220de82..9a262bff 100644 --- a/lib/account.py +++ b/lib/account.py @@ -109,7 +109,7 @@ class OldAccount(Account): master_public_key = master_private_key.get_verifying_key().to_string() if master_public_key != self.mpk: print_error('invalid password (mpk)') - raise BaseException('Invalid password') + raise Exception('Invalid password') return True def redeem_script(self, sequence): diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 94d50756..9780a65a 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -294,7 +294,7 @@ def verify_message(address, signature, message): try: EC_KEY.verify_message(address, signature, message) return True - except BaseException as e: + except Exception as e: print_error("Verification error: {0}".format(e)) return False @@ -319,7 +319,7 @@ class EC_KEY(object): except: continue else: - raise BaseException("error: cannot sign message") + raise Exception("error: cannot sign message") @classmethod def verify_message(self, address, signature, message): @@ -331,11 +331,11 @@ class EC_KEY(object): order = G.order() # extract r,s from signature sig = base64.b64decode(signature) - if len(sig) != 65: raise BaseException("Wrong encoding") + if len(sig) != 65: raise Exception("Wrong encoding") r,s = util.sigdecode_string(sig[1:], order) nV = ord(sig[0]) if nV < 27 or nV >= 35: - raise BaseException("Bad encoding") + raise Exception("Bad encoding") if nV >= 31: compressed = True nV -= 4 @@ -364,7 +364,7 @@ class EC_KEY(object): # check that we get the original signing address addr = public_key_to_bc_address( encode_point(public_key, compressed) ) if address != addr: - raise BaseException("Bad signature") + raise Exception("Bad signature") ###################################### BIP32 ############################## diff --git a/lib/commands.py b/lib/commands.py index 129b1c5c..aef1e9c7 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -228,7 +228,7 @@ class Commands: try: addr = self.wallet.import_key(sec,self.password) out = "Keypair imported: ", addr - except BaseException as e: + except Exception as e: out = "Error: Keypair import failed: " + str(e) return out @@ -245,19 +245,19 @@ class Commands: for to_address, amount in outputs: if not is_valid(to_address): - raise BaseException("Invalid Bitcoin address", to_address) + raise Exception("Invalid Bitcoin address", to_address) if change_addr: if not is_valid(change_addr): - raise BaseException("Invalid Bitcoin address", change_addr) + raise Exception("Invalid Bitcoin address", change_addr) if domain is not None: for addr in domain: if not is_valid(addr): - raise BaseException("invalid Bitcoin address", addr) + raise Exception("invalid Bitcoin address", addr) if not self.wallet.is_mine(addr): - raise BaseException("address not in wallet", addr) + raise Exception("address not in wallet", addr) for k, v in self.wallet.labels.items(): if change_addr and v == change_addr: diff --git a/lib/interface.py b/lib/interface.py index 43b0a6cf..360b82ce 100644 --- a/lib/interface.py +++ b/lib/interface.py @@ -117,7 +117,7 @@ class Interface(threading.Thread): return if protocol not in 'ghst': - raise BaseException('Unknown protocol: %s'%protocol) + raise Exception('Unknown protocol: %s'%protocol) self.host = host self.port = port diff --git a/lib/util.py b/lib/util.py index fb84b5d5..b719fed7 100644 --- a/lib/util.py +++ b/lib/util.py @@ -49,7 +49,7 @@ def user_dir(): elif 'ANDROID_DATA' in os.environ: return "/sdcard/electrum/" else: - #raise BaseException("No home directory found in environment variables.") + #raise Exception("No home directory found in environment variables.") return def appdata_dir(): diff --git a/lib/wallet.py b/lib/wallet.py index cbc95a2b..4297f2cf 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -56,7 +56,7 @@ def pw_decode(s, password): try: d = DecodeAES(secret, s) except: - raise BaseException('Invalid password') + raise Exception('Invalid password') return d else: return s @@ -257,10 +257,10 @@ class Wallet: try: address = address_from_private_key(sec) except: - raise BaseException('Invalid private key') + raise Exception('Invalid private key') if self.is_mine(address): - raise BaseException('Address already in wallet') + raise Exception('Address already in wallet') # store the originally requested keypair into the imported keys table self.imported_keys[address] = pw_encode(sec, password ) @@ -296,7 +296,7 @@ class Wallet: import mnemonic if self.seed: - raise BaseException("a seed exists") + raise Exception("a seed exists") if not seed: self.seed = random_seed(128) @@ -438,7 +438,7 @@ class Wallet: elif account_type == '2of3': return "m/3'/%d & m/4'/%d & m/5'/%d"%(i,i,i) else: - raise BaseException('unknown account type') + raise Exception('unknown account type') def num_accounts(self, account_type): @@ -609,7 +609,7 @@ class Wallet: K, Kc = get_pubkeys_from_secret(master_k.decode('hex')) assert K.encode('hex') == master_K except: - raise BaseException("Invalid password") + raise Exception("Invalid password") return master_k @@ -628,7 +628,7 @@ class Wallet: if v == address: return k, (0,0) - raise BaseException("Address not found", address) + raise Exception("Address not found", address) def get_roots(self, account): @@ -1110,7 +1110,7 @@ class Wallet: if h == ['*']: continue for tx_hash, tx_height in h: tx = self.transactions.get(tx_hash) - if tx is None: raise BaseException("Wallet not synchronized") + if tx is None: raise Exception("Wallet not synchronized") is_coinbase = tx.inputs[0].get('prevout_hash') == '0'*64 for output in tx.d.get('outputs'): if output.get('address') != addr: continue @@ -1245,7 +1245,7 @@ class Wallet: def receive_history_callback(self, addr, hist): if not self.check_new_history(addr, hist): - raise BaseException("error: received history for %s is not consistent with known transactions"%addr) + raise Exception("error: received history for %s is not consistent with known transactions"%addr) with self.lock: self.history[addr] = hist @@ -1754,12 +1754,12 @@ class WalletSynchronizer(threading.Thread): hist.append( (tx_hash, item['height']) ) if len(hist) != len(result): - raise BaseException("error: server sent history with non-unique txid", result) + raise Exception("error: server sent history with non-unique txid", result) # check that the status corresponds to what was announced rs = requested_histories.pop(addr) if self.wallet.get_status(hist) != rs: - raise BaseException("error: status mismatch: %s"%addr) + raise Exception("error: status mismatch: %s"%addr) # store received history self.wallet.receive_history_callback(addr, hist) diff --git a/plugins/aliases.py b/plugins/aliases.py index c2946744..0a54d6d7 100644 --- a/plugins/aliases.py +++ b/plugins/aliases.py @@ -52,7 +52,7 @@ class Plugin(BasePlugin): def get_alias(self, alias, interactive = False, show_message=None, question = None): try: target, signing_address, auth_name = read_alias(self, alias) - except BaseException, e: + except Exception as e: # raise exception if verify fails (verify the chain) if interactive: show_message("Alias error: " + str(e)) diff --git a/plugins/qrscanner.py b/plugins/qrscanner.py index d76742d9..4826eebc 100644 --- a/plugins/qrscanner.py +++ b/plugins/qrscanner.py @@ -110,7 +110,7 @@ class Plugin(BasePlugin): try: tx = self.gui.main_window.wallet.mktx( [(to_address, amount)], None, fee) - except BaseException, e: + except Exception as e: self.gui.main_window.show_message(str(e)) return @@ -126,13 +126,13 @@ class Plugin(BasePlugin): input_info = [] - except BaseException, e: + except Exception as e: self.gui.main_window.show_message(str(e)) try: json_text = json.dumps(tx.as_dict()).replace(' ', '') self.show_tx_qrcode(json_text, 'Unsigned Transaction') - except BaseException, e: + except Exception as e: self.gui.main_window.show_message(str(e)) def show_tx_qrcode(self, data, title): @@ -235,7 +235,7 @@ class Plugin(BasePlugin): self.gui.main_window.wallet.signrawtransaction(tx, input_info, [], password) txtext = json.dumps(tx.as_dict()).replace(' ', '') self.show_tx_qrcode(txtext, 'Signed Transaction') - except BaseException, e: + except Exception as e: self.gui.main_window.show_message(str(e)) From 225d8b83a386fffc3d9ad8bb154cac2d82bcd45b Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 9 Nov 2013 21:23:57 -0800 Subject: [PATCH 09/12] don't use bare except --- lib/bitcoin.py | 8 ++++---- lib/blockchain.py | 8 ++++---- lib/commands.py | 2 +- lib/interface.py | 18 +++++++++--------- lib/network.py | 2 +- lib/plugins.py | 4 ++-- lib/simple_config.py | 4 ++-- lib/transaction.py | 2 +- lib/wallet.py | 14 +++++++------- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 9780a65a..36758f9d 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -115,7 +115,7 @@ def hash_160(public_key): md = hashlib.new('ripemd160') md.update(hashlib.sha256(public_key).digest()) return md.digest() - except: + except Exception: import ripemd md = ripemd.new(hashlib.sha256(public_key).digest()) return md.digest() @@ -268,7 +268,7 @@ def is_valid(addr): if not ADDRESS_RE.match(addr): return False try: addrtype, h = bc_address_to_hash_160(addr) - except: + except Exception: return False return addr == hash_160_to_bc_address(h, addrtype) @@ -277,7 +277,7 @@ def is_valid(addr): try: from ecdsa.ecdsa import curve_secp256k1, generator_secp256k1 -except: +except Exception: print "cannot import ecdsa.curve_secp256k1. You probably need to upgrade ecdsa.\nTry: sudo pip install --upgrade ecdsa" exit() from ecdsa.curves import SECP256k1 @@ -316,7 +316,7 @@ class EC_KEY(object): try: self.verify_message( address, sig, message) return sig - except: + except Exception: continue else: raise Exception("error: cannot sign message") diff --git a/lib/blockchain.py b/lib/blockchain.py index c7dab20f..08461d0c 100644 --- a/lib/blockchain.py +++ b/lib/blockchain.py @@ -119,7 +119,7 @@ class Blockchain(threading.Thread): assert prev_hash == header.get('prev_block_hash') assert bits == header.get('bits') assert eval('0x'+_hash) < target - except: + except Exception: return False prev_header = header @@ -176,7 +176,7 @@ class Blockchain(threading.Thread): assert prev_hash == header.get('prev_block_hash') assert bits == header.get('bits') assert eval('0x'+_hash) < target - except: + except Exception: # this can be caused by a reorg. print_error("verify header failed"+ repr(header)) verifier.undo_verifications() @@ -227,7 +227,7 @@ class Blockchain(threading.Thread): print_error("downloading ", self.headers_url ) urllib.urlretrieve(self.headers_url, filename) print_error("done.") - except: + except Exception: print_error( "download failed. creating file", filename ) open(filename,'wb+').close() @@ -411,7 +411,7 @@ class Blockchain(threading.Thread): index = params[0] try: self.verify_chunk(index, result) - except: + except Exception: print_error('Verify chunk failed!!') return False requested_chunks.remove(index) diff --git a/lib/commands.py b/lib/commands.py index aef1e9c7..f34c10a3 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -306,7 +306,7 @@ class Commands: tx_hash, conf, is_mine, value, fee, balance, timestamp = item try: time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] - except: + except Exception: time_str = "----" label, is_default_label = self.wallet.get_label(tx_hash) diff --git a/lib/interface.py b/lib/interface.py index 360b82ce..44de2858 100644 --- a/lib/interface.py +++ b/lib/interface.py @@ -49,7 +49,7 @@ def check_cert(host, cert): def cert_has_expired(cert_path): try: import OpenSSL - except: + except Exception: print_error("Warning: cannot import OpenSSL") return False from OpenSSL import crypto as c @@ -112,7 +112,7 @@ class Interface(threading.Thread): try: host, port, protocol = self.server.split(':') port = int(port) - except: + except Exception: self.server = None return @@ -196,7 +196,7 @@ class Interface(threading.Thread): self.connection_msg = ('https' if self.use_ssl else 'http') + '://%s:%d'%( self.host, self.port ) try: self.poll() - except: + except Exception: print_error("http init session failed") self.is_connected = False return @@ -218,7 +218,7 @@ class Interface(threading.Thread): break except socket.error: break - except: + except Exception: traceback.print_exc(file=sys.stdout) break @@ -265,7 +265,7 @@ class Interface(threading.Thread): try: req = urllib2.Request(self.connection_msg, data_json, headers) response_stream = urllib2.urlopen(req, timeout=DEFAULT_TIMEOUT) - except: + except Exception: return for index, cookie in enumerate(cj): @@ -318,7 +318,7 @@ class Interface(threading.Thread): s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) try: s.connect((self.host, self.port)) - except: + except Exception: # print_error("failed to connect", self.host, self.port) return @@ -346,7 +346,7 @@ class Interface(threading.Thread): try: s.connect(( self.host.encode('ascii'), int(self.port))) - except: + except Exception: print_error("failed to connect", self.host, self.port) return @@ -370,7 +370,7 @@ class Interface(threading.Thread): else: print_msg("wrong certificate", self.host) return - except: + except Exception: print_error("wrap_socket failed", self.host) traceback.print_exc(file=sys.stdout) return @@ -424,7 +424,7 @@ class Interface(threading.Thread): c = json.loads(c) self.queue_json_response(c) - except: + except Exception: traceback.print_exc(file=sys.stdout) self.is_connected = False diff --git a/lib/network.py b/lib/network.py index 82bdcb42..c900cadb 100644 --- a/lib/network.py +++ b/lib/network.py @@ -385,7 +385,7 @@ class Network(threading.Thread): if pruning_level == '': pruning_level = '0' try: is_recent = float(version)>=float(PROTOCOL_VERSION) - except: + except Exception: is_recent = False if out and is_recent: diff --git a/lib/plugins.py b/lib/plugins.py index 0e7e520a..a3ba5bc2 100644 --- a/lib/plugins.py +++ b/lib/plugins.py @@ -24,7 +24,7 @@ def init_plugins(self): for name, p in zip(plugin_names, plugin_modules): try: plugins.append( p.Plugin(self, name) ) - except: + except Exception: print_msg(_("Error: cannot initialize plugin"),p) traceback.print_exc(file=sys.stdout) @@ -45,7 +45,7 @@ def run_hook(name, *args): try: f(*args) - except: + except Exception: print_error("Plugin error") traceback.print_exc(file=sys.stdout) diff --git a/lib/simple_config.py b/lib/simple_config.py index e3614f5e..1ae65792 100644 --- a/lib/simple_config.py +++ b/lib/simple_config.py @@ -103,7 +103,7 @@ a SimpleConfig instance then reads the wallet file. import ast try: out = ast.literal_eval(out) - except: + except Exception: print "type error for '%s': using default value"%key out = default @@ -154,7 +154,7 @@ a SimpleConfig instance then reads the wallet file. return try: d = ast.literal_eval( data ) #parse raw data from reading wallet file - except: + except Exception: raise IOError("Cannot read config file.") self.user_config = d diff --git a/lib/transaction.py b/lib/transaction.py index 7e36369d..b1c4bf50 100644 --- a/lib/transaction.py +++ b/lib/transaction.py @@ -298,7 +298,7 @@ def match_decoded(decoded, to_match): def get_address_from_input_script(bytes): try: decoded = [ x for x in script_GetOp(bytes) ] - except: + except Exception: # coinbase transactions raise an exception print_error("cannot find address in input script", bytes.encode('hex')) return [], [], "(None)" diff --git a/lib/wallet.py b/lib/wallet.py index 4297f2cf..4cb7bd41 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -55,7 +55,7 @@ def pw_decode(s, password): secret = Hash(password) try: d = DecodeAES(secret, s) - except: + except Exception: raise Exception('Invalid password') return d else: @@ -117,7 +117,7 @@ class WalletStorage: return try: d = ast.literal_eval( data ) #parse raw data from reading wallet file - except: + except Exception: raise IOError("Cannot read wallet file.") self.data = d @@ -192,7 +192,7 @@ class Wallet: for k,v in tx_list.items(): try: tx = Transaction(v) - except: + except Exception: print_msg("Warning: Cannot deserialize transactions. skipping") continue @@ -256,7 +256,7 @@ class Wallet: seed = self.get_seed(password) try: address = address_from_private_key(sec) - except: + except Exception: raise Exception('Invalid private key') if self.is_mine(address): @@ -314,7 +314,7 @@ class Wallet: self.seed_version = 4 self.seed = str(seed) return - except: + except Exception: pass words = seed.split() @@ -324,7 +324,7 @@ class Wallet: #try: # mnemonic.mn_decode(words) # uses_electrum_words = True - #except: + #except Exception: # uses_electrum_words = False # #if uses_electrum_words and len(words) != 13: @@ -608,7 +608,7 @@ class Wallet: try: K, Kc = get_pubkeys_from_secret(master_k.decode('hex')) assert K.encode('hex') == master_K - except: + except Exception: raise Exception("Invalid password") return master_k From 57e7eb2ff9acb90ca1dbf4cb5e4fa56ec1e8c64d Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sun, 10 Nov 2013 11:51:56 +0100 Subject: [PATCH 10/12] wallet.py: use get_seed in update_password --- lib/wallet.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/wallet.py b/lib/wallet.py index 4cb7bd41..443a3d6a 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1408,8 +1408,7 @@ class Wallet: def update_password(self, old_password, new_password): if new_password == '': new_password = None - # this will throw an exception if unicode cannot be converted - decoded = pw_decode(self.seed, old_password) + decoded = self.get_seed(old_password) self.seed = pw_encode( decoded, new_password) self.storage.put('seed', self.seed, True) self.use_encryption = (new_password != None) From eae0c7c3b94680906713b89eecd9b3700265ad7c Mon Sep 17 00:00:00 2001 From: thomasv Date: Sun, 10 Nov 2013 15:22:22 +0100 Subject: [PATCH 11/12] get_private_key: call get_seed first in order to check password --- lib/wallet.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/wallet.py b/lib/wallet.py index 443a3d6a..8aa39f92 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -697,13 +697,15 @@ class Wallet: def get_private_key(self, address, password): + # first check the provided password + seed = self.get_seed(password) + out = [] if address in self.imported_keys.keys(): out.append( pw_decode( self.imported_keys[address], password ) ) else: account, sequence = self.get_address_index(address) if account == 0: - seed = self.get_seed(password) pk = self.accounts[account].get_private_key(seed, sequence) out.append(pk) return out From 24cabcbee93a091f1af94eee941cd8ce38aed9d3 Mon Sep 17 00:00:00 2001 From: Maran Date: Sun, 10 Nov 2013 18:11:26 +0100 Subject: [PATCH 12/12] Switch icon based on OS, OS X requires dark icon --- gui/qt/main_window.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 57f8307a..03f77b9e 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -138,8 +138,13 @@ class ElectrumWindow(QMainWindow): self._close_electrum = False self.lite = None - - self.icon = QIcon(':icons/electrum_light_icon.png') + + if sys.platform == 'darwin': + self.icon = QIcon(":icons/electrum_dark_icon.png") + #self.icon = QIcon(":icons/lock.png") + else: + self.icon = QIcon(':icons/electrum_light_icon.png') + self.tray = QSystemTrayIcon(self.icon, self) self.tray.setToolTip('Electrum') self.tray.activated.connect(self.tray_activated)