| 97 | } |
| 98 | |
| 99 | static void fillin_apy_acct_details(const struct bkpr *bkpr, |
| 100 | struct command *cmd, |
| 101 | const struct account *acct, |
| 102 | u32 current_blockheight, |
| 103 | struct channel_apy *apy) |
| 104 | { |
| 105 | struct chain_event *ev; |
| 106 | bool ok; |
| 107 | |
| 108 | apy->acct_name = tal_strdup(apy, acct->name); |
| 109 | |
| 110 | assert(acct->open_event_db_id); |
| 111 | ev = find_chain_event_by_id(tmpctx, bkpr, cmd, *acct->open_event_db_id); |
| 112 | assert(ev); |
| 113 | |
| 114 | apy->start_blockheight = ev->blockheight; |
| 115 | apy->our_start_bal = ev->credit; |
| 116 | apy->total_start_bal = ev->output_value; |
| 117 | |
| 118 | /* if this account is closed, add closing blockheight */ |
| 119 | if (acct->closed_event_db_id) { |
| 120 | ev = find_chain_event_by_id(tmpctx, bkpr, cmd, |
| 121 | *acct->closed_event_db_id); |
| 122 | assert(ev); |
| 123 | apy->end_blockheight = ev->blockheight; |
| 124 | } else |
| 125 | apy->end_blockheight = current_blockheight; |
| 126 | |
| 127 | /* If there is any push_out or lease_fees_out, we subtract |
| 128 | * from starting balance */ |
| 129 | ok = amount_msat_deduct(&apy->our_start_bal, apy->push_out); |
| 130 | assert(ok); |
| 131 | ok = amount_msat_deduct(&apy->our_start_bal, apy->lease_out); |
| 132 | assert(ok); |
| 133 | |
| 134 | /* we add values in to starting balance */ |
| 135 | ok = amount_msat_accumulate(&apy->our_start_bal, apy->push_in); |
| 136 | assert(ok); |
| 137 | ok = amount_msat_accumulate(&apy->our_start_bal, apy->lease_in); |
| 138 | assert(ok); |
| 139 | } |
| 140 | |
| 141 | struct channel_apy **compute_channel_apys(const tal_t *ctx, |
| 142 | const struct bkpr *bkpr, |
no test coverage detected