fix #1494
This commit is contained in:
28
electrum
28
electrum
@@ -142,26 +142,12 @@ def init_cmdline(config):
|
|||||||
|
|
||||||
if cmd.name == 'restore':
|
if cmd.name == 'restore':
|
||||||
text = config.get('text')
|
text = config.get('text')
|
||||||
|
password = password_dialog() if Wallet.is_seed(text) or Wallet.is_xprv(text) or Wallet.is_private_key(text) else None
|
||||||
try:
|
try:
|
||||||
wallet = Wallet.from_text(text, password_dialog, storage)
|
wallet = Wallet.from_text(text, password, storage)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
sys.exit(str(e))
|
sys.exit(str(e))
|
||||||
|
wallet.synchronize()
|
||||||
if not config.get('offline'):
|
|
||||||
network = Network(config)
|
|
||||||
network.start()
|
|
||||||
wallet.start_threads(network)
|
|
||||||
print_msg("Recovering wallet...")
|
|
||||||
wallet.restore(lambda x: x)
|
|
||||||
wallet.synchronize()
|
|
||||||
if wallet.is_found():
|
|
||||||
print_msg("Recovery successful")
|
|
||||||
else:
|
|
||||||
print_msg("Warning: Found no history for this wallet")
|
|
||||||
else:
|
|
||||||
wallet.synchronize()
|
|
||||||
print_msg("Warning: This wallet was restored offline. It may contain more addresses than displayed.")
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
password = password_dialog()
|
password = password_dialog()
|
||||||
wallet = Wallet(storage)
|
wallet = Wallet(storage)
|
||||||
@@ -174,8 +160,6 @@ def init_cmdline(config):
|
|||||||
print_msg("Please keep it in a safe place; if you lose it, you will not be able to restore your wallet.")
|
print_msg("Please keep it in a safe place; if you lose it, you will not be able to restore your wallet.")
|
||||||
|
|
||||||
print_msg("Wallet saved in '%s'" % wallet.storage.path)
|
print_msg("Wallet saved in '%s'" % wallet.storage.path)
|
||||||
# terminate
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
if cmd.name not in ['create', 'restore'] and cmd.requires_wallet and not storage.file_exists:
|
if cmd.name not in ['create', 'restore'] and cmd.requires_wallet and not storage.file_exists:
|
||||||
print_msg("Error: Wallet file not found.")
|
print_msg("Error: Wallet file not found.")
|
||||||
@@ -248,6 +232,9 @@ def run_command(config, network, password):
|
|||||||
storage = WalletStorage(config.get_wallet_path())
|
storage = WalletStorage(config.get_wallet_path())
|
||||||
# create wallet instance
|
# create wallet instance
|
||||||
wallet = Wallet(storage) if cmd.requires_wallet else None
|
wallet = Wallet(storage) if cmd.requires_wallet else None
|
||||||
|
# start threads
|
||||||
|
if network:
|
||||||
|
wallet.start_threads(network)
|
||||||
# arguments passed to function
|
# arguments passed to function
|
||||||
args = map(lambda x: config.get(x), cmd.params)
|
args = map(lambda x: config.get(x), cmd.params)
|
||||||
# decode json arguments
|
# decode json arguments
|
||||||
@@ -264,10 +251,9 @@ def run_command(config, network, password):
|
|||||||
cmd_runner.password = password
|
cmd_runner.password = password
|
||||||
func = getattr(cmd_runner, cmd.name)
|
func = getattr(cmd_runner, cmd.name)
|
||||||
result = func(*args)
|
result = func(*args)
|
||||||
|
# stop threads
|
||||||
if wallet:
|
if wallet:
|
||||||
wallet.stop_threads()
|
wallet.stop_threads()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -565,7 +565,8 @@ class InstallWizard(QDialog):
|
|||||||
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)
|
password = self.password_dialog() if Wallet.is_seed(text) or Wallet.is_xprv(text) or Wallet.is_private_key(text) else None
|
||||||
|
wallet = Wallet.from_text(text, password, self.storage)
|
||||||
elif re.match('(\d+)of(\d+)', t):
|
elif re.match('(\d+)of(\d+)', t):
|
||||||
n = int(re.match('(\d+)of(\d+)', t).group(2))
|
n = int(re.match('(\d+)of(\d+)', t).group(2))
|
||||||
key_list = self.multi_seed_dialog(n - 1)
|
key_list = self.multi_seed_dialog(n - 1)
|
||||||
|
|||||||
@@ -101,13 +101,20 @@ class Commands:
|
|||||||
@command('')
|
@command('')
|
||||||
def create(self):
|
def create(self):
|
||||||
"""Create a new wallet"""
|
"""Create a new wallet"""
|
||||||
|
return True
|
||||||
|
|
||||||
@command('')
|
@command('wn')
|
||||||
def restore(self, text):
|
def restore(self, text):
|
||||||
"""Restore a wallet from text. Text can be a seed phrase, a master
|
"""Restore a wallet from text. Text can be a seed phrase, a master
|
||||||
public key, a master private key, a list of bitcoin addresses
|
public key, a master private key, a list of bitcoin addresses
|
||||||
or bitcoin private keys. If you want to be prompted for your
|
or bitcoin private keys. If you want to be prompted for your
|
||||||
seed, type '?' or ':' (concealed) """
|
seed, type '?' or ':' (concealed) """
|
||||||
|
self.wallet.restore(lambda x: print_msg(x))
|
||||||
|
#self.wallet.synchronize()
|
||||||
|
msg = "Recovery successful" if self.wallet.is_found() else "Warning: Found no history for this wallet"
|
||||||
|
if not self.network:
|
||||||
|
msg += "\nWarning: This wallet was restored offline. It may contain more addresses than displayed."
|
||||||
|
return msg
|
||||||
|
|
||||||
@command('w')
|
@command('w')
|
||||||
def deseed(self):
|
def deseed(self):
|
||||||
|
|||||||
@@ -1135,8 +1135,28 @@ class Abstract_Wallet(PrintError):
|
|||||||
self.verifier = None
|
self.verifier = None
|
||||||
self.storage.put('stored_height', self.get_local_height(), True)
|
self.storage.put('stored_height', self.get_local_height(), True)
|
||||||
|
|
||||||
def restore(self, cb):
|
def restore(self, callback):
|
||||||
pass
|
from i18n import _
|
||||||
|
def wait_for_wallet():
|
||||||
|
self.set_up_to_date(False)
|
||||||
|
while not self.is_up_to_date():
|
||||||
|
msg = "%s\n%s %d"%(
|
||||||
|
_("Please wait..."),
|
||||||
|
_("Addresses generated:"),
|
||||||
|
len(self.addresses(True)))
|
||||||
|
apply(callback, (msg,))
|
||||||
|
time.sleep(0.1)
|
||||||
|
def wait_for_network():
|
||||||
|
while not self.network.is_connected():
|
||||||
|
msg = "%s \n" % (_("Connecting..."))
|
||||||
|
apply(callback, (msg,))
|
||||||
|
time.sleep(0.1)
|
||||||
|
# wait until we are connected, because the user might have selected another server
|
||||||
|
if self.network:
|
||||||
|
wait_for_network()
|
||||||
|
wait_for_wallet()
|
||||||
|
else:
|
||||||
|
self.synchronize()
|
||||||
|
|
||||||
def get_accounts(self):
|
def get_accounts(self):
|
||||||
return self.accounts
|
return self.accounts
|
||||||
@@ -1509,32 +1529,6 @@ class Deterministic_Wallet(Abstract_Wallet):
|
|||||||
for account in self.accounts.values():
|
for account in self.accounts.values():
|
||||||
account.synchronize(self)
|
account.synchronize(self)
|
||||||
|
|
||||||
def restore(self, callback):
|
|
||||||
from i18n import _
|
|
||||||
def wait_for_wallet():
|
|
||||||
self.set_up_to_date(False)
|
|
||||||
while not self.is_up_to_date():
|
|
||||||
msg = "%s\n%s %d"%(
|
|
||||||
_("Please wait..."),
|
|
||||||
_("Addresses generated:"),
|
|
||||||
len(self.addresses(True)))
|
|
||||||
|
|
||||||
apply(callback, (msg,))
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
def wait_for_network():
|
|
||||||
while not self.network.is_connected():
|
|
||||||
msg = "%s \n" % (_("Connecting..."))
|
|
||||||
apply(callback, (msg,))
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
# wait until we are connected, because the user might have selected another server
|
|
||||||
if self.network:
|
|
||||||
wait_for_network()
|
|
||||||
wait_for_wallet()
|
|
||||||
else:
|
|
||||||
self.synchronize()
|
|
||||||
|
|
||||||
def is_beyond_limit(self, address, account, is_change):
|
def is_beyond_limit(self, address, account, is_change):
|
||||||
if type(account) == ImportedAccount:
|
if type(account) == ImportedAccount:
|
||||||
return False
|
return False
|
||||||
@@ -2089,9 +2083,8 @@ class Wallet(object):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_text(klass, text, password_dialog, storage):
|
def from_text(klass, text, password, storage):
|
||||||
if Wallet.is_xprv(text):
|
if Wallet.is_xprv(text):
|
||||||
password = password_dialog()
|
|
||||||
wallet = klass.from_xprv(text, password, storage)
|
wallet = klass.from_xprv(text, password, storage)
|
||||||
elif Wallet.is_old_mpk(text):
|
elif Wallet.is_old_mpk(text):
|
||||||
wallet = klass.from_old_mpk(text, storage)
|
wallet = klass.from_old_mpk(text, storage)
|
||||||
@@ -2100,10 +2093,8 @@ class Wallet(object):
|
|||||||
elif Wallet.is_address(text):
|
elif Wallet.is_address(text):
|
||||||
wallet = klass.from_address(text, storage)
|
wallet = klass.from_address(text, storage)
|
||||||
elif Wallet.is_private_key(text):
|
elif Wallet.is_private_key(text):
|
||||||
password = password_dialog()
|
|
||||||
wallet = klass.from_private_key(text, password, storage)
|
wallet = klass.from_private_key(text, password, storage)
|
||||||
elif Wallet.is_seed(text):
|
elif Wallet.is_seed(text):
|
||||||
password = password_dialog()
|
|
||||||
wallet = klass.from_seed(text, password, storage)
|
wallet = klass.from_seed(text, password, storage)
|
||||||
else:
|
else:
|
||||||
raise BaseException('Invalid seedphrase or key')
|
raise BaseException('Invalid seedphrase or key')
|
||||||
|
|||||||
Reference in New Issue
Block a user