1
0

generic restore from command line

This commit is contained in:
ThomasV
2015-10-27 14:33:41 +01:00
parent 614f3df4b8
commit 26682491b2
4 changed files with 59 additions and 65 deletions

View File

@@ -103,8 +103,10 @@ class Commands:
"""Create a new wallet"""
@command('')
def restore(self, concealed=False, mpk=None):
"""Restore a wallet from seed. """
def restore(self, concealed=False):
"""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')
def deseed(self):
@@ -629,7 +631,6 @@ command_options = {
'entropy': (None, "--entropy", "Custom entropy"),
'language': ("-L", "--lang", "Default language for wordlist"),
'gap_limit': ("-G", "--gap", "Gap limit"),
'mpk': (None, "--mpk", "Restore from master public key"),
'deserialized':("-d", "--deserialized","Return deserialized transaction"),
'privkey': (None, "--privkey", "Private key. Set to '?' to get a prompt."),
'unsigned': ("-u", "--unsigned", "Do not sign transaction"),

View File

@@ -2085,3 +2085,24 @@ class Wallet(object):
self.storage.put('use_encryption', self.use_encryption, True)
self.create_main_account(password)
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