From aa32af635f03968e3226bb08778825d4f37e8bcb Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Tue, 28 Feb 2017 00:02:06 +0000 Subject: [PATCH] change search placeholder text depending if custom lmdb exists --- src/page.h | 77 +++++++++++++++++++++++++++++++-------- src/templates/header.html | 14 ++++--- 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/page.h b/src/page.h index ae61c50..307b0f9 100644 --- a/src/page.h +++ b/src/page.h @@ -259,6 +259,8 @@ class page { bool enable_pusher; + bool have_custom_lmdb; + uint64_t no_of_mempool_tx_of_frontpage; @@ -274,10 +276,40 @@ public: server_timestamp {std::time(nullptr)}, lmdb2_path {_lmdb2_path}, testnet {_testnet}, - enable_pusher {_enable_pusher} + enable_pusher {_enable_pusher}, + have_custom_lmdb {false} { css_styles = xmreg::read(TMPL_CSS_STYLES); no_of_mempool_tx_of_frontpage = 25; + + // just moneky patching now, to check + // if custom lmdb database exist, so that + // we can search for, e.g., key images, + // payments ids. try to open this database. + // if it fails, we assume it does not exist. + // this is ugly check, but will do for now. + // it does not even check if this custom lmdb + // is up to date. + try + { + unique_ptr mylmdb; + + if (bf::is_directory(lmdb2_path)) + { + mylmdb = make_unique(lmdb2_path); + + // if we got to here, it seems that database exist + have_custom_lmdb = true; + } + + } + catch (const std::exception& e) + { + cerr << "Custom lmdb databse seem not to exist. Its not big deal. " + "Just some searches wont be possible" + << endl; + } + } /** @@ -302,6 +334,7 @@ public: // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"have_custom_lmdb", have_custom_lmdb}, {"refresh" , refresh_page}, {"height" , std::to_string(height)}, {"server_timestamp", xmreg::timestamp_to_str(server_timestamp)}, @@ -710,6 +743,7 @@ public: // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb}, {"blk_hash" , blk_hash_str}, {"blk_height" , _blk_height}, {"blk_timestamp" , blk_timestamp}, @@ -894,7 +928,8 @@ public: } mstch::map context { - {"testnet" , this->testnet} + {"testnet" , this->testnet}, + {"have_custom_lmdb" , have_custom_lmdb} }; context.emplace("txs" , mstch::array{}); @@ -1108,6 +1143,7 @@ public: // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb}, {"tx_hash" , tx_hash_str}, {"tx_prefix_hash" , pod_to_hex(txd.prefix_hash)}, {"xmr_address" , xmr_address_str}, @@ -1619,7 +1655,8 @@ public: // initalise page tempate map with basic info about blockchain mstch::map context { - {"testnet" , testnet} + {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb} }; // read rawtx.html @@ -1657,6 +1694,7 @@ public: // initalize page template context map mstch::map context { {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb}, {"unsigned_tx_given" , unsigned_tx_given}, {"have_raw_tx" , true}, {"data_prefix" , data_prefix}, @@ -2281,6 +2319,7 @@ public: // initalize page template context map mstch::map context { {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb}, {"have_raw_tx" , true}, {"has_error" , false}, {"error_msg" , string {}}, @@ -2462,7 +2501,8 @@ public: { // initalize page template context map mstch::map context { - {"testnet" , testnet} + {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb} }; // read rawkeyimgs.html @@ -2482,7 +2522,8 @@ public: { // initalize page template context map mstch::map context { - {"testnet" , testnet} + {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb} }; // read rawoutputkeys.html @@ -2510,9 +2551,10 @@ public: // initalize page template context map mstch::map context{ - {"testnet" , testnet}, - {"has_error", false}, - {"error_msg", string{}}, + {"testnet" , testnet}, + {"have_custom_lmdb", have_custom_lmdb}, + {"has_error" , false}, + {"error_msg" , string{}}, }; // read page template @@ -2873,9 +2915,10 @@ public: // initalize page template context map mstch::map context{ - {"testnet", testnet}, - {"has_error", false}, - {"error_msg", string{}}, + {"testnet" , testnet}, + {"have_custom_lmdb", have_custom_lmdb}, + {"has_error" , false}, + {"error_msg" , string{}} }; @@ -3639,6 +3682,7 @@ public: {"public_spendkey" , REMOVE_HASH_BRAKETS(pub_spendkey_str)}, {"is_integrated_addr" , false}, {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb} }; // read address.html @@ -3672,6 +3716,7 @@ public: {"encrypted_payment_id" , REMOVE_HASH_BRAKETS(enc_payment_id_str)}, {"is_integrated_addr" , true}, {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb} }; // read address.html @@ -3786,10 +3831,11 @@ public: // initalise page tempate map with basic info about blockchain mstch::map context { - {"testnet" , testnet}, - {"search_text" , search_text}, - {"no_results" , true}, - {"to_many_results", false} + {"testnet" , testnet}, + {"search_text" , search_text}, + {"no_results" , true}, + {"to_many_results" , false}, + {"have_custom_lmdb", have_custom_lmdb} }; for (const pair>& found_txs: all_possible_tx_hashes) @@ -4000,6 +4046,7 @@ private: // initalise page tempate map with basic info about blockchain mstch::map context { {"testnet" , testnet}, + {"have_custom_lmdb" , have_custom_lmdb}, {"tx_hash" , tx_hash_str}, {"tx_prefix_hash" , pod_to_hex(txd.prefix_hash)}, {"tx_pub_key" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", txd.pk))}, diff --git a/src/templates/header.html b/src/templates/header.html index b68b253..3cb7817 100644 --- a/src/templates/header.html +++ b/src/templates/header.html @@ -22,7 +22,8 @@ - {{^testnet}} + + {{#have_custom_lmdb}}
- {{/testnet}} - {{#testnet}} + {{/have_custom_lmdb}} + {{^have_custom_lmdb}}
- +
- {{/testnet}} + {{/have_custom_lmdb}} +