| 770 | }; |
| 771 | |
| 772 | static struct command_result *do_account_events(struct command *cmd, |
| 773 | struct account_events_info *info) |
| 774 | { |
| 775 | struct json_stream *res; |
| 776 | struct account *acct; |
| 777 | struct bitcoin_txid *tx_id; |
| 778 | struct channel_event **channel_events; |
| 779 | struct chain_event **chain_events; |
| 780 | struct onchain_fee **onchain_fees; |
| 781 | struct bkpr *bkpr = bkpr_of(cmd->plugin); |
| 782 | |
| 783 | if (info->acct_name && info->payment_id != NULL) { |
| 784 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 785 | "Can only specify one of " |
| 786 | "{account} or {payment_id}"); |
| 787 | } |
| 788 | |
| 789 | if (info->acct_name) { |
| 790 | acct = find_account(bkpr, info->acct_name); |
| 791 | if (!acct) |
| 792 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 793 | "Account '%s' not found", |
| 794 | info->acct_name); |
| 795 | } else |
| 796 | acct = NULL; |
| 797 | |
| 798 | if (acct) { |
| 799 | channel_events = account_get_channel_events(cmd, bkpr, cmd, acct); |
| 800 | chain_events = account_get_chain_events(cmd, bkpr, cmd, acct); |
| 801 | onchain_fees = account_get_chain_fees(tmpctx, bkpr, acct->name); |
| 802 | } else if (info->payment_id != NULL) { |
| 803 | channel_events = get_channel_events_by_id(cmd, bkpr, cmd, info->payment_id); |
| 804 | |
| 805 | tx_id = tal(cmd, struct bitcoin_txid); |
| 806 | tx_id->shad.sha = *info->payment_id; |
| 807 | /* Transaction ids are stored as big-endian in the database */ |
| 808 | reverse_bytes(tx_id->shad.sha.u.u8, sizeof(tx_id->shad.sha.u.u8)); |
| 809 | |
| 810 | chain_events = find_chain_events_bytxid(cmd, bkpr, cmd, tx_id); |
| 811 | onchain_fees = get_chain_fees_by_txid(cmd, bkpr, tx_id); |
| 812 | } else { |
| 813 | channel_events = list_channel_events(cmd, bkpr, cmd); |
| 814 | chain_events = list_chain_events(cmd, bkpr, cmd); |
| 815 | onchain_fees = list_chain_fees(cmd, bkpr); |
| 816 | } |
| 817 | |
| 818 | res = jsonrpc_stream_success(cmd); |
| 819 | json_array_start(res, "events"); |
| 820 | json_add_events(res, bkpr, channel_events, chain_events, onchain_fees); |
| 821 | json_array_end(res); |
| 822 | return command_finished(cmd, res); |
| 823 | } |
| 824 | |
| 825 | /* Find all the events for this account, ordered by timestamp */ |
| 826 | static struct command_result *json_list_account_events(struct command *cmd, |
nothing calls this directly
no test coverage detected