commit 1c75d939d978caea9ae6512c3820c47f8e73da52
parent 0ec9f794023af9ded64a5f9477868dfbf3e92acd
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 9 Aug 2019 22:02:01 +0200
commands: change API of "make_seed" and "create" commands
instead of "segwit" boolean, take a "seed_type" optional arg
default seed_type to "segwit"
previously these commands created legacy seeds by defalt
Diffstat:
6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/electrum/commands.py b/electrum/commands.py
@@ -132,7 +132,7 @@ class Commands:
return ' '.join(sorted(known_commands.keys()))
@command('')
- def create(self, passphrase=None, password=None, encrypt_file=True, segwit=False):
+ def create(self, passphrase=None, password=None, encrypt_file=True, seed_type=None):
"""Create a new wallet.
If you want to be prompted for an argument, type '?' or ':' (concealed)
"""
@@ -140,7 +140,7 @@ class Commands:
passphrase=passphrase,
password=password,
encrypt_file=encrypt_file,
- segwit=segwit)
+ seed_type=seed_type)
return {
'seed': d['seed'],
'path': d['wallet'].storage.path,
@@ -203,11 +203,10 @@ class Commands:
return True
@command('')
- def make_seed(self, nbits=132, language=None, segwit=False):
+ def make_seed(self, nbits=132, language=None, seed_type=None):
"""Create a seed"""
from .mnemonic import Mnemonic
- t = 'segwit' if segwit else 'standard'
- s = Mnemonic(language).make_seed(t, nbits)
+ s = Mnemonic(language).make_seed(seed_type, num_bits=nbits)
return s
@command('n')
@@ -810,7 +809,7 @@ command_options = {
'from_addr': ("-F", "Source address (must be a wallet address; use sweep to spend from non-wallet address)."),
'change_addr': ("-c", "Change address. Default is a spare address, or the source address if it's not in the wallet"),
'nbits': (None, "Number of bits of entropy"),
- 'segwit': (None, "Create segwit seed"),
+ 'seed_type': (None, "The type of seed to create, e.g. 'standard' or 'segwit'"),
'language': ("-L", "Default language for wordlist"),
'passphrase': (None, "Seed extension"),
'privkey': (None, "Private key. Set to '?' to get a prompt."),
diff --git a/electrum/mnemonic.py b/electrum/mnemonic.py
@@ -160,7 +160,9 @@ class Mnemonic(Logger):
i = i*n + k
return i
- def make_seed(self, seed_type='standard', num_bits=132):
+ def make_seed(self, seed_type=None, *, num_bits=132):
+ if seed_type is None:
+ seed_type = 'segwit'
prefix = version.seed_prefix(seed_type)
# increase num_bits in order to obtain a uniform distribution for the last word
bpw = math.log(len(self.wordlist), 2)
diff --git a/electrum/tests/test_mnemonic.py b/electrum/tests/test_mnemonic.py
@@ -120,7 +120,7 @@ class Test_NewMnemonic(SequentialTestCase):
iters = 10
m = mnemonic.Mnemonic(lang='en')
for _ in range(iters):
- seed = m.make_seed()
+ seed = m.make_seed("standard")
i = m.mnemonic_decode(seed)
self.assertEqual(m.mnemonic_encode(i), seed)
diff --git a/electrum/tests/test_wallet.py b/electrum/tests/test_wallet.py
@@ -156,7 +156,6 @@ class TestCreateRestoreWallet(WalletTestCase):
passphrase=passphrase,
password=password,
encrypt_file=encrypt_file,
- segwit=True,
gap_limit=1)
wallet = d['wallet'] # type: Standard_Wallet
wallet.check_password(password)
diff --git a/electrum/version.py b/electrum/version.py
@@ -19,3 +19,4 @@ def seed_prefix(seed_type):
return SEED_PREFIX_2FA
elif seed_type == '2fa_segwit':
return SEED_PREFIX_2FA_SW
+ raise Exception(f"unknown seed_type: {seed_type}")
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -2005,13 +2005,12 @@ class Wallet(object):
raise WalletFileException("Unknown wallet type: " + str(wallet_type))
-def create_new_wallet(*, path, passphrase=None, password=None, encrypt_file=True, segwit=True, gap_limit=None):
+def create_new_wallet(*, path, passphrase=None, password=None, encrypt_file=True, seed_type=None, gap_limit=None):
"""Create a new wallet"""
storage = WalletStorage(path)
if storage.file_exists():
raise Exception("Remove the existing wallet first!")
- seed_type = 'segwit' if segwit else 'standard'
seed = Mnemonic('en').make_seed(seed_type)
k = keystore.from_seed(seed, passphrase)
storage.put('keystore', k.dump())