| 273 | AUTODATA(json_command, &listaddresses_command); |
| 274 | |
| 275 | static struct command_result *json_listaddrs(struct command *cmd, |
| 276 | const char *buffer, |
| 277 | const jsmntok_t *obj UNNEEDED, |
| 278 | const jsmntok_t *params) |
| 279 | { |
| 280 | struct json_stream *response; |
| 281 | struct pubkey pubkey; |
| 282 | u64 *max_index; |
| 283 | bool use_bip86 = (cmd->ld->bip86_base != NULL); |
| 284 | |
| 285 | if (!param(cmd, buffer, params, |
| 286 | p_opt("max_index", param_u64, &max_index), |
| 287 | NULL)) |
| 288 | return command_param_failed(); |
| 289 | |
| 290 | if (!max_index) { |
| 291 | max_index = tal(cmd, u64); |
| 292 | /* Use bip86_max_index for BIP86 wallets, bip32_max_index for legacy */ |
| 293 | if (use_bip86) { |
| 294 | *max_index = db_get_intvar(cmd->ld->wallet->db, |
| 295 | "bip86_max_index", 0); |
| 296 | } else { |
| 297 | *max_index = db_get_intvar(cmd->ld->wallet->db, |
| 298 | "bip32_max_index", 0); |
| 299 | } |
| 300 | } |
| 301 | response = json_stream_success(cmd); |
| 302 | json_array_start(response, "addresses"); |
| 303 | |
| 304 | for (s64 keyidx = 1; keyidx <= *max_index; keyidx++) { |
| 305 | |
| 306 | if (keyidx == BIP32_INITIAL_HARDENED_CHILD){ |
| 307 | break; |
| 308 | } |
| 309 | |
| 310 | /* Use BIP86 derivation for BIP86 wallets, BIP32 for legacy */ |
| 311 | if (use_bip86) { |
| 312 | bip86_pubkey(cmd->ld, &pubkey, keyidx); |
| 313 | } else { |
| 314 | bip32_pubkey(cmd->ld, &pubkey, keyidx); |
| 315 | } |
| 316 | |
| 317 | // bech32 : p2wpkh |
| 318 | u8 *redeemscript_p2wpkh; |
| 319 | char *out_p2wpkh = encode_pubkey_to_addr(cmd, |
| 320 | &pubkey, |
| 321 | ADDR_BECH32, |
| 322 | &redeemscript_p2wpkh); |
| 323 | if (!out_p2wpkh) { |
| 324 | abort(); |
| 325 | } |
| 326 | |
| 327 | // p2tr |
| 328 | char *out_p2tr = encode_pubkey_to_addr(cmd, |
| 329 | &pubkey, |
| 330 | ADDR_P2TR, |
| 331 | /* out_redeemscript */ NULL); |
| 332 | if (!out_p2tr) { |
nothing calls this directly
no test coverage detected