Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit 156b1ce

Browse files
committed
Make keypool the default, switch option to --nokeypool
1 parent bf55a7d commit 156b1ce

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

docs/bitcoin-core-usage.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ We will be fetching keys at the BIP 84 default. If `--path` and `--internal` are
4747
specified, both receiving and change address descriptors are generated.
4848

4949
```
50-
$ ./hwi.py -f 8038ecd9 getkeypool --wpkh --keypool 0 1000
50+
$ ./hwi.py -f 8038ecd9 getkeypool --wpkh 0 1000
5151
[{"desc": "wpkh([8038ecd9/84h/0h/0h]xpub6DR4rqx16YnCcfwFqgwvJdKiWrjDRzqxYTY44aoyHwZDSeSB5n2tqt42aYr9qPKhSKUdftPdTjhHrKKD6WGKVbuyhMvGH76VyKKZubg8o4P/0/*)#36sal9a4", "internal": false, "range": [0, 1000], "timestamp": "now", "keypool": true, "watchonly": true}, {"desc": "wpkh([8038ecd9/84h/0h/0h]xpub6DR4rqx16YnCcfwFqgwvJdKiWrjDRzqxYTY44aoyHwZDSeSB5n2tqt42aYr9qPKhSKUdftPdTjhHrKKD6WGKVbuyhMvGH76VyKKZubg8o4P/1/*)#nl2rc26w", "internal": true, "range": [0, 1000], "timestamp": "now", "keypool": true, "watchonly": true}]
5252
```
5353

@@ -276,8 +276,8 @@ e51392c82e13bbfe714c73361aff14ac1a1637abf37587a562844ae5a4265adf
276276
When the keypools run out, they can be refilled by using the `getkeypool` commands as done in the beginning, but with different starting and ending indexes. For example, to refill my keypools, I would use the following `getkeypool` commands:
277277

278278
```
279-
$ ./hwi.py -f 8038ecd9 getkeypool --wpkh --keypool 1000 2000
280-
$ ./hwi.py -f 8038ecd9 getkeypool --wpkh --keypool --internal 1000 2000
279+
$ ./hwi.py -f 8038ecd9 getkeypool --wpkh 1000 2000
280+
$ ./hwi.py -f 8038ecd9 getkeypool --wpkh --internal 1000 2000
281281
```
282282
The output can be imported with `importmulti` as shown in the Setup steps.
283283

hwilib/cli.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ def process_commands(cli_args):
125125
signmsg_parser.set_defaults(func=signmessage_handler)
126126

127127
getkeypool_parser = subparsers.add_parser('getkeypool', help='Get JSON array of keys that can be imported to Bitcoin Core with importmulti')
128-
getkeypool_parser.add_argument('--keypool', action='store_true', help='Indicates that the keys are to be imported to the keypool')
128+
kparg_group = getkeypool_parser.add_mutually_exclusive_group()
129+
kparg_group.add_argument('--keypool', action='store_true', dest='keypool', help='Indicates that the keys are to be imported to the keypool', default=True)
130+
kparg_group.add_argument('--nokeypool', action='store_false', dest='keypool', help='Indicates that the keys are not to be imported to the keypool', default=False)
129131
getkeypool_parser.add_argument('--internal', action='store_true', help='Indicates that the keys are change keys')
130132
getkeypool_parser.add_argument('--sh_wpkh', action='store_true', help='Generate p2sh-nested segwit addresses (default path: m/49h/0h/0h/[0,1]/*)')
131133
getkeypool_parser.add_argument('--wpkh', action='store_true', help='Generate bech32 addresses (default path: m/84h/0h/0h/[0,1]/*)')

hwilib/commands.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def getxpub(client, path):
8383
def signmessage(client, message, path):
8484
return client.sign_message(message, path)
8585

86-
def getkeypool_inner(client, path, start, end, internal=False, keypool=False, account=0, sh_wpkh=False, wpkh=True):
86+
def getkeypool_inner(client, path, start, end, internal=False, keypool=True, account=0, sh_wpkh=False, wpkh=True):
8787
if sh_wpkh and wpkh:
8888
return {'error': 'Both `--wpkh` and `--sh_wpkh` can not be selected at the same time.', 'code': BAD_ARGUMENT}
8989

@@ -159,7 +159,7 @@ def getdescriptor(client, master_xpub, testnet=False, path=None, internal=False,
159159
return Descriptor(master_fpr, path_base.replace('m', ''), client.xpub_cache.get(path_base), path_suffix, client.is_testnet, sh_wpkh, wpkh)
160160

161161
# wrapper to allow both internal and external entries when path not given
162-
def getkeypool(client, path, start, end, internal=False, keypool=False, account=0, sh_wpkh=False, wpkh=True):
162+
def getkeypool(client, path, start, end, internal=False, keypool=True, account=0, sh_wpkh=False, wpkh=True):
163163
if path is None and not internal:
164164
internal_chain = getkeypool_inner(client, None, start, end, True, keypool, account, sh_wpkh, wpkh)
165165
external_chain = getkeypool_inner(client, None, start, end, False, keypool, account, sh_wpkh, wpkh)

test/test_device.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ def test_getkeypool_bad_args(self):
179179
self.assertEqual(result['code'], -7)
180180

181181
def test_getkeypool(self):
182-
non_keypool_desc = self.do_command(self.dev_args + ['getkeypool', '0', '20'])
182+
non_keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--nokeypool', '0', '20'])
183183
import_result = self.wpk_rpc.importmulti(non_keypool_desc)
184184
self.assertTrue(import_result[0]['success'])
185185

186-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '0', '20'])
186+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '0', '20'])
187187
import_result = self.wpk_rpc.importmulti(keypool_desc)
188188
self.assertFalse(import_result[0]['success'])
189189

@@ -195,7 +195,7 @@ def test_getkeypool(self):
195195
addr_info = self.wrpc.getaddressinfo(self.wrpc.getrawchangeaddress())
196196
self.assertEqual(addr_info['hdkeypath'], "m/44'/1'/0'/1/{}".format(i))
197197

198-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--sh_wpkh', '0', '20'])
198+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--sh_wpkh', '0', '20'])
199199
import_result = self.wrpc.importmulti(keypool_desc)
200200
self.assertTrue(import_result[0]['success'])
201201
for i in range(0, 21):
@@ -204,7 +204,7 @@ def test_getkeypool(self):
204204
addr_info = self.wrpc.getaddressinfo(self.wrpc.getrawchangeaddress())
205205
self.assertEqual(addr_info['hdkeypath'], "m/49'/1'/0'/1/{}".format(i))
206206

207-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--wpkh', '0', '20'])
207+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--wpkh', '0', '20'])
208208
import_result = self.wrpc.importmulti(keypool_desc)
209209
self.assertTrue(import_result[0]['success'])
210210
for i in range(0, 21):
@@ -213,15 +213,15 @@ def test_getkeypool(self):
213213
addr_info = self.wrpc.getaddressinfo(self.wrpc.getrawchangeaddress())
214214
self.assertEqual(addr_info['hdkeypath'], "m/84'/1'/0'/1/{}".format(i))
215215

216-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--sh_wpkh', '--account', '3', '0', '20'])
216+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--sh_wpkh', '--account', '3', '0', '20'])
217217
import_result = self.wrpc.importmulti(keypool_desc)
218218
self.assertTrue(import_result[0]['success'])
219219
for i in range(0, 21):
220220
addr_info = self.wrpc.getaddressinfo(self.wrpc.getnewaddress())
221221
self.assertEqual(addr_info['hdkeypath'], "m/49'/1'/3'/0/{}".format(i))
222222
addr_info = self.wrpc.getaddressinfo(self.wrpc.getrawchangeaddress())
223223
self.assertEqual(addr_info['hdkeypath'], "m/49'/1'/3'/1/{}".format(i))
224-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--wpkh', '--account', '3', '0', '20'])
224+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--wpkh', '--account', '3', '0', '20'])
225225
import_result = self.wrpc.importmulti(keypool_desc)
226226
self.assertTrue(import_result[0]['success'])
227227
for i in range(0, 21):
@@ -230,17 +230,17 @@ def test_getkeypool(self):
230230
addr_info = self.wrpc.getaddressinfo(self.wrpc.getrawchangeaddress())
231231
self.assertEqual(addr_info['hdkeypath'], "m/84'/1'/3'/1/{}".format(i))
232232

233-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--path', 'm/0h/0h/4h/*', '0', '20'])
233+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--path', 'm/0h/0h/4h/*', '0', '20'])
234234
import_result = self.wrpc.importmulti(keypool_desc)
235235
self.assertTrue(import_result[0]['success'])
236236
for i in range(0, 21):
237237
addr_info = self.wrpc.getaddressinfo(self.wrpc.getnewaddress())
238238
self.assertEqual(addr_info['hdkeypath'], "m/0'/0'/4'/{}".format(i))
239239

240-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--path', '/0h/0h/4h/*', '0', '20'])
240+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--path', '/0h/0h/4h/*', '0', '20'])
241241
self.assertEqual(keypool_desc['error'], 'Path must start with m/')
242242
self.assertEqual(keypool_desc['code'], -7)
243-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--path', 'm/0h/0h/4h/', '0', '20'])
243+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--path', 'm/0h/0h/4h/', '0', '20'])
244244
self.assertEqual(keypool_desc['error'], 'Path must end with /*')
245245
self.assertEqual(keypool_desc['code'], -7)
246246

@@ -337,10 +337,10 @@ def _generate_and_finalize(self, unknown_inputs, psbt):
337337

338338
def _test_signtx(self, input_type, multisig):
339339
# Import some keys to the watch only wallet and send coins to them
340-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--sh_wpkh', '30', '40'])
340+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--sh_wpkh', '30', '40'])
341341
import_result = self.wrpc.importmulti(keypool_desc)
342342
self.assertTrue(import_result[0]['success'])
343-
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--keypool', '--sh_wpkh', '--internal', '30', '40'])
343+
keypool_desc = self.do_command(self.dev_args + ['getkeypool', '--sh_wpkh', '--internal', '30', '40'])
344344
import_result = self.wrpc.importmulti(keypool_desc)
345345
self.assertTrue(import_result[0]['success'])
346346
sh_wpkh_addr = self.wrpc.getnewaddress('', 'p2sh-segwit')

0 commit comments

Comments
 (0)