Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdio: very basic demo implementation of new wallet wizard in stdio gui #8201

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions electrum/gui/stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import getpass
import datetime
import logging
import os
from typing import Optional

from electrum.gui import BaseElectrumGui
Expand All @@ -14,6 +15,9 @@
from electrum.transaction import PartialTxOutput
from electrum.network import TxBroadcastError, BestEffortRequestFailed

from electrum.wizard import NewWalletWizard
from electrum import mnemonic

_ = lambda x:x # i18n

# minimal fdisk like gui for console usage
Expand All @@ -24,6 +28,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):

def __init__(self, *, config, daemon, plugins):
BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins)
self.daemon = daemon
self.network = daemon.network
storage = WalletStorage(config.get_wallet_path(use_gui_last_wallet=True))
if not storage.file_exists():
Expand Down Expand Up @@ -84,6 +89,7 @@ def main_command(self):
elif c == "b" : self.print_banner()
elif c == "n" : self.network_dialog()
elif c == "e" : self.settings_dialog()
elif c == "w" : self.wallet_wizard()
elif c == "q" : self.done = 1
else: self.print_commands()

Expand Down Expand Up @@ -244,6 +250,67 @@ def password_dialog(self):
return getpass.getpass()


def wallet_wizard(self):
self._new_wallet = NewWalletWizard(self.daemon)
self._new_wallet.navmap_merge({
'wallet_name': { 'gui': 'wizard_wallet_name' },
'wallet_type': { 'gui': 'wizard_wallet_type' },
'keystore_type': { 'gui': 'wizard_keystore_type' },
'create_seed': { 'gui': 'wizard_create_seed',
'next': self._new_wallet.on_have_or_confirm_seed,
},
'wallet_password': { 'gui': 'wizard_password' },
})
self.wallet_folder = os.path.dirname(self.daemon.config.get_wallet_path())
print('Start wallet wizard')
current = self._new_wallet.start()
self._wdata = current.wizard_data
self.call_view(current.view)

def wizard_submit(self):
self._new_wallet.log_state(self._wdata)
if self._new_wallet.is_last_view(self._new_wallet._current.view, self._wdata):
self._new_wallet.create_storage(os.path.join(self.wallet_folder, self._wdata['wallet_name']), self._wdata)
return
view = self._new_wallet.resolve_next(self._new_wallet._current.view, self._wdata)
self._wdata = view.wizard_data
print(f'next view: {view.view}')
self.call_view(view.view)

def wizard_wallet_name(self):
self._wdata['wallet_name'] = input('Wallet Name: ')
self.wizard_submit()

def wizard_wallet_type(self):
print('enter one of standard|2fa|multisig|imported')
self._wdata['wallet_type'] = input('Wallet Type: ')
self._wdata['seed_type'] = 'segwit'
self._wdata['seed_extend'] = False
self._wdata['seed_extra_words'] = ''
self.wizard_submit()

def wizard_keystore_type(self):
print('[1] create seed')
print('[2] have seed')
self._wdata['keystore_type'] = {'1': 'createseed', '2': 'haveseed' }[input('Keystore Type: ')]
self.wizard_submit()

def wizard_create_seed(self):
m = mnemonic.Mnemonic('en').make_seed(seed_type='segwit')
print(f'Seed: {m}')
self._wdata['seed'] = m
self._wdata['seed_variant'] = 'electrum'
self.wizard_submit()

def wizard_password(self):
self._wdata['password'] = input('Enter password: ')
self._wdata['encrypt'] = self._wdata['password'] != ''
self.wizard_submit()

def call_view(self, view):
getattr(self, self._new_wallet.navmap[view]['gui'])()


# XXX unused

def run_receive_tab(self, c):
Expand Down