Skip to content

Commit e16892b

Browse files
sangbidarustyrussell
authored andcommitted
wallet: change dev_listaddrs to also list bip86 addresses
listaddrs is dev only and used in tests so it's okay if we change the API here, the usage is by positional arguments in tests so we're okay. Also changing est_option_upfront_shutdown_script to handle both old hsmsecret and the newer mnemonic one.
1 parent 095ff3d commit e16892b

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

wallet/walletrpc.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,28 +292,40 @@ static struct command_result *json_listaddrs(struct command *cmd,
292292
{
293293
struct json_stream *response;
294294
struct pubkey pubkey;
295-
u64 *bip32_max_index;
295+
u64 *max_index;
296+
bool use_bip86 = (cmd->ld->bip86_base != NULL);
296297

297298
if (!param(cmd, buffer, params,
298-
p_opt("bip32_max_index", param_u64, &bip32_max_index),
299+
p_opt("max_index", param_u64, &max_index),
299300
NULL))
300301
return command_param_failed();
301302

302-
if (!bip32_max_index) {
303-
bip32_max_index = tal(cmd, u64);
304-
*bip32_max_index = db_get_intvar(cmd->ld->wallet->db,
305-
"bip32_max_index", 0);
303+
if (!max_index) {
304+
max_index = tal(cmd, u64);
305+
/* Use bip86_max_index for BIP86 wallets, bip32_max_index for legacy */
306+
if (use_bip86) {
307+
*max_index = db_get_intvar(cmd->ld->wallet->db,
308+
"bip86_max_index", 0);
309+
} else {
310+
*max_index = db_get_intvar(cmd->ld->wallet->db,
311+
"bip32_max_index", 0);
312+
}
306313
}
307314
response = json_stream_success(cmd);
308315
json_array_start(response, "addresses");
309316

310-
for (s64 keyidx = 1; keyidx <= *bip32_max_index; keyidx++) {
317+
for (s64 keyidx = 1; keyidx <= *max_index; keyidx++) {
311318

312319
if (keyidx == BIP32_INITIAL_HARDENED_CHILD){
313320
break;
314321
}
315322

316-
bip32_pubkey(cmd->ld, &pubkey, keyidx);
323+
/* Use BIP86 derivation for BIP86 wallets, BIP32 for legacy */
324+
if (use_bip86) {
325+
bip86_pubkey(cmd->ld, &pubkey, keyidx);
326+
} else {
327+
bip32_pubkey(cmd->ld, &pubkey, keyidx);
328+
}
317329

318330
// bech32 : p2wpkh
319331
u8 *redeemscript_p2wpkh;

0 commit comments

Comments
 (0)