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

Function do_inspect

plugins/bkpr/bookkeeper.c:574–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

572}
573
574static struct command_result *do_inspect(struct command *cmd,
575 char *acct_name)
576{
577 struct json_stream *res;
578 struct account *acct;
579 struct fee_sum **fee_sums;
580 struct txo_set **txos;
581 struct bkpr *bkpr = bkpr_of(cmd->plugin);
582
583 if (!is_channel_account(acct_name))
584 return command_fail(cmd, PLUGIN_ERROR,
585 "`inspect` not supported for"
586 " non-channel accounts");
587
588 acct = find_account(bkpr, acct_name);
589 if (!acct)
590 return command_fail(cmd, PLUGIN_ERROR,
591 "Account %s not found",
592 acct_name);
593
594 find_txo_chain(cmd, bkpr, cmd, acct, &txos);
595 fee_sums = find_account_onchain_fees(cmd, bkpr, acct);
596
597 res = jsonrpc_stream_success(cmd);
598 json_array_start(res, "txs");
599 for (size_t i = 0; i < tal_count(txos); i++) {
600 struct txo_set *set = txos[i];
601 struct fee_sum *fee_sum;
602
603 json_object_start(res, NULL);
604 json_add_txid(res, "txid", set->txid);
605
606 /* annoyting, but we can only add the block height
607 * if we have a txo for it */
608 for (size_t j = 0; j < tal_count(set->pairs); j++) {
609 if (set->pairs[j]->txo
610 && set->pairs[j]->txo->blockheight > 0) {
611 json_add_num(res, "blockheight",
612 set->pairs[j]->txo->blockheight);
613 break;
614 }
615 }
616
617 fee_sum = find_sum_for_txid(fee_sums, set->txid);
618 if (fee_sum)
619 json_add_amount_msat(res, "fees_paid_msat",
620 fee_sum->fees_paid);
621 else
622 json_add_amount_msat(res, "fees_paid_msat",
623 AMOUNT_MSAT(0));
624
625 json_array_start(res, "outputs");
626 for (size_t j = 0; j < tal_count(set->pairs); j++) {
627 struct txo_pair *pr = set->pairs[j];
628
629 /* Is this an event that belongs to this account? */
630 if (pr->txo) {
631 if (pr->txo->origin_acct) {

Callers

nothing calls this directly

Calls 15

is_channel_accountFunction · 0.85
json_array_startFunction · 0.85
json_object_startFunction · 0.85
json_add_txidFunction · 0.85
json_add_numFunction · 0.85
find_sum_for_txidFunction · 0.85
json_add_amount_msatFunction · 0.85
is_wallet_accountFunction · 0.85
json_add_sha256Function · 0.85
json_object_endFunction · 0.85
json_array_endFunction · 0.85
bkpr_ofFunction · 0.70

Tested by

no test coverage detected