URI: 
       tadd InvalidPassword exception - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 63c7a27d7e35b4ae13a5eeb2b673a841a8c25242
   DIR parent 0e3500469e7c865f1db421e39a146ababba40118
  HTML Author: ThomasV <thomasv@gitorious>
       Date:   Wed,  3 Dec 2014 22:35:05 +0100
       
       add InvalidPassword exception
       
       Diffstat:
         M electrum                            |       4 ++--
         M gui/gtk.py                          |       4 ++--
         M gui/qt/main_window.py               |      10 +++++-----
         M gui/qt/password_dialog.py           |       4 ++--
         M lib/account.py                      |       7 ++++---
         M lib/bitcoin.py                      |       4 ++--
         M lib/util.py                         |       7 ++++++-
         M lib/wallet.py                       |      12 ++++++++----
       
       8 files changed, 31 insertions(+), 21 deletions(-)
       ---
   DIR diff --git a/electrum b/electrum
       t@@ -45,7 +45,7 @@ if __builtin__.use_local_modules:
        
        from electrum import util
        from electrum import SimpleConfig, Network, Wallet, WalletStorage, NetworkProxy, Commands, known_commands, pick_random_server
       -from electrum.util import print_msg, print_stderr, print_json, set_verbosity
       +from electrum.util import print_msg, print_stderr, print_json, set_verbosity, InvalidPassword
        from electrum.daemon import get_daemon
        from electrum.plugins import init_plugins
        
       t@@ -360,7 +360,7 @@ if __name__ == '__main__':
                    # check password
                    try:
                        seed = wallet.get_seed(password)
       -            except Exception:
       +            except InvalidPassword:
                        print_msg("Error: This password does not decode this wallet.")
                        sys.exit(1)
                else:
   DIR diff --git a/gui/gtk.py b/gui/gtk.py
       t@@ -24,7 +24,7 @@ import gi
        gi.require_version('Gtk', '3.0')
        from gi.repository import Gtk, Gdk, GObject, cairo
        from decimal import Decimal
       -from electrum.util import print_error
       +from electrum.util import print_error, InvalidPassword
        from electrum.bitcoin import is_valid
        from electrum import WalletStorage, Wallet
        
       t@@ -596,7 +596,7 @@ class ElectrumWindow:
        
                    try:
                        wallet.get_seed(password)
       -            except Exception:
       +            except InvalidPassword:
                        show_message("Incorrect password")
                        return
        
   DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
       t@@ -1912,8 +1912,8 @@ class ElectrumWindow(QMainWindow):
        
                try:
                    mnemonic = self.wallet.get_mnemonic(password)
       -        except Exception:
       -            QMessageBox.warning(self, _('Error'), _('Incorrect Password'), _('OK'))
       +        except BaseException as e:
       +            QMessageBox.warning(self, _('Error'), str(e), _('OK'))
                    return
                from seed_dialog import SeedDialog
                d = SeedDialog(self, mnemonic, self.wallet.has_imported_keys())
       t@@ -2312,10 +2312,10 @@ class ElectrumWindow(QMainWindow):
        
                try:
                    mnemonic = self.wallet.get_mnemonic(password)
       -        except Exception:
       -            QMessageBox.warning(self, _('Error'), _('Incorrect Password'), _('OK'))
       +        except Exception as e:
       +            QMessageBox.warning(self, _('Error'), str(e), _('OK'))
                    return
       -            
       +
                d = QDialog(self)
                d.setWindowTitle(_('Private keys'))
                d.setMinimumSize(850, 300)
   DIR diff --git a/gui/qt/password_dialog.py b/gui/qt/password_dialog.py
       t@@ -157,8 +157,8 @@ class PasswordDialog(QDialog):
        
                try:
                    self.wallet.check_password(password)
       -        except Exception:
       -            QMessageBox.warning(self.parent, _('Error'), _('Incorrect Password'), _('OK'))
       +        except BaseException as e:
       +            QMessageBox.warning(self.parent, _('Error'), str(e), _('OK'))
                    return False, None, None
        
                try:
   DIR diff --git a/lib/account.py b/lib/account.py
       t@@ -20,7 +20,7 @@ import bitcoin
        from bitcoin import *
        from i18n import _
        from transaction import Transaction, is_extended_pubkey
       -from util import print_msg
       +from util import print_msg, InvalidPassword
        
        
        class Account(object):
       t@@ -145,7 +145,8 @@ class ImportedAccount(Account):
                address = self.get_addresses(0)[i]
                pk = pw_decode(self.keypairs[address][1], password)
                # this checks the password
       -        assert address == address_from_private_key(pk)
       +        if address != address_from_private_key(pk):
       +            raise InvalidPassword()
                return [pk]
        
            def has_change(self):
       t@@ -242,7 +243,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)', self.mpk.encode('hex'), master_public_key.encode('hex'))
       -            raise Exception('Invalid password')
       +            raise InvalidPassword()
                return True
        
            def get_master_pubkeys(self):
   DIR diff --git a/lib/bitcoin.py b/lib/bitcoin.py
       t@@ -24,7 +24,7 @@ import sys
        import hmac
        
        import version
       -from util import print_error
       +from util import print_error, InvalidPassword
        
        try:
            import ecdsa
       t@@ -98,7 +98,7 @@ def pw_decode(s, password):
                try:
                    d = DecodeAES(secret, s).decode("utf8")
                except Exception:
       -            raise Exception('Invalid password')
       +            raise InvalidPassword()
                return d
            else:
                return s
   DIR diff --git a/lib/util.py b/lib/util.py
       t@@ -2,10 +2,14 @@ import os, sys, re, json
        import platform
        import shutil
        from datetime import datetime
       -is_verbose = False
       +from i18n import _
        
        class NotEnoughFunds(Exception): pass
        
       +class InvalidPassword(Exception):
       +    def __str__(self):
       +        return _("Incorrect password")
       +
        class MyEncoder(json.JSONEncoder):
            def default(self, obj):
                from transaction import Transaction
       t@@ -14,6 +18,7 @@ class MyEncoder(json.JSONEncoder):
                return super(MyEncoder, self).default(obj)
        
        
       +is_verbose = False
        def set_verbosity(b):
            global is_verbose
            is_verbose = b
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -230,7 +230,8 @@ class Abstract_Wallet(object):
                    sec = pw_decode(v, password)
                    pubkey = public_key_from_private_key(sec)
                    address = public_key_to_bc_address(pubkey.decode('hex'))
       -            assert address == k
       +            if address != k:
       +                raise InvalidPassword()
                    self.import_key(sec, password)
                    self.imported_keys.pop(k)
                self.storage.put('imported_keys', self.imported_keys)
       t@@ -713,8 +714,6 @@ class Abstract_Wallet(object):
                    if total >= amount + fee: break
                else:
                    raise NotEnoughFunds()
       -            #print_error("Not enough funds", total, amount, fee)
       -            #return None
        
                # change address
                if not change_addr:
       t@@ -1284,12 +1283,17 @@ class BIP32_Wallet(Deterministic_Wallet):
                k = self.master_private_keys.get(account)
                if not k: return
                xprv = pw_decode(k, password)
       +        try:
       +            deserialize_xkey(xprv)
       +        except:
       +            raise InvalidPassword()
                return xprv
        
            def check_password(self, password):
                xpriv = self.get_master_private_key(self.root_name, password)
                xpub = self.master_public_keys[self.root_name]
       -        assert deserialize_xkey(xpriv)[3] == deserialize_xkey(xpub)[3]
       +        if deserialize_xkey(xpriv)[3] != deserialize_xkey(xpub)[3]:
       +            raise InvalidPassword()
        
            def add_master_public_key(self, name, xpub):
                self.master_public_keys[name] = xpub