| 262 | } |
| 263 | |
| 264 | WARN_UNUSED_RESULT static bool calc_apy(struct amount_msat earned, |
| 265 | struct amount_msat capital, |
| 266 | u32 blocks_elapsed, |
| 267 | double *result) |
| 268 | { |
| 269 | double apy; |
| 270 | |
| 271 | assert(!amount_msat_zero(capital)); |
| 272 | assert(blocks_elapsed > 0); |
| 273 | |
| 274 | apy = amount_msat_ratio(earned, capital) * BLOCK_YEAR / blocks_elapsed; |
| 275 | |
| 276 | /* convert to percent */ |
| 277 | apy *= 100; |
| 278 | |
| 279 | /* If mantissa is < 64 bits, a naive "if (scaled > |
| 280 | * UINT64_MAX)" doesn't work. Stick to powers of 2. */ |
| 281 | if (apy >= (double)((u64)1 << 63) * 2) |
| 282 | return false; |
| 283 | |
| 284 | *result = apy; |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | void json_add_channel_apy(struct json_stream *res, |
| 289 | const struct channel_apy *apy) |
no test coverage detected