| 572 | } |
| 573 | |
| 574 | static 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) { |
nothing calls this directly
no test coverage detected