electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 98f7d36313130746cb574f3627cf6f6d184dca69
parent bc4671ac34df5b3f691d8d85d9588f578b309a6d
Author: thomasv <thomasv@gitorious>
Date:   Tue,  9 Apr 2013 18:08:14 +0200

ask users to enter their seed on create

Diffstat:
Melectrum | 25+++++++++++++++----------
Mgui/gui_android.py | 3+++
Mgui/gui_classic.py | 127+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Mgui/gui_gtk.py | 4++++
Mgui/gui_text.py | 4+++-
Mlib/interface.py | 2+-
Mlib/wallet.py | 4+++-
7 files changed, 102 insertions(+), 67 deletions(-)

diff --git a/electrum b/electrum @@ -126,8 +126,6 @@ if __name__ == '__main__': interface = Interface(config, True) wallet.interface = interface - interface.start(wait = False) - interface.send([('server.peers.subscribe',[])]) gui = gui.ElectrumGui(wallet, config) @@ -135,11 +133,16 @@ if __name__ == '__main__': if not found: a = gui.restore_or_create() if not a: exit() - # select a server. - s = gui.network_dialog() if a =='create': wallet.init_seed(None) + # display seed + gui.show_seed() + + # retype seed + if not gui.verify_seed(): + exit() + else: # ask for seed and gap. sg = gui.seed_dialog() @@ -153,13 +156,15 @@ if __name__ == '__main__': else: wallet.init_seed(str(seed)) + # select a server. + s = gui.network_dialog() + + interface.start(wait = False) + interface.send([('server.peers.subscribe',[])]) - # generate the first addresses, in case we are offline - if s is None or a == 'create': - wallet.synchronize() - if a == 'create': - # display seed - gui.show_seed() + # generate the first addresses, in case we are offline + if not found and ( s is None or a == 'create'): + wallet.synchronize() verifier = WalletVerifier(interface, config) verifier.start() diff --git a/gui/gui_android.py b/gui/gui_android.py @@ -969,6 +969,9 @@ class ElectrumGui: def network_dialog(self): return True + def verify_seed(self): + self.wallet.save_seed() + return True def show_seed(self): modal_dialog('Your seed is:', wallet.seed) diff --git a/gui/gui_classic.py b/gui/gui_classic.py @@ -1604,57 +1604,6 @@ class ElectrumWindow(QMainWindow): parent.password_button.setIcon( icon ) - @staticmethod - def seed_dialog(wallet, parent=None): - d = QDialog(parent) - d.setModal(1) - - vbox = QVBoxLayout() - msg = _("Please enter your wallet seed (or your master public key if you want to create a watching-only wallet)." + '\n') - vbox.addWidget(QLabel(msg)) - - grid = QGridLayout() - grid.setSpacing(8) - - seed_e = QLineEdit() - grid.addWidget(QLabel(_('Seed or master public key')), 1, 0) - grid.addWidget(seed_e, 1, 1) - grid.addWidget(HelpButton(_("Your seed can be entered as a mnemonic (sequence of words), or as a hexadecimal string.")), 1, 3) - - gap_e = AmountEdit(None, True) - gap_e.setText("5") - grid.addWidget(QLabel(_('Gap limit')), 2, 0) - grid.addWidget(gap_e, 2, 1) - grid.addWidget(HelpButton(_('Keep the default value unless you modified this parameter in your wallet.')), 2, 3) - vbox.addLayout(grid) - - vbox.addLayout(ok_cancel_buttons(d)) - d.setLayout(vbox) - - if not d.exec_(): return - - try: - gap = int(unicode(gap_e.text())) - except: - QMessageBox.warning(None, _('Error'), 'error', 'OK') - return - - try: - seed = str(seed_e.text()) - seed.decode('hex') - except: - print_error("Warning: Not hex, trying decode") - try: - seed = mnemonic.mn_decode( seed.split(' ') ) - except: - QMessageBox.warning(None, _('Error'), _('I cannot decode this'), _('OK')) - return - - if not seed: - QMessageBox.warning(None, _('Error'), _('No seed'), _('OK')) - return - - return seed, gap def generate_transaction_information_widget(self, tx): tabs = QTabWidget(self) @@ -2352,8 +2301,79 @@ class ElectrumGui: if r==2: return None return 'restore' if r==1 else 'create' - def seed_dialog(self): - return ElectrumWindow.seed_dialog( self.wallet ) + + def verify_seed(self): + r = self.seed_dialog(False) + if not r: return False + if r[0] != self.wallet.seed: + QMessageBox.warning(None, _('Error'), 'incorrect seed', 'OK') + return False + else: + self.wallet.save_seed() + return True + + + + def seed_dialog(self, is_restore=True): + d = QDialog() + d.setModal(1) + + vbox = QVBoxLayout() + if is_restore: + msg = _("Please enter your wallet seed (or your master public key if you want to create a watching-only wallet)." + '\n') + else: + msg = _("Please type your seed." + '\n') + + vbox.addWidget(QLabel(msg)) + + grid = QGridLayout() + grid.setSpacing(8) + + seed_e = QLineEdit() + seed_e.setMinimumWidth(400) + grid.addWidget(QLabel(_('Seed or master public key') if is_restore else _('Seed')), 1, 0) + grid.addWidget(seed_e, 1, 1) + grid.addWidget(HelpButton(_("Your seed can be entered as a mnemonic (sequence of words), or as a hexadecimal string.")), 1, 3) + + if is_restore: + gap_e = AmountEdit(None, True) + gap_e.setText("5") + grid.addWidget(QLabel(_('Gap limit')), 2, 0) + grid.addWidget(gap_e, 2, 1) + grid.addWidget(HelpButton(_('Keep the default value unless you modified this parameter in your wallet.')), 2, 3) + + vbox.addLayout(grid) + vbox.addLayout(ok_cancel_buttons(d)) + d.setLayout(vbox) + + if not d.exec_(): return + + if is_restore: + try: + gap = int(unicode(gap_e.text())) + except: + QMessageBox.warning(None, _('Error'), 'error', 'OK') + return + else: + gap = None + + try: + seed = str(seed_e.text()) + seed.decode('hex') + except: + print_error("Warning: Not hex, trying decode") + try: + seed = mnemonic.mn_decode( seed.split(' ') ) + except: + QMessageBox.warning(None, _('Error'), _('I cannot decode this'), _('OK')) + return + + if not seed: + QMessageBox.warning(None, _('Error'), _('No seed'), _('OK')) + return + + return seed, gap + def network_dialog(self): return ElectrumWindow.network_dialog( self.wallet, parent=None ) @@ -2362,7 +2382,6 @@ class ElectrumGui: def show_seed(self): ElectrumWindow.show_seed(self.wallet.seed, self.wallet.imported_keys) - def password_dialog(self): if self.wallet.seed: ElectrumWindow.change_password_dialog(self.wallet) diff --git a/gui/gui_gtk.py b/gui/gui_gtk.py @@ -1292,6 +1292,10 @@ class ElectrumGui(): def seed_dialog(self): return run_recovery_dialog( self.wallet ) + def verify_seed(self): + self.wallet.save_seed() + return True + def network_dialog(self): return run_network_dialog( self.wallet, parent=None ) diff --git a/gui/gui_text.py b/gui/gui_text.py @@ -47,7 +47,9 @@ class ElectrumGui: def restore_or_create(self): pass - + def verify_seed(self): + pass + def get_string(self, y, x): curses.curs_set(1) curses.echo() diff --git a/lib/interface.py b/lib/interface.py @@ -382,7 +382,7 @@ class Interface(threading.Thread): def __init__(self, config=None, loop=False): - self.server = None + self.server = random.choice(DEFAULT_SERVERS[:]) self.proxy = None if config is None: diff --git a/lib/wallet.py b/lib/wallet.py @@ -151,7 +151,9 @@ class Wallet: if self.seed: raise BaseException("a seed exists") if not seed: seed = random_seed(128) - self.seed = seed + self.seed = seed + + def save_seed(self): self.config.set_key('seed', self.seed, True) self.config.set_key('seed_version', self.seed_version, True) mpk = self.SequenceClass.mpk_from_seed(self.seed)