| 596 | } |
| 597 | |
| 598 | static 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) { |
nothing calls this directly
no test coverage detected