| 332 | }; |
| 333 | |
| 334 | static struct command_result * |
| 335 | getblockheight_done(struct command *cmd, |
| 336 | const char *method, |
| 337 | const char *buf, |
| 338 | const jsmntok_t *result, |
| 339 | struct apy_req *req) |
| 340 | { |
| 341 | const jsmntok_t *blockheight_tok; |
| 342 | u32 blockheight; |
| 343 | struct json_stream *res; |
| 344 | struct channel_apy **apys, *net_apys; |
| 345 | struct bkpr *bkpr = bkpr_of(cmd->plugin); |
| 346 | |
| 347 | blockheight_tok = json_get_member(buf, result, "blockheight"); |
| 348 | if (!blockheight_tok) |
| 349 | plugin_err(cmd->plugin, "getblockheight: " |
| 350 | "getinfo gave no 'blockheight'? '%.*s'", |
| 351 | result->end - result->start, buf + result->start); |
| 352 | |
| 353 | if (!json_to_u32(buf, blockheight_tok, &blockheight)) |
| 354 | plugin_err(cmd->plugin, "getblockheight: " |
| 355 | "getinfo gave non-unsigned-32-bit 'blockheight'? '%.*s'", |
| 356 | result->end - result->start, buf + result->start); |
| 357 | |
| 358 | /* Get the income events */ |
| 359 | apys = compute_channel_apys(cmd, bkpr, cmd, |
| 360 | *req->start_time, |
| 361 | *req->end_time, |
| 362 | blockheight); |
| 363 | |
| 364 | /* Setup the net_apys entry */ |
| 365 | net_apys = new_channel_apy(cmd); |
| 366 | net_apys->end_blockheight = 0; |
| 367 | net_apys->start_blockheight = UINT_MAX; |
| 368 | net_apys->our_start_bal = AMOUNT_MSAT(0); |
| 369 | net_apys->total_start_bal = AMOUNT_MSAT(0); |
| 370 | |
| 371 | res = jsonrpc_stream_success(cmd); |
| 372 | json_array_start(res, "channels_apy"); |
| 373 | for (size_t i = 0; i < tal_count(apys); i++) { |
| 374 | json_add_channel_apy(res, apys[i]); |
| 375 | |
| 376 | /* Add to net/rollup APY */ |
| 377 | if (!channel_apy_sum(net_apys, apys[i])) |
| 378 | return command_fail(cmd, PLUGIN_ERROR, |
| 379 | "Overflow adding APYs net"); |
| 380 | } |
| 381 | |
| 382 | /* Append a net/rollup entry */ |
| 383 | if (!amount_msat_is_zero(net_apys->total_start_bal)) { |
| 384 | net_apys->acct_name = tal_fmt(net_apys, "net"); |
| 385 | json_add_channel_apy(res, net_apys); |
| 386 | } |
| 387 | json_array_end(res); |
| 388 | |
| 389 | return command_finished(cmd, res); |
| 390 | } |
| 391 |
nothing calls this directly
no test coverage detected