def load_wallet(self, wallet):
import electrum
+
self.wallet = wallet
+ self.update_wallet_format()
+
self.accounts_expanded = self.wallet.storage.get('accounts_expanded',{})
self.current_account = self.wallet.storage.get("current_account", None)
-
title = 'Electrum ' + self.wallet.electrum_version + ' - ' + self.wallet.storage.path
if self.wallet.is_watching_only(): title += ' [%s]' % (_('watching only'))
self.setWindowTitle( title )
run_hook('load_wallet', wallet)
+ def update_wallet_format(self):
+ # convert old-format imported keys
+ if self.wallet.imported_keys:
+ password = self.password_dialog(_("Please enter your password in order to update imported keys"))
+ try:
+ self.wallet.convert_imported_keys(password)
+ except:
+ self.show_message("error")
+
+
def open_wallet(self):
wallet_folder = self.wallet.storage.path
filename = unicode( QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder) )
QMessageBox.warning(self, _('Error'), _('Incorrect Password'), _('OK'))
return
from seed_dialog import SeedDialog
- d = SeedDialog(self, mnemonic, self.wallet.imported_keys)
+ d = SeedDialog(self, mnemonic, self.wallet.has_imported_keys())
d.exec_()
def show_message(self, msg):
QMessageBox.information(self, _('Message'), msg, _('OK'))
- def password_dialog(self ):
+ def password_dialog(self, msg=None):
d = QDialog(self)
d.setModal(1)
d.setWindowTitle(_("Enter Password"))
pw.setEchoMode(2)
vbox = QVBoxLayout()
- msg = _('Please enter your password')
+ if not msg:
+ msg = _('Please enter your password')
vbox.addWidget(QLabel(msg))
grid = QGridLayout()
@protected
def do_import_privkey(self, password):
- if not self.wallet.imported_keys:
+ if not self.wallet.has_imported_keys():
r = QMessageBox.question(None, _('Warning'), '<b>'+_('Warning') +':\n</b><br/>'+ _('Imported keys are not recoverable from seed.') + ' ' \
+ _('If you ever need to restore your wallet from its seed, these keys will be lost.') + '<p>' \
+ _('Are you sure you understand what you are doing?'), 3, 4)
def get_action(self):
pass
+
+ def convert_imported_keys(self, password):
+ for k, v in self.imported_keys.items():
+ sec = pw_decode(v, password)
+ pubkey = public_key_from_private_key(sec)
+ address = public_key_to_bc_address(pubkey.decode('hex'))
+ assert address == k
+ self.import_key(sec, password)
+ self.imported_keys.pop(k)
+ self.storage.put('imported_keys', self.imported_keys)
+
+
def load_accounts(self):
self.accounts = {}
self.imported_keys = self.storage.get('imported_keys',{})
- if self.imported_keys:
- print_error("cannot load imported keys")
d = self.storage.get('accounts', {})
for k, v in d.items():
else:
return False
+ def has_imported_keys(self):
+ account = self.accounts.get(IMPORTED_ACCOUNT)
+ return account is not None
+
def import_key(self, sec, password):
try:
pubkey = public_key_from_private_key(sec)