update imported keys
This commit is contained in:
parent
650ef92c5f
commit
194291c80b
|
@ -187,10 +187,12 @@ class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
def load_wallet(self, wallet):
|
def load_wallet(self, wallet):
|
||||||
import electrum
|
import electrum
|
||||||
|
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
|
self.update_wallet_format()
|
||||||
|
|
||||||
self.accounts_expanded = self.wallet.storage.get('accounts_expanded',{})
|
self.accounts_expanded = self.wallet.storage.get('accounts_expanded',{})
|
||||||
self.current_account = self.wallet.storage.get("current_account", None)
|
self.current_account = self.wallet.storage.get("current_account", None)
|
||||||
|
|
||||||
title = 'Electrum ' + self.wallet.electrum_version + ' - ' + self.wallet.storage.path
|
title = 'Electrum ' + self.wallet.electrum_version + ' - ' + self.wallet.storage.path
|
||||||
if self.wallet.is_watching_only(): title += ' [%s]' % (_('watching only'))
|
if self.wallet.is_watching_only(): title += ' [%s]' % (_('watching only'))
|
||||||
self.setWindowTitle( title )
|
self.setWindowTitle( title )
|
||||||
|
@ -213,6 +215,16 @@ class ElectrumWindow(QMainWindow):
|
||||||
run_hook('load_wallet', wallet)
|
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):
|
def open_wallet(self):
|
||||||
wallet_folder = self.wallet.storage.path
|
wallet_folder = self.wallet.storage.path
|
||||||
filename = unicode( QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder) )
|
filename = unicode( QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder) )
|
||||||
|
@ -1491,7 +1503,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
QMessageBox.warning(self, _('Error'), _('Incorrect Password'), _('OK'))
|
QMessageBox.warning(self, _('Error'), _('Incorrect Password'), _('OK'))
|
||||||
return
|
return
|
||||||
from seed_dialog import SeedDialog
|
from seed_dialog import SeedDialog
|
||||||
d = SeedDialog(self, mnemonic, self.wallet.imported_keys)
|
d = SeedDialog(self, mnemonic, self.wallet.has_imported_keys())
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1730,7 +1742,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
def show_message(self, msg):
|
def show_message(self, msg):
|
||||||
QMessageBox.information(self, _('Message'), msg, _('OK'))
|
QMessageBox.information(self, _('Message'), msg, _('OK'))
|
||||||
|
|
||||||
def password_dialog(self ):
|
def password_dialog(self, msg=None):
|
||||||
d = QDialog(self)
|
d = QDialog(self)
|
||||||
d.setModal(1)
|
d.setModal(1)
|
||||||
d.setWindowTitle(_("Enter Password"))
|
d.setWindowTitle(_("Enter Password"))
|
||||||
|
@ -1739,7 +1751,8 @@ class ElectrumWindow(QMainWindow):
|
||||||
pw.setEchoMode(2)
|
pw.setEchoMode(2)
|
||||||
|
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
msg = _('Please enter your password')
|
if not msg:
|
||||||
|
msg = _('Please enter your password')
|
||||||
vbox.addWidget(QLabel(msg))
|
vbox.addWidget(QLabel(msg))
|
||||||
|
|
||||||
grid = QGridLayout()
|
grid = QGridLayout()
|
||||||
|
@ -2118,7 +2131,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
def do_import_privkey(self, password):
|
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.') + ' ' \
|
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>' \
|
+ _('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)
|
+ _('Are you sure you understand what you are doing?'), 3, 4)
|
||||||
|
|
|
@ -221,11 +221,21 @@ class Abstract_Wallet:
|
||||||
def get_action(self):
|
def get_action(self):
|
||||||
pass
|
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):
|
def load_accounts(self):
|
||||||
self.accounts = {}
|
self.accounts = {}
|
||||||
self.imported_keys = self.storage.get('imported_keys',{})
|
self.imported_keys = self.storage.get('imported_keys',{})
|
||||||
if self.imported_keys:
|
|
||||||
print_error("cannot load imported keys")
|
|
||||||
|
|
||||||
d = self.storage.get('accounts', {})
|
d = self.storage.get('accounts', {})
|
||||||
for k, v in d.items():
|
for k, v in d.items():
|
||||||
|
@ -271,6 +281,10 @@ class Abstract_Wallet:
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def has_imported_keys(self):
|
||||||
|
account = self.accounts.get(IMPORTED_ACCOUNT)
|
||||||
|
return account is not None
|
||||||
|
|
||||||
def import_key(self, sec, password):
|
def import_key(self, sec, password):
|
||||||
try:
|
try:
|
||||||
pubkey = public_key_from_private_key(sec)
|
pubkey = public_key_from_private_key(sec)
|
||||||
|
|
Loading…
Reference in New Issue