| 139 | } |
| 140 | |
| 141 | struct channel_apy **compute_channel_apys(const tal_t *ctx, |
| 142 | const struct bkpr *bkpr, |
| 143 | struct command *cmd, |
| 144 | u64 start_time, |
| 145 | u64 end_time, |
| 146 | u32 current_blockheight) |
| 147 | { |
| 148 | struct channel_event **evs; |
| 149 | struct channel_apy *apy, **apys; |
| 150 | struct account *acct, **accts; |
| 151 | |
| 152 | evs = list_channel_events_timebox(ctx, bkpr, cmd, start_time, end_time); |
| 153 | accts = list_accounts(ctx, bkpr); |
| 154 | |
| 155 | apys = tal_arr(ctx, struct channel_apy *, 0); |
| 156 | |
| 157 | /* Sort events by acct_name */ |
| 158 | asort(evs, tal_count(evs), cmp_channel_event_acct, NULL); |
| 159 | /* Sort accounts by name also */ |
| 160 | asort(accts, tal_count(accts), cmp_acct, NULL); |
| 161 | |
| 162 | acct = NULL; |
| 163 | apy = new_channel_apy(apys); |
| 164 | for (size_t i = 0; i < tal_count(evs); i++) { |
| 165 | struct channel_event *ev = evs[i]; |
| 166 | bool ok; |
| 167 | |
| 168 | if (!acct || !streq(acct->name, ev->acct_name)) { |
| 169 | if (acct && is_channel_account(acct->name)) { |
| 170 | fillin_apy_acct_details(bkpr, cmd, acct, |
| 171 | current_blockheight, |
| 172 | apy); |
| 173 | /* Save current apy, make new */ |
| 174 | tal_arr_expand(&apys, apy); |
| 175 | apy = new_channel_apy(apys); |
| 176 | } |
| 177 | acct = search_account(accts, ev->acct_name); |
| 178 | assert(acct); |
| 179 | } |
| 180 | |
| 181 | /* No entry for external or wallet accts */ |
| 182 | if (!is_channel_account(acct->name)) |
| 183 | continue; |
| 184 | |
| 185 | /* Accumulate routing stats */ |
| 186 | if (streq("routed", ev->tag) |
| 187 | || streq("invoice", ev->tag)) { |
| 188 | ok = amount_msat_accumulate(&apy->routed_in, |
| 189 | ev->credit); |
| 190 | assert(ok); |
| 191 | ok = amount_msat_accumulate(&apy->routed_out, |
| 192 | ev->debit); |
| 193 | assert(ok); |
| 194 | |
| 195 | /* No fees for invoices */ |
| 196 | if (streq("invoice", ev->tag)) |
| 197 | continue; |
| 198 |
no test coverage detected