electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit c2a42520655cbd8d652d4a3f40dd8df9ab2c61cf
parent 6035fe974c34c7910c5af5d0a3443ed7ffd9e4fd
Author: ThomasV <thomasv@gitorious>
Date:   Fri,  8 May 2015 10:58:54 +0200

do not pass config to storage. request height from network_proxy if connected

Diffstat:
Melectrum | 2+-
Mgui/android.py | 2+-
Mgui/gtk.py | 2+-
Mgui/qt/__init__.py | 2+-
Mgui/qt/main_window.py | 2+-
Mgui/stdio.py | 2+-
Mgui/text.py | 2+-
Mlib/simple_config.py | 29+++++++++++++++++++++++++++++
Mlib/wallet.py | 40+++++++---------------------------------
Mscripts/authenticator.py | 2+-
10 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/electrum b/electrum @@ -296,7 +296,7 @@ if __name__ == '__main__': cmd = known_commands[cmd] # instanciate wallet for command-line - storage = WalletStorage(config) + storage = WalletStorage(config.get_wallet_path()) if cmd.name in ['create', 'restore']: if storage.file_exists: diff --git a/gui/android.py b/gui/android.py @@ -907,7 +907,7 @@ class ElectrumGui: contacts = util.StoreDict(config, 'contacts') - storage = WalletStorage(config) + storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists: action = self.restore_or_create() if not action: diff --git a/gui/gtk.py b/gui/gtk.py @@ -1290,7 +1290,7 @@ class ElectrumGui(): def main(self, url=None): - storage = WalletStorage(self.config) + storage = WalletStorage(self.config.get_wallet_path()) if not storage.file_exists: action = self.restore_or_create() if not action: diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py @@ -179,7 +179,7 @@ class ElectrumGui: if os.path.exists(last_wallet): self.config.read_only_options['default_wallet_path'] = last_wallet try: - storage = WalletStorage(self.config) + storage = WalletStorage(self.config.get_wallet_path()) except BaseException as e: QMessageBox.warning(None, _('Warning'), str(e), _('OK')) self.config.set_key('gui_last_wallet', None) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -264,7 +264,7 @@ class ElectrumWindow(QMainWindow): if not filename: return try: - storage = WalletStorage({'wallet_path': filename}) + storage = WalletStorage(filename) except Exception as e: self.show_message(str(e)) return diff --git a/gui/stdio.py b/gui/stdio.py @@ -15,7 +15,7 @@ class ElectrumGui: def __init__(self, config, network): self.network = network self.config = config - storage = WalletStorage(config) + storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists: print "Wallet not found. try 'electrum create'" exit() diff --git a/gui/text.py b/gui/text.py @@ -17,7 +17,7 @@ class ElectrumGui: self.config = config self.network = network - storage = WalletStorage(config) + storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists: print "Wallet not found. try 'electrum create'" exit() diff --git a/lib/simple_config.py b/lib/simple_config.py @@ -146,6 +146,35 @@ class SimpleConfig(object): import stat os.chmod(path, stat.S_IREAD | stat.S_IWRITE) + def get_wallet_path(self): + """Set the path of the wallet.""" + + # command line -w option + path = self.get('wallet_path') + if path: + return path + + # path in config file + path = self.get('default_wallet_path') + if path and os.path.exists(path): + return path + + # default path + dirpath = os.path.join(self.path, "wallets") + if not os.path.exists(dirpath): + os.mkdir(dirpath) + + new_path = os.path.join(self.path, "wallets", "default_wallet") + + # default path in pre 1.9 versions + old_path = os.path.join(self.path, "electrum.dat") + if os.path.exists(old_path) and not os.path.exists(new_path): + os.rename(old_path, new_path) + + return new_path + + + def read_system_config(path=SYSTEM_CONFIG_PATH): """Parse and return the system config settings in /etc/electrum.conf.""" result = {} diff --git a/lib/wallet.py b/lib/wallet.py @@ -48,43 +48,15 @@ IMPORTED_ACCOUNT = '/x' class WalletStorage(object): - def __init__(self, config): + def __init__(self, path): self.lock = threading.RLock() - self.config = config self.data = {} + self.path = path self.file_exists = False - self.path = self.init_path(config) print_error( "wallet path", self.path ) if self.path: self.read(self.path) - def init_path(self, config): - """Set the path of the wallet.""" - - # command line -w option - path = config.get('wallet_path') - if path: - return path - - # path in config file - path = config.get('default_wallet_path') - if path and os.path.exists(path): - return path - - # default path - dirpath = os.path.join(config.path, "wallets") - if not os.path.exists(dirpath): - os.mkdir(dirpath) - - new_path = os.path.join(config.path, "wallets", "default_wallet") - - # default path in pre 1.9 versions - old_path = os.path.join(config.path, "electrum.dat") - if os.path.exists(old_path) and not os.path.exists(new_path): - os.rename(old_path, new_path) - - return new_path - def read(self, path): """Read the contents of the wallet file.""" try: @@ -425,8 +397,9 @@ class Abstract_Wallet(object): return txs def get_local_height(self): - '''This does not require a network so works in offline mode''' - return self.storage.config.height + """ todo: fetch height in offline mode """ + return self.network.get_local_height() if self.network else 0 + def get_confirmations(self, tx): """ return the number of confirmations of a monitored transaction. """ @@ -1484,7 +1457,8 @@ class BIP32_Wallet(Deterministic_Wallet): return Mnemonic.mnemonic_to_seed(seed, password) def make_seed(self): - lang = self.storage.config.get('language') + # fixme lang = self.storage.config.get('language') + lang = None return Mnemonic(lang).make_seed() def format_seed(self, seed): diff --git a/scripts/authenticator.py b/scripts/authenticator.py @@ -174,7 +174,7 @@ class Authenticator: def __init__(self): global wallet self.qr_data = None - storage = WalletStorage({'wallet_path':'/sdcard/electrum/authenticator'}) + storage = WalletStorage('/sdcard/electrum/authenticator') if not storage.file_exists: action = self.restore_or_create()