| 54 | }; |
| 55 | |
| 56 | static struct command_result * |
| 57 | getblockheight_done(struct command *cmd, const char *buf, |
| 58 | const jsmntok_t *result, |
| 59 | struct apy_req *req) |
| 60 | { |
| 61 | const jsmntok_t *blockheight_tok; |
| 62 | u32 blockheight; |
| 63 | struct json_stream *res; |
| 64 | struct channel_apy **apys, *net_apys; |
| 65 | |
| 66 | blockheight_tok = json_get_member(buf, result, "blockheight"); |
| 67 | if (!blockheight_tok) |
| 68 | plugin_err(cmd->plugin, "getblockheight: " |
| 69 | "getinfo gave no 'blockheight'? '%.*s'", |
| 70 | result->end - result->start, buf); |
| 71 | |
| 72 | if (!json_to_u32(buf, blockheight_tok, &blockheight)) |
| 73 | plugin_err(cmd->plugin, "getblockheight: " |
| 74 | "getinfo gave non-unsigned-32-bit 'blockheight'? '%.*s'", |
| 75 | result->end - result->start, buf); |
| 76 | |
| 77 | /* Get the income events */ |
| 78 | db_begin_transaction(db); |
| 79 | apys = compute_channel_apys(cmd, db, |
| 80 | *req->start_time, |
| 81 | *req->end_time, |
| 82 | blockheight); |
| 83 | db_commit_transaction(db); |
| 84 | |
| 85 | /* Setup the net_apys entry */ |
| 86 | net_apys = new_channel_apy(cmd); |
| 87 | net_apys->end_blockheight = 0; |
| 88 | net_apys->start_blockheight = UINT_MAX; |
| 89 | net_apys->our_start_bal = AMOUNT_MSAT(0); |
| 90 | net_apys->total_start_bal = AMOUNT_MSAT(0); |
| 91 | |
| 92 | res = jsonrpc_stream_success(cmd); |
| 93 | json_array_start(res, "channels_apy"); |
| 94 | for (size_t i = 0; i < tal_count(apys); i++) { |
| 95 | json_add_channel_apy(res, apys[i]); |
| 96 | |
| 97 | /* Add to net/rollup APY */ |
| 98 | if (!channel_apy_sum(net_apys, apys[i])) |
| 99 | return command_fail(cmd, PLUGIN_ERROR, |
| 100 | "Overflow adding APYs net"); |
| 101 | } |
| 102 | |
| 103 | /* Append a net/rollup entry */ |
| 104 | if (!amount_msat_zero(net_apys->total_start_bal)) { |
| 105 | net_apys->acct_name = tal_fmt(net_apys, "net"); |
| 106 | json_add_channel_apy(res, net_apys); |
| 107 | } |
| 108 | json_array_end(res); |
| 109 | |
| 110 | return command_finished(cmd, res); |
| 111 | } |
| 112 | |
| 113 | static struct command_result *json_channel_apy(struct command *cmd, |
nothing calls this directly
no test coverage detected