| 195 | } |
| 196 | |
| 197 | static struct command_result *json_listaddresses(struct command *cmd, |
| 198 | const char *buffer, |
| 199 | const jsmntok_t *obj UNNEEDED, |
| 200 | const jsmntok_t *params) |
| 201 | { |
| 202 | struct json_stream *response; |
| 203 | struct pubkey pubkey; |
| 204 | const u8 *scriptpubkey; |
| 205 | u64 *liststart; |
| 206 | u32 *listlimit; |
| 207 | char *addr = NULL; |
| 208 | |
| 209 | if (!param(cmd, buffer, params, |
| 210 | p_opt("address", param_bitcoin_address, &scriptpubkey), |
| 211 | p_opt_def("start", param_u64, &liststart, 1), |
| 212 | p_opt("limit", param_u32, &listlimit), |
| 213 | NULL)) |
| 214 | return command_param_failed(); |
| 215 | |
| 216 | addr = encode_scriptpubkey_to_addr(tmpctx, chainparams, scriptpubkey, tal_bytelen(scriptpubkey)); |
| 217 | |
| 218 | if (*liststart == 0) { |
| 219 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 220 | "Starting keyidx is 1; Cannot {start} with 0"); |
| 221 | } |
| 222 | struct issued_address_type *listaddrtypes = wallet_list_addresses(tmpctx, cmd->ld->wallet, *liststart, listlimit); |
| 223 | response = json_stream_success(cmd); |
| 224 | json_array_start(response, "addresses"); |
| 225 | for (size_t i = 0; i < tal_count(listaddrtypes); i++) { |
| 226 | if (listaddrtypes[i].keyidx == BIP32_INITIAL_HARDENED_CHILD){ |
| 227 | break; |
| 228 | } |
| 229 | /* Use appropriate derivation based on wallet type */ |
| 230 | if (cmd->ld->bip86_base) { |
| 231 | /* Mnemonic wallet - use BIP86 derivation */ |
| 232 | bip86_pubkey(cmd->ld, &pubkey, listaddrtypes[i].keyidx); |
| 233 | } else { |
| 234 | /* Legacy wallet - use BIP32 derivation */ |
| 235 | bip32_pubkey(cmd->ld, &pubkey, listaddrtypes[i].keyidx); |
| 236 | } |
| 237 | char *out_p2wpkh = ""; |
| 238 | char *out_p2tr = ""; |
| 239 | if (listaddrtypes[i].addrtype == ADDR_BECH32 || listaddrtypes[i].addrtype == ADDR_ALL) { |
| 240 | u8 *redeemscript_p2wpkh; |
| 241 | out_p2wpkh = encode_pubkey_to_addr(cmd, |
| 242 | &pubkey, |
| 243 | ADDR_BECH32, |
| 244 | &redeemscript_p2wpkh); |
| 245 | if (!out_p2wpkh) { |
| 246 | abort(); |
| 247 | } |
| 248 | } |
| 249 | if (listaddrtypes[i].addrtype == ADDR_P2TR || listaddrtypes[i].addrtype == ADDR_ALL) { |
| 250 | out_p2tr = encode_pubkey_to_addr(cmd, |
| 251 | &pubkey, |
| 252 | ADDR_P2TR, |
| 253 | /* out_redeemscript */ NULL); |
| 254 | if (!out_p2tr) { |
nothing calls this directly
no test coverage detected