From 7b9ee5732d398149baa48226ed9f003a1234ffe9 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Fri, 19 May 2017 17:50:12 +0800 Subject: [PATCH] /api/emission added --- main.cpp | 8 ++++++++ src/page.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/main.cpp b/main.cpp index e216f7a..c58dac1 100644 --- a/main.cpp +++ b/main.cpp @@ -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) { diff --git a/src/page.h b/src/page.h index 44db60b..2c8d72e 100644 --- a/src/page.h +++ b/src/page.h @@ -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 +