Skip to content

Commit

Permalink
Merge #1702: Handle None enter_seed_callback() response
Browse files Browse the repository at this point in the history
8eb55be Handle None enter_seed_callback() response (Kristaps Kaupe)

Pull request description:

  Fixes #1698. Also added type hints.

Top commit has no ACKs.

Tree-SHA512: c5d6e9f0dd63528013c64556086b119a0b25e24f10d683f21c43bf88f794d02d8da28191f05e3bcb204ed2d43cba314962536c62e24c46334644234b458220d3
  • Loading branch information
kristapsk committed May 16, 2024
2 parents 2bbdf3c + 8eb55be commit a5711bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
14 changes: 7 additions & 7 deletions scripts/joinmarket-qt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
from typing import Optional

'''
Joinmarket GUI using PyQt for doing coinjoins.
Expand All @@ -23,6 +22,7 @@
import sys, datetime, os, logging
import platform, json, threading, time
from optparse import OptionParser
from typing import Optional, Tuple

from PySide2 import QtCore

Expand Down Expand Up @@ -1921,7 +1921,7 @@ def show_privkeys():
"Private keys exported to: " + os.path.join(jm_single().datadir,
privkeys_fn) + '.json', title="Success")

def seedEntry(self):
def seedEntry(self) -> Tuple[Optional[str], Optional[str]]:
d = QDialog(self)
d.setModal(1)
d.setWindowTitle('Recover from mnemonic phrase')
Expand Down Expand Up @@ -2230,7 +2230,7 @@ def showSeedDialog(self):
mbtype='info',
title="Error")

def getPassword(self):
def getPassword(self) -> str:
pd = PasswordDialog()
while True:
for child in pd.findChildren(QLineEdit):
Expand All @@ -2255,7 +2255,7 @@ def getPassword(self):
self.textpassword = str(pd.new_pw.text())
return self.textpassword.encode('utf-8')

def getWalletFileName(self):
def getWalletFileName(self) -> str:
walletname, ok = QInputDialog.getText(self, 'Choose wallet name',
'Enter wallet file name:',
QLineEdit.Normal, "wallet.jmdat")
Expand All @@ -2267,7 +2267,7 @@ def getWalletFileName(self):
self.walletname = str(walletname)
return self.walletname

def displayWords(self, words, mnemonic_extension):
def displayWords(self, words: str, mnemonic_extension: str) -> None:
mb = QMessageBox(self)
seed_recovery_warning = [
"WRITE DOWN THIS WALLET RECOVERY SEED.",
Expand All @@ -2282,13 +2282,13 @@ def displayWords(self, words, mnemonic_extension):
mb.setStandardButtons(QMessageBox.Ok)
ret = mb.exec_()

def promptUseMnemonicExtension(self):
def promptUseMnemonicExtension(self) -> bool:
msg = "Would you like to use a two-factor mnemonic recovery phrase?\nIf you don\'t know what this is press No."
reply = QMessageBox.question(self, 'Use mnemonic extension?',
msg, QMessageBox.Yes, QMessageBox.No)
return reply == QMessageBox.Yes

def promptInputMnemonicExtension(self):
def promptInputMnemonicExtension(self) -> Optional[str]:
mnemonic_extension, ok = QInputDialog.getText(self,
'Input Mnemonic Extension',
'Enter mnemonic Extension:',
Expand Down
35 changes: 21 additions & 14 deletions src/jmclient/wallet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from numbers import Integral
from collections import Counter, defaultdict
from itertools import islice, chain
from typing import Optional, Tuple
from typing import Callable, Optional, Tuple
from jmclient import (get_network, WALLET_IMPLEMENTATIONS, Storage, podle,
jm_single, WalletError, BaseWallet, VolatileStorage,
StoragePasswordError, is_segwit_mode, SegwitLegacyWallet, LegacyWallet,
Expand Down Expand Up @@ -673,25 +673,25 @@ def get_addr_status(addr_path, utxos, utxos_enabled, is_new, is_internal):
else:
return walletview

def cli_get_wallet_passphrase_check():
def cli_get_wallet_passphrase_check() -> Optional[str]:
password = get_password("Enter new passphrase to encrypt wallet: ")
password2 = get_password("Reenter new passphrase to encrypt wallet: ")
if password != password2:
jmprint('ERROR. Passwords did not match', "error")
return False
return None
return password

def cli_get_wallet_file_name(defaultname="wallet.jmdat"):
return input('Input wallet file name (default: ' + defaultname + '): ')
def cli_get_wallet_file_name(defaultname: str = "wallet.jmdat") -> str:
return input(f'Input wallet file name (default: {defaultname}): ')

def cli_display_user_words(words, mnemonic_extension):
def cli_display_user_words(words: str, mnemonic_extension: str) -> None:
text = 'Write down this wallet recovery mnemonic\n\n' + words +'\n'
if mnemonic_extension:
text += '\nAnd this mnemonic extension: ' + mnemonic_extension.decode(
'utf-8') + '\n'
jmprint(text, "important")

def cli_user_mnemonic_entry():
def cli_user_mnemonic_entry() -> Tuple[Optional[str], Optional[str]]:
mnemonic_phrase = input("Input mnemonic recovery phrase: ")
mnemonic_extension = input("Input mnemonic extension, leave blank if there isnt one: ")
if len(mnemonic_extension.strip()) == 0:
Expand All @@ -707,7 +707,7 @@ def cli_do_use_mnemonic_extension() -> bool:
jmprint("Not using mnemonic extension", "info")
return False #no mnemonic extension

def cli_get_mnemonic_extension():
def cli_get_mnemonic_extension() -> str:
jmprint("Note: This will be stored in a reversible way. Do not reuse!",
"info")
return input("Enter mnemonic extension: ")
Expand All @@ -721,10 +721,17 @@ def cli_do_support_fidelity_bonds() -> bool:
jmprint("Not supporting fidelity bonds", "info")
return False

def wallet_generate_recover_bip39(method, walletspath, default_wallet_name,
display_seed_callback, enter_seed_callback, enter_wallet_password_callback,
enter_wallet_file_name_callback, enter_if_use_seed_extension,
enter_seed_extension_callback, enter_do_support_fidelity_bonds, mixdepth=DEFAULT_MIXDEPTH):
def wallet_generate_recover_bip39(method: str,
walletspath: str,
default_wallet_name: str,
display_seed_callback: Callable[[str, str], None],
enter_seed_callback: Optional[Callable[[], Tuple[Optional[str], Optional[str]]]],
enter_wallet_password_callback: Callable[[], str],
enter_wallet_file_name_callback: Callable[[], str],
enter_if_use_seed_extension: Optional[Callable[[], bool]],
enter_seed_extension_callback: Optional[Callable[[], Optional[str]]],
enter_do_support_fidelity_bonds: Callable[[], bool],
mixdepth: int = DEFAULT_MIXDEPTH) -> bool:
entropy = None
mnemonic_extension = None
if method == "generate":
Expand All @@ -734,10 +741,10 @@ def wallet_generate_recover_bip39(method, walletspath, default_wallet_name,
return False
elif method == 'recover':
words, mnemonic_extension = enter_seed_callback()
words = words.strip()
mnemonic_extension = mnemonic_extension and mnemonic_extension.strip()
words = words and words.strip()
if not words:
return False
mnemonic_extension = mnemonic_extension and mnemonic_extension.strip()
try:
entropy = SegwitLegacyWallet.entropy_from_mnemonic(words)
except WalletError:
Expand Down

0 comments on commit a5711bc

Please sign in to comment.