diff --git a/README.md b/README.md index c3908a2..20b5998 100644 --- a/README.md +++ b/README.md @@ -716,6 +716,27 @@ curl -w "\n" -X GET "http://139.162.32.245:8081/api/emission" Emission only works when the emission monitoring thread is enabled. +#### api/version + +```bash +curl -w "\n" -X GET "http://139.162.32.245:8081/api/version" +``` + +```json +{ + "data": { + "api": 65536, + "blockchain_height": 1357031, + "git_branch_name": "update_to_current_monero", + "last_git_commit_date": "2017-07-25", + "last_git_commit_hash": "a549f25", + "monero_version_full": "0.10.3.1-ab594cfe" + }, + "status": "success" +} +``` + +api number is store as `uint32_t`. #### api/rawblock/ diff --git a/main.cpp b/main.cpp index ca46e8c..36da89c 100644 --- a/main.cpp +++ b/main.cpp @@ -592,6 +592,14 @@ main(int ac, const char* av[]) return r; }); + CROW_ROUTE(app, "/api/version") + ([&](const crow::request &req) { + + myxmr::jsonresponse r{xmrblocks.json_version()}; + + return r; + }); + } if (enable_autorefresh_option) diff --git a/src/page.h b/src/page.h index a9fc9ac..a506555 100644 --- a/src/page.h +++ b/src/page.h @@ -55,6 +55,11 @@ #define TMPL_MY_CHECKRAWOUTPUTKEYS TMPL_DIR "/checkrawoutputkeys.html" +#define ONIONEXPLORER_RPC_VERSION_MAJOR 1 +#define ONIONEXPLORER_RPC_VERSION_MINOR 0 +#define MAKE_ONIONEXPLORER_RPC_VERSION(major,minor) (((major)<<16)|(minor)) +#define ONIONEXPLORER_RPC_VERSION \ + MAKE_ONIONEXPLORER_RPC_VERSION(ONIONEXPLORER_RPC_VERSION_MAJOR, ONIONEXPLORER_RPC_VERSION_MINOR) // basic info about tx to be stored in cashe. @@ -4937,6 +4942,35 @@ namespace xmreg } + /* + * Lets use this json api convention for success and error + * https://labs.omniti.com/labs/jsend + */ + json + json_version() + { + json j_response { + {"status", "fail"}, + {"data", json {}} + }; + + json& j_data = j_response["data"]; + + j_data = json { + {"last_git_commit_hash", string {GIT_COMMIT_HASH}}, + {"last_git_commit_date", string {GIT_COMMIT_DATETIME}}, + {"git_branch_name" , string {GIT_BRANCH_NAME}}, + {"monero_version_full" , string {MONERO_VERSION_FULL}}, + {"api" , ONIONEXPLORER_RPC_VERSION}, + {"blockchain_height" , core_storage->get_current_blockchain_height()} + }; + + j_response["status"] = "success"; + + return j_response; + } + + private: @@ -5884,7 +5918,10 @@ namespace xmreg {"last_git_commit_hash", string {GIT_COMMIT_HASH}}, {"last_git_commit_date", string {GIT_COMMIT_DATETIME}}, {"git_branch_name" , string {GIT_BRANCH_NAME}}, - {"monero_version_full" , string {MONERO_VERSION_FULL}} + {"monero_version_full" , string {MONERO_VERSION_FULL}}, + {"api" , std::to_string(ONIONEXPLORER_RPC_VERSION_MAJOR) + + "." + + std::to_string(ONIONEXPLORER_RPC_VERSION_MINOR)}, }; string footer_html = mstch::render(xmreg::read(TMPL_FOOTER), footer_context); diff --git a/src/templates/footer.html b/src/templates/footer.html index e5db414..4e0cbe6 100644 --- a/src/templates/footer.html +++ b/src/templates/footer.html @@ -1,7 +1,7 @@
source code - | explorer version: {{git_branch_name}}-{{last_git_commit_date}}-{{last_git_commit_hash}} + | explorer version (api): {{git_branch_name}}-{{last_git_commit_date}}-{{last_git_commit_hash}} ({{api}}) | monero version: {{monero_version_full}}