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

Function json_listfunds

wallet/walletrpc.c:304–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304static struct command_result *json_listfunds(struct command *cmd,
305 const char *buffer,
306 const jsmntok_t *obj UNNEEDED,
307 const jsmntok_t *params)
308{
309 struct json_stream *response;
310 struct peer *p;
311 struct utxo **utxos, **reserved_utxos, **spent_utxos;
312 bool *spent;
313
314 if (!param(cmd, buffer, params,
315 p_opt_def("spent", param_bool, &spent, false),
316 NULL))
317 return command_param_failed();
318
319 response = json_stream_success(cmd);
320
321 utxos = wallet_get_utxos(cmd, cmd->ld->wallet, OUTPUT_STATE_AVAILABLE);
322 reserved_utxos = wallet_get_utxos(cmd, cmd->ld->wallet, OUTPUT_STATE_RESERVED);
323
324 json_array_start(response, "outputs");
325 json_add_utxos(response, cmd->ld->wallet, utxos);
326 json_add_utxos(response, cmd->ld->wallet, reserved_utxos);
327
328 if (*spent) {
329 spent_utxos = wallet_get_utxos(cmd, cmd->ld->wallet, OUTPUT_STATE_SPENT);
330 json_add_utxos(response, cmd->ld->wallet, spent_utxos);
331 }
332
333 json_array_end(response);
334
335 /* Add funds that are allocated to channels */
336 json_array_start(response, "channels");
337 list_for_each(&cmd->ld->peers, p, list) {
338 struct channel *c;
339 list_for_each(&p->channels, c, list) {
340 /* We don't print out uncommitted channels */
341 if (channel_unsaved(c))
342 continue;
343 json_object_start(response, NULL);
344 json_add_node_id(response, "peer_id", &p->id);
345 json_add_bool(response, "connected",
346 channel_is_connected(c));
347 json_add_string(response, "state",
348 channel_state_name(c));
349 if (c->scid)
350 json_add_short_channel_id(response,
351 "short_channel_id",
352 c->scid);
353
354 json_add_amount_sat_compat(response,
355 amount_msat_to_sat_round_down(c->our_msat),
356 "channel_sat",
357 "our_amount_msat");
358 json_add_amount_sat_compat(response, c->funding_sats,
359 "channel_total_sat",
360 "amount_msat");
361 json_add_txid(response, "funding_txid",

Callers

nothing calls this directly

Calls 15

wallet_get_utxosFunction · 0.85
json_add_utxosFunction · 0.85
channel_unsavedFunction · 0.85
channel_is_connectedFunction · 0.85
paramFunction · 0.50
command_param_failedFunction · 0.50
json_stream_successFunction · 0.50
json_array_startFunction · 0.50
json_array_endFunction · 0.50
json_object_startFunction · 0.50
json_add_node_idFunction · 0.50

Tested by

no test coverage detected