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

Function do_inspect

plugins/bkpr/bookkeeper.c:598–715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

596}
597
598static struct command_result *do_inspect(struct command *cmd,
599 char *acct_name)
600{
601 struct json_stream *res;
602 struct account *acct;
603 struct fee_sum **fee_sums;
604 struct txo_set **txos;
605 struct bkpr *bkpr = bkpr_of(cmd->plugin);
606
607 if (!is_channel_account(acct_name))
608 return command_fail(cmd, PLUGIN_ERROR,
609 "`inspect` not supported for"
610 " non-channel accounts");
611
612 acct = find_account(bkpr, acct_name);
613 if (!acct)
614 return command_fail(cmd, PLUGIN_ERROR,
615 "Account %s not found",
616 acct_name);
617
618 find_txo_chain(cmd, bkpr, cmd, acct, &txos);
619 fee_sums = find_account_onchain_fees(cmd, bkpr, acct);
620
621 res = jsonrpc_stream_success(cmd);
622 json_array_start(res, "txs");
623 for (size_t i = 0; i < tal_count(txos); i++) {
624 struct txo_set *set = txos[i];
625 struct fee_sum *fee_sum;
626
627 json_object_start(res, NULL);
628 json_add_txid(res, "txid", set->txid);
629
630 /* annoyting, but we can only add the block height
631 * if we have a txo for it */
632 for (size_t j = 0; j < tal_count(set->pairs); j++) {
633 if (set->pairs[j]->txo
634 && set->pairs[j]->txo->blockheight > 0) {
635 json_add_num(res, "blockheight",
636 set->pairs[j]->txo->blockheight);
637 break;
638 }
639 }
640
641 fee_sum = find_sum_for_txid(fee_sums, set->txid);
642 if (fee_sum)
643 json_add_amount_msat(res, "fees_paid_msat",
644 fee_sum->fees_paid);
645 else
646 json_add_amount_msat(res, "fees_paid_msat",
647 AMOUNT_MSAT(0));
648
649 json_array_start(res, "outputs");
650 for (size_t j = 0; j < tal_count(set->pairs); j++) {
651 struct txo_pair *pr = set->pairs[j];
652
653 /* Is this an event that belongs to this account? */
654 if (pr->txo) {
655 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