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

Function json_list_balances

plugins/bkpr/bookkeeper.c:453–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

451}
452
453static struct command_result *json_list_balances(struct command *cmd,
454 const char *buf,
455 const jsmntok_t *params)
456{
457 struct json_stream *res;
458 struct account **accts;
459 char *err;
460
461 if (!param(cmd, buf, params, NULL))
462 return command_param_failed();
463
464 res = jsonrpc_stream_success(cmd);
465 /* List of accts */
466 db_begin_transaction(db);
467 accts = list_accounts(cmd, db);
468
469 json_array_start(res, "accounts");
470 for (size_t i = 0; i < tal_count(accts); i++) {
471 struct acct_balance **balances;
472
473 err = account_get_balance(cmd, db,
474 accts[i]->name,
475 true,
476 false, /* don't skip ignored */
477 &balances,
478 NULL);
479
480 if (err)
481 plugin_err(cmd->plugin,
482 "Get account balance returned err"
483 " for account %s: %s",
484 accts[i]->name, err);
485
486 /* Skip the external acct balance, it's effectively
487 * meaningless */
488 if (streq(accts[i]->name, EXTERNAL_ACCT))
489 continue;
490
491 /* Add it to the result data */
492 json_object_start(res, NULL);
493
494 json_add_string(res, "account", accts[i]->name);
495 if (accts[i]->peer_id) {
496 json_add_node_id(res, "peer_id", accts[i]->peer_id);
497 json_add_bool(res, "we_opened", accts[i]->we_opened);
498 json_add_bool(res, "account_closed",
499 !(!accts[i]->closed_event_db_id));
500 json_add_bool(res, "account_resolved",
501 accts[i]->onchain_resolved_block > 0);
502 if (accts[i]->onchain_resolved_block > 0)
503 json_add_u32(res, "resolved_at_block",
504 accts[i]->onchain_resolved_block);
505 }
506
507 json_array_start(res, "balances");
508 for (size_t j = 0; j < tal_count(balances); j++) {
509 json_object_start(res, NULL);
510 json_add_amount_msat_only(res, "balance_msat",

Callers

nothing calls this directly

Calls 15

list_accountsFunction · 0.85
account_get_balanceFunction · 0.85
paramFunction · 0.50
command_param_failedFunction · 0.50
jsonrpc_stream_successFunction · 0.50
json_array_startFunction · 0.50
plugin_errFunction · 0.50
json_object_startFunction · 0.50
json_add_stringFunction · 0.50
json_add_node_idFunction · 0.50
json_add_boolFunction · 0.50
json_add_u32Function · 0.50

Tested by

no test coverage detected