/api/emission added

This commit is contained in:
moneroexamples 2017-05-19 17:50:12 +08:00
parent 2c133482af
commit 7b9ee5732d
2 changed files with 53 additions and 0 deletions

View file

@ -487,6 +487,14 @@ int main(int ac, const char* av[]) {
return r;
});
CROW_ROUTE(app, "/api/emission")
([&](const crow::request &req) {
myxmr::jsonresponse r{xmrblocks.json_emission()};
return r;
});
CROW_ROUTE(app, "/api/outputs").methods("GET"_method)
([&](const crow::request &req) {

View file

@ -4802,6 +4802,50 @@ namespace xmreg
}
/*
* Lets use this json api convention for success and error
* https://labs.omniti.com/labs/jsend
*/
json
json_emission()
{
json j_response {
{"status", "fail"},
{"data", json {}}
};
json& j_data = j_response["data"];
json j_info;
// get basic network info
if (!CurrentBlockchainStatus::is_thread_running())
{
j_data["title"] = "Emission monitoring thread not enabled.";
return j_response;
}
else
{
CurrentBlockchainStatus::Emission current_values
= CurrentBlockchainStatus::get_emission();
string emission_blk_no = std::to_string(current_values.blk_no - 1);
string emission_coinbase = xmr_amount_to_str(current_values.coinbase, "{:0.3f}");
string emission_fee = xmr_amount_to_str(current_values.fee, "{:0.3f}");
j_data = json {
{"blk_no" , current_values.blk_no - 1},
{"coinbase", current_values.coinbase},
{"fee" , current_values.fee},
};
}
j_response["status"] = "success";
return j_response;
}
private:
json
@ -5657,3 +5701,4 @@ namespace xmreg
#endif //CROWXMR_PAGE_H