tnew class: Imported_Wallet - electrum - Electrum Bitcoin wallet
 (HTM) git clone https://git.parazyd.org/electrum
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
       ---
 (DIR) commit 582fb76e9efbba0cb1894df551e124343fe8af86
 (DIR) parent 3ae48a181950363578d9ea3a2dd76e45f6ab2045
 (HTM) Author: ThomasV <thomasv@gitorious>
       Date:   Tue, 29 Apr 2014 21:04:16 +0200
       
       new class: Imported_Wallet
       
       Diffstat:
         M gui/qt/installwizard.py             |       7 ++++++-
         M lib/bitcoin.py                      |       8 ++++++++
         M lib/wallet.py                       |      49 +++++++++++++++++++++++++++++--
       
       3 files changed, 61 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py
       t@@ -4,6 +4,7 @@ import PyQt4.QtCore as QtCore
        
        from electrum.i18n import _
        from electrum import Wallet, Wallet_2of2, Wallet_2of3
       +import electrum.bitcoin as bitcoin
        
        import seed_dialog
        from network_dialog import NetworkDialog
       t@@ -92,7 +93,7 @@ class InstallWizard(QDialog):
        
            def is_seed(self, seed_e):
                text = self.get_seed_text(seed_e)
       -        return Wallet.is_seed(text) or Wallet.is_mpk(text)
       +        return Wallet.is_seed(text) or Wallet.is_mpk(text) or Wallet.is_address(text) or Wallet.is_private_key(text)
        
        
            def enter_seed_dialog(self, is_restore, sid):
       t@@ -372,6 +373,10 @@ class InstallWizard(QDialog):
                            wallet.create_accounts(password)
                        elif Wallet.is_mpk(text):
                            wallet = Wallet.from_mpk(text, self.storage)
       +                elif Wallet.is_address(text):
       +                    wallet = Wallet.from_address(text, self.storage)
       +                elif Wallet.is_private_key(text):
       +                    wallet = Wallet.from_private_key(text, self.storage)
                        else:
                            raise
        
 (DIR) diff --git a/lib/bitcoin.py b/lib/bitcoin.py
       t@@ -285,6 +285,10 @@ def address_from_private_key(sec):
        
        
        def is_valid(addr):
       +    return is_address(addr)
       +
       +
       +def is_address(addr):
            ADDRESS_RE = re.compile('[1-9A-HJ-NP-Za-km-z]{26,}\\Z')
            if not ADDRESS_RE.match(addr): return False
            try:
       t@@ -294,6 +298,10 @@ def is_valid(addr):
            return addr == hash_160_to_bc_address(h, addrtype)
        
        
       +def is_private_key(key):
       +    return ASecretToSecret(key) is not False
       +
       +
        ########### end pywallet functions #######################
        
        try:
 (DIR) diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -36,6 +36,7 @@ from bitcoin import *
        from account import *
        from transaction import Transaction
        from plugins import run_hook
       +import bitcoin
        
        COINBASE_MATURITY = 100
        DUST_THRESHOLD = 5430
       t@@ -331,6 +332,8 @@ class NewWallet:
                self.add_account("m/", account)
        
        
       +
       +
            def create_accounts(self, password):
                seed = pw_decode(self.seed, password)
                self.create_account('Main account', password)
       t@@ -1480,6 +1483,17 @@ class NewWallet:
        
        
        
       +class Imported_Wallet(NewWallet):
       +
       +    def __init__(self, storage):
       +        NewWallet.__init__(self, storage)
       +
       +    def is_watching_only(self):
       +        n = self.imported_keys.values()
       +        return n == [''] * len(n)
       +
       +
       +
        class Wallet_2of2(NewWallet):
        
            def __init__(self, storage):
       t@@ -1543,7 +1557,6 @@ class Wallet_2of3(Wallet_2of2):
        
        class WalletSynchronizer(threading.Thread):
        
       -
            def __init__(self, wallet, network):
                threading.Thread.__init__(self)
                self.daemon = True
       t@@ -1843,6 +1856,10 @@ class Wallet(object):
                if storage.get('wallet_type') == '2of3':
                    return Wallet_2of3(storage)
        
       +        if storage.file_exists and not storage.get('seed'):
       +            # wallet made of imported keys
       +            return Imported_Wallet(storage)
       +
        
                if not storage.file_exists:
                    seed_version = NEW_SEED_VERSION if config.get('bip32') is True else OLD_SEED_VERSION
       t@@ -1891,7 +1908,20 @@ class Wallet(object):
                        return True
                    except:
                        return False
       -                
       +
       +    @classmethod
       +    def is_address(self, text):
       +        for x in text.split():
       +            if not bitcoin.is_address(x):
       +                return False
       +        return True
       +
       +    @classmethod
       +    def is_private_key(self, text):
       +        for x in text.split():
       +            if not bitcoin.is_private_key(x):
       +                return False
       +        return True
        
            @classmethod
            def from_seed(self, seed, storage):
       t@@ -1903,6 +1933,21 @@ class Wallet(object):
                return w
        
            @classmethod
       +    def from_address(self, text, storage):
       +        w = Imported_Wallet(storage)
       +        for x in text.split():
       +            w.imported_keys[x] = ''
       +        w.storage.put('imported_keys', w.imported_keys, True)
       +        return w
       +
       +    @classmethod
       +    def from_private_key(self, text, storage):
       +        w = Imported_Wallet(storage)
       +        for x in text.split():
       +            w.import_key(x, None)
       +        return w
       +
       +    @classmethod
            def from_mpk(self, mpk, storage):
        
                try: