commit e955ee69a8fc68212076583b877ccba3cbd77159
parent 9ddd9c7c65eaada61d20079b83625885c4775d1d
Author: ThomasV <thomasv@gitorious>
Date: Fri, 28 Feb 2014 15:43:06 +0100
restore from master public key (qt and command line)
Diffstat:
3 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/electrum b/electrum
@@ -90,6 +90,7 @@ def arg_parser():
parser.add_option("-W", "--password", dest="password", default=None, help="set password for usage with commands (currently only implemented for create command, do not use it for longrunning gui session since the password is visible in /proc)")
parser.add_option("-1", "--oneserver", action="store_true", dest="oneserver", default=False, help="connect to one server only")
parser.add_option("--bip32", action="store_true", dest="bip32", default=False, help="bip32")
+ parser.add_option("--mpk", dest="mpk", default=False, help="master public key")
return parser
@@ -265,6 +266,8 @@ if __name__ == '__main__':
sys.exit("Error: Remove the existing wallet first!")
if options.password is not None:
password = options.password
+ elif cmd.name == 'restore' and options.mpk:
+ password = None
else:
password = prompt_password("Password (hit return if you do not wish to encrypt your wallet):")
@@ -282,12 +285,16 @@ if __name__ == '__main__':
# wallet.change_gap_limit(int(gap))
if cmd.name == 'restore':
- import getpass
- seed = getpass.getpass(prompt="seed:", stream=None) if options.concealed else raw_input("seed:")
- wallet = Wallet.from_seed(str(seed),storage)
- if not wallet:
- sys.exit("Error: Invalid seed")
- wallet.save_seed(password)
+ if options.mpk:
+ wallet = Wallet.from_mpk(options.mpk, storage)
+ else:
+ import getpass
+ seed = getpass.getpass(prompt="seed:", stream=None) if options.concealed else raw_input("seed:")
+ wallet = Wallet.from_seed(str(seed),storage)
+ if not wallet:
+ sys.exit("Error: Invalid seed")
+ wallet.save_seed(password)
+
if not options.offline:
network = Network(config)
network.start()
diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py
@@ -167,12 +167,6 @@ class InstallWizard(QDialog):
mpk_e.setMaximumHeight(100)
grid.addWidget(mpk_e, 0, 1)
- label = QLabel(_("Chain"))
- #grid.addWidget(label, 1, 0)
- chain_e = QTextEdit()
- chain_e.setMaximumHeight(100)
- #grid.addWidget(chain_e, 1, 1)
-
vbox.addLayout(grid)
vbox.addStretch(1)
@@ -183,8 +177,7 @@ class InstallWizard(QDialog):
return None
mpk = str(mpk_e.toPlainText()).strip()
- chain = str(chain_e.toPlainText()).strip()
- return mpk, chain
+ return mpk
def network_dialog(self):
@@ -289,8 +282,7 @@ class InstallWizard(QDialog):
mpk = self.mpk_dialog()
if not mpk:
return
- wallet.seed = ''
- wallet.create_watching_only_wallet(mpk)
+ wallet = Wallet.from_mpk(mpk, self.storage)
else: raise
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -1809,7 +1809,6 @@ class Wallet(object):
-
@classmethod
def from_seed(self, seed, storage):
import mnemonic
@@ -1835,8 +1834,26 @@ class Wallet(object):
w.init_seed(seed) #hex
else:
#assert is_seed(seed)
- w = Wallet(storage)
+ w = NewWallet(storage)
w.init_seed(seed)
+ return w
+
+
+ @classmethod
+ def from_mpk(self, s, storage):
+ try:
+ mpk, chain = s.split(':')
+ except:
+ mpk = s
+ chain = False
+
+ if chain:
+ w = NewWallet(storage)
+ w.create_watching_only_wallet(mpk, chain)
+ else:
+ w = OldWallet(storage)
+ w.seed = ''
+ w.create_watching_only_wallet(mpk)
return w