| 236 | } |
| 237 | |
| 238 | WARN_UNUSED_RESULT static bool calc_apy(struct amount_msat earned, |
| 239 | struct amount_msat capital, |
| 240 | u32 blocks_elapsed, |
| 241 | double *result) |
| 242 | { |
| 243 | double apy; |
| 244 | |
| 245 | assert(!amount_msat_is_zero(capital)); |
| 246 | assert(blocks_elapsed > 0); |
| 247 | |
| 248 | apy = amount_msat_ratio(earned, capital) * BLOCK_YEAR / blocks_elapsed; |
| 249 | |
| 250 | /* convert to percent */ |
| 251 | apy *= 100; |
| 252 | |
| 253 | /* If mantissa is < 64 bits, a naive "if (scaled > |
| 254 | * UINT64_MAX)" doesn't work. Stick to powers of 2. */ |
| 255 | if (apy >= (double)((u64)1 << 63) * 2) |
| 256 | return false; |
| 257 | |
| 258 | *result = apy; |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | void json_add_channel_apy(struct json_stream *res, |
| 263 | const struct channel_apy *apy) |
no test coverage detected