generic restore from command line
This commit is contained in:
parent
614f3df4b8
commit
26682491b2
29
electrum
29
electrum
|
@ -136,26 +136,17 @@ def init_cmdline(config):
|
||||||
if cmd.name in ['create', 'restore']:
|
if cmd.name in ['create', 'restore']:
|
||||||
if storage.file_exists:
|
if storage.file_exists:
|
||||||
sys.exit("Error: Remove the existing wallet first!")
|
sys.exit("Error: Remove the existing wallet first!")
|
||||||
if config.get('password') is not None:
|
|
||||||
password = config.get('password')
|
def password_dialog():
|
||||||
elif cmd.name == 'restore' and config.get('mpk'):
|
return prompt_password("Password (hit return if you do not wish to encrypt your wallet):")
|
||||||
password = None
|
|
||||||
else:
|
|
||||||
password = prompt_password("Password (hit return if you do not wish to encrypt your wallet):")
|
|
||||||
|
|
||||||
if cmd.name == 'restore':
|
if cmd.name == 'restore':
|
||||||
mpk = config.get('mpk')
|
import getpass
|
||||||
if mpk:
|
text = getpass.getpass(prompt="seed:", stream=None) if config.get('concealed') else raw_input("seed or key(s):")
|
||||||
if Wallet.is_old_mpk(mpk):
|
try:
|
||||||
wallet = Wallet.from_old_mpk(mpk, storage)
|
wallet = Wallet.from_text(text, password_dialog, storage)
|
||||||
if Wallet.is_xpub(mpk):
|
except BaseException as e:
|
||||||
wallet = Wallet.from_xpub(mpk, storage)
|
sys.exit(str(e))
|
||||||
else:
|
|
||||||
import getpass
|
|
||||||
seed = getpass.getpass(prompt="seed:", stream=None) if config.get('concealed') else raw_input("seed:")
|
|
||||||
if not Wallet.is_seed(seed):
|
|
||||||
sys.exit("Error: Invalid seed")
|
|
||||||
wallet = Wallet.from_seed(seed, password, storage)
|
|
||||||
|
|
||||||
if not config.get('offline'):
|
if not config.get('offline'):
|
||||||
network = Network(config)
|
network = Network(config)
|
||||||
|
@ -163,6 +154,7 @@ def init_cmdline(config):
|
||||||
wallet.start_threads(network)
|
wallet.start_threads(network)
|
||||||
print_msg("Recovering wallet...")
|
print_msg("Recovering wallet...")
|
||||||
wallet.restore(lambda x: x)
|
wallet.restore(lambda x: x)
|
||||||
|
wallet.synchronize()
|
||||||
if wallet.is_found():
|
if wallet.is_found():
|
||||||
print_msg("Recovery successful")
|
print_msg("Recovery successful")
|
||||||
else:
|
else:
|
||||||
|
@ -172,6 +164,7 @@ def init_cmdline(config):
|
||||||
print_msg("Warning: This wallet was restored offline. It may contain more addresses than displayed.")
|
print_msg("Warning: This wallet was restored offline. It may contain more addresses than displayed.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
password = password_dialog()
|
||||||
wallet = Wallet(storage)
|
wallet = Wallet(storage)
|
||||||
seed = wallet.make_seed()
|
seed = wallet.make_seed()
|
||||||
wallet.add_seed(seed, password)
|
wallet.add_seed(seed, password)
|
||||||
|
|
|
@ -561,47 +561,26 @@ class InstallWizard(QDialog):
|
||||||
|
|
||||||
|
|
||||||
def restore(self, t):
|
def restore(self, t):
|
||||||
|
if t == 'standard':
|
||||||
if t == 'standard':
|
text = self.enter_seed_dialog(MSG_ENTER_ANYTHING, None)
|
||||||
text = self.enter_seed_dialog(MSG_ENTER_ANYTHING, None)
|
if not text:
|
||||||
if not text:
|
return
|
||||||
return
|
wallet = Wallet.from_text(text, self.password_dialog, self.storage)
|
||||||
if Wallet.is_xprv(text):
|
elif re.match('(\d+)of(\d+)', t):
|
||||||
password = self.password_dialog()
|
n = int(re.match('(\d+)of(\d+)', t).group(2))
|
||||||
wallet = Wallet.from_xprv(text, password, self.storage)
|
key_list = self.multi_seed_dialog(n - 1)
|
||||||
elif Wallet.is_old_mpk(text):
|
if not key_list:
|
||||||
wallet = Wallet.from_old_mpk(text, self.storage)
|
return
|
||||||
elif Wallet.is_xpub(text):
|
password = self.password_dialog() if any(map(lambda x: Wallet.is_seed(x) or Wallet.is_xprv(x), key_list)) else None
|
||||||
wallet = Wallet.from_xpub(text, self.storage)
|
wallet = Wallet.from_multisig(key_list, password, self.storage, t)
|
||||||
elif Wallet.is_address(text):
|
else:
|
||||||
wallet = Wallet.from_address(text, self.storage)
|
self.storage.put('wallet_type', t, False)
|
||||||
elif Wallet.is_private_key(text):
|
# call the constructor to load the plugin (side effect)
|
||||||
password = self.password_dialog()
|
Wallet(self.storage)
|
||||||
wallet = Wallet.from_private_key(text, password, self.storage)
|
wallet = always_hook('installwizard_restore', self, self.storage)
|
||||||
elif Wallet.is_seed(text):
|
if not wallet:
|
||||||
password = self.password_dialog()
|
util.print_error("no wallet")
|
||||||
wallet = Wallet.from_seed(text, password, self.storage)
|
return
|
||||||
else:
|
# create first keys offline
|
||||||
raise BaseException('unknown wallet type')
|
self.waiting_dialog(wallet.synchronize)
|
||||||
|
return wallet
|
||||||
elif re.match('(\d+)of(\d+)', t):
|
|
||||||
n = int(re.match('(\d+)of(\d+)', t).group(2))
|
|
||||||
key_list = self.multi_seed_dialog(n - 1)
|
|
||||||
if not key_list:
|
|
||||||
return
|
|
||||||
password = self.password_dialog() if any(map(lambda x: Wallet.is_seed(x) or Wallet.is_xprv(x), key_list)) else None
|
|
||||||
wallet = Wallet.from_multisig(key_list, password, self.storage, t)
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.storage.put('wallet_type', t, False)
|
|
||||||
# call the constructor to load the plugin (side effect)
|
|
||||||
Wallet(self.storage)
|
|
||||||
wallet = always_hook('installwizard_restore', self, self.storage)
|
|
||||||
if not wallet:
|
|
||||||
util.print_error("no wallet")
|
|
||||||
return
|
|
||||||
|
|
||||||
# create first keys offline
|
|
||||||
self.waiting_dialog(wallet.synchronize)
|
|
||||||
|
|
||||||
return wallet
|
|
||||||
|
|
|
@ -103,8 +103,10 @@ class Commands:
|
||||||
"""Create a new wallet"""
|
"""Create a new wallet"""
|
||||||
|
|
||||||
@command('')
|
@command('')
|
||||||
def restore(self, concealed=False, mpk=None):
|
def restore(self, concealed=False):
|
||||||
"""Restore a wallet from seed. """
|
"""Restore a wallet. A wallet can be restored from a seed phrase, a
|
||||||
|
master public key, a master private key, a list of bitcoin addresses
|
||||||
|
or bitcoin private keys."""
|
||||||
|
|
||||||
@command('w')
|
@command('w')
|
||||||
def deseed(self):
|
def deseed(self):
|
||||||
|
@ -629,7 +631,6 @@ command_options = {
|
||||||
'entropy': (None, "--entropy", "Custom entropy"),
|
'entropy': (None, "--entropy", "Custom entropy"),
|
||||||
'language': ("-L", "--lang", "Default language for wordlist"),
|
'language': ("-L", "--lang", "Default language for wordlist"),
|
||||||
'gap_limit': ("-G", "--gap", "Gap limit"),
|
'gap_limit': ("-G", "--gap", "Gap limit"),
|
||||||
'mpk': (None, "--mpk", "Restore from master public key"),
|
|
||||||
'deserialized':("-d", "--deserialized","Return deserialized transaction"),
|
'deserialized':("-d", "--deserialized","Return deserialized transaction"),
|
||||||
'privkey': (None, "--privkey", "Private key. Set to '?' to get a prompt."),
|
'privkey': (None, "--privkey", "Private key. Set to '?' to get a prompt."),
|
||||||
'unsigned': ("-u", "--unsigned", "Do not sign transaction"),
|
'unsigned': ("-u", "--unsigned", "Do not sign transaction"),
|
||||||
|
|
|
@ -2085,3 +2085,24 @@ class Wallet(object):
|
||||||
self.storage.put('use_encryption', self.use_encryption, True)
|
self.storage.put('use_encryption', self.use_encryption, True)
|
||||||
self.create_main_account(password)
|
self.create_main_account(password)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_text(klass, text, password_dialog, storage):
|
||||||
|
if Wallet.is_xprv(text):
|
||||||
|
password = password_dialog()
|
||||||
|
wallet = klass.from_xprv(text, password, storage)
|
||||||
|
elif Wallet.is_old_mpk(text):
|
||||||
|
wallet = klass.from_old_mpk(text, storage)
|
||||||
|
elif Wallet.is_xpub(text):
|
||||||
|
wallet = klass.from_xpub(text, storage)
|
||||||
|
elif Wallet.is_address(text):
|
||||||
|
wallet = klass.from_address(text, storage)
|
||||||
|
elif Wallet.is_private_key(text):
|
||||||
|
password = password_dialog()
|
||||||
|
wallet = klass.from_private_key(text, password, storage)
|
||||||
|
elif Wallet.is_seed(text):
|
||||||
|
password = password_dialog()
|
||||||
|
wallet = klass.from_seed(text, password, storage)
|
||||||
|
else:
|
||||||
|
raise BaseException('Invalid seedphrase or key')
|
||||||
|
return wallet
|
||||||
|
|
Loading…
Reference in New Issue