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

Function json_listfunds

wallet/walletrpc.c:428–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426}
427
428static struct command_result *json_listfunds(struct command *cmd,
429 const char *buffer,
430 const jsmntok_t *obj UNNEEDED,
431 const jsmntok_t *params)
432{
433 struct json_stream *response;
434 struct peer *p;
435 struct peer_node_id_map_iter it;
436 struct utxo **utxos;
437 bool *spent;
438
439 if (!param(cmd, buffer, params,
440 p_opt_def("spent", param_bool, &spent, false),
441 NULL))
442 return command_param_failed();
443
444 response = json_stream_success(cmd);
445
446 if (*spent)
447 utxos = wallet_get_all_utxos(cmd, cmd->ld->wallet);
448 else
449 utxos = wallet_get_unspent_utxos(cmd, cmd->ld->wallet);
450
451 json_array_start(response, "outputs");
452 json_add_utxos(response, cmd->ld->wallet, utxos);
453 json_array_end(response);
454
455 /* Add funds that are allocated to channels */
456 json_array_start(response, "channels");
457 for (p = peer_node_id_map_first(cmd->ld->peers, &it);
458 p;
459 p = peer_node_id_map_next(cmd->ld->peers, &it)) {
460 struct channel *c;
461 list_for_each(&p->channels, c, list) {
462 /* We don't print out uncommitted channels, which makes us meet this: */
463 /* BOLT #2:
464 * The receiving node MUST NOT:
465 * - consider funds received, using `push_msat`, to be received
466 * until the funding transaction has reached sufficient depth.
467 */
468 if (channel_state_uncommitted(c->state))
469 continue;
470 json_object_start(response, NULL);
471 json_add_node_id(response, "peer_id", &p->id);
472 json_add_bool(response, "connected",
473 channel_is_connected(c));
474 json_add_string(response, "state",
475 channel_state_name(c));
476 json_add_channel_id(response, "channel_id", &c->cid);
477 if (c->scid)
478 json_add_short_channel_id(response,
479 "short_channel_id",
480 *c->scid);
481
482 json_add_amount_msat(response,
483 "our_amount_msat",
484 c->our_msat);
485 json_add_amount_sat_msat(response,

Callers

nothing calls this directly

Calls 15

wallet_get_all_utxosFunction · 0.85
wallet_get_unspent_utxosFunction · 0.85
json_array_startFunction · 0.85
json_add_utxosFunction · 0.85
json_array_endFunction · 0.85
json_object_startFunction · 0.85
json_add_node_idFunction · 0.85
json_add_boolFunction · 0.85
channel_is_connectedFunction · 0.85
json_add_channel_idFunction · 0.85

Tested by

no test coverage detected