MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_listaddrs

Function json_listaddrs

wallet/walletrpc.c:162–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160AUTODATA(json_command, &newaddr_command);
161
162static struct command_result *json_listaddrs(struct command *cmd,
163 const char *buffer,
164 const jsmntok_t *obj UNNEEDED,
165 const jsmntok_t *params)
166{
167 struct json_stream *response;
168 struct pubkey pubkey;
169 u64 *bip32_max_index;
170
171 if (!param(cmd, buffer, params,
172 p_opt("bip32_max_index", param_u64, &bip32_max_index),
173 NULL))
174 return command_param_failed();
175
176 if (!bip32_max_index) {
177 bip32_max_index = tal(cmd, u64);
178 *bip32_max_index = db_get_intvar(cmd->ld->wallet->db,
179 "bip32_max_index", 0);
180 }
181 response = json_stream_success(cmd);
182 json_array_start(response, "addresses");
183
184 for (s64 keyidx = 0; keyidx <= *bip32_max_index; keyidx++) {
185
186 if (keyidx == BIP32_INITIAL_HARDENED_CHILD){
187 break;
188 }
189
190 if (!bip32_pubkey(cmd->ld->wallet->bip32_base, &pubkey, keyidx))
191 abort();
192
193 // p2sh
194 u8 *redeemscript_p2sh;
195 char *out_p2sh = encode_pubkey_to_addr(cmd,
196 &pubkey,
197 true,
198 &redeemscript_p2sh);
199
200 // bech32 : p2wpkh
201 u8 *redeemscript_p2wpkh;
202 char *out_p2wpkh = encode_pubkey_to_addr(cmd,
203 &pubkey,
204 false,
205 &redeemscript_p2wpkh);
206 if (!out_p2wpkh) {
207 abort();
208 }
209
210 // outputs
211 json_object_start(response, NULL);
212 json_add_u64(response, "keyidx", keyidx);
213 json_add_pubkey(response, "pubkey", &pubkey);
214 json_add_string(response, "p2sh", out_p2sh);
215 json_add_hex_talarr(response, "p2sh_redeemscript",
216 redeemscript_p2sh);
217 json_add_string(response, "bech32", out_p2wpkh);
218 json_add_hex_talarr(response, "bech32_redeemscript",
219 redeemscript_p2wpkh);

Callers

nothing calls this directly

Calls 15

bip32_pubkeyFunction · 0.85
abortFunction · 0.85
encode_pubkey_to_addrFunction · 0.85
json_add_pubkeyFunction · 0.85
paramFunction · 0.50
command_param_failedFunction · 0.50
db_get_intvarFunction · 0.50
json_stream_successFunction · 0.50
json_array_startFunction · 0.50
json_object_startFunction · 0.50
json_add_u64Function · 0.50
json_add_stringFunction · 0.50

Tested by

no test coverage detected