diff --git a/main.cpp b/main.cpp index 9a61c2b..e26ee8e 100644 --- a/main.cpp +++ b/main.cpp @@ -94,6 +94,12 @@ int main(int ac, const char* av[]) { return xmrblocks.show_tx(tx_hash); }); + + CROW_ROUTE(app, "/search").methods("GET"_method) + ([&](const crow::request& req) { + return xmrblocks.search(string(req.url_params.get("value"))); + }); + CROW_ROUTE(app, "/autorefresh") ([&]() { uint64_t page_no {0}; diff --git a/src/page.h b/src/page.h index 06875c1..63a820a 100644 --- a/src/page.h +++ b/src/page.h @@ -431,7 +431,7 @@ namespace xmreg { if (!mcore->get_block_by_height(_blk_height, blk)) { cerr << "Cant get block: " << _blk_height << endl; - return fmt::format("Block of height {:d} not found!", _blk_height); + return fmt::format("Cant get block {:d}!", _blk_height); } // get block's hash @@ -615,7 +615,7 @@ namespace xmreg { if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash)) { cerr << "Cant parse tx hash: " << tx_hash_str << endl; - return string("Cant parse tx hash: " + tx_hash_str); + return string("Cant get tx hash due to parse error: " + tx_hash_str); } // tx age @@ -628,7 +628,7 @@ namespace xmreg { if (!mcore->get_tx(tx_hash, tx)) { - cerr << "Cant find tx ib blockchain: " << tx_hash + cerr << "Cant get tx in blockchain: " << tx_hash << ". Check mempool now" << endl; vector> found_txs @@ -653,7 +653,7 @@ namespace xmreg { else { // tx is nowhere to be found :-( - return string("Cant find tx: " + tx_hash_str); + return string("Cant get tx: " + tx_hash_str); } } @@ -858,6 +858,30 @@ namespace xmreg { return mstch::render(full_page, context); } + string + search(const string& search_text) + { + // first let try searching for tx + // parse tx hash string to hash object + string result_html = show_tx(search_text); + + // nasty check if output is "Cant get" as a sign of + // a not found tx. Later need to think of something better. + if (result_html.find("Cant get") == std::string::npos) { + return result_html; + } + + // if tx search not successful, check if we are looking for block + result_html = show_block(search_text); + + if (result_html.find("Cant get") == std::string::npos) { + return result_html; + } + + + return "No such thing found: " + search_text; + } + private: @@ -947,7 +971,7 @@ namespace xmreg { if (!parse_and_validate_tx_from_blob( tx_blob, tx)) { - cerr << "Cant parse tx from blob" << endl; + cerr << "Cant get tx from blob" << endl; continue; } diff --git a/src/templates/header.html b/src/templates/header.html index 19f2d11..7cd4523 100644 --- a/src/templates/header.html +++ b/src/templates/header.html @@ -56,6 +56,12 @@ text-decoration: none; color: white; } + + form { + display: inline-block; + text-align: center; + } + @@ -66,3 +72,10 @@

Onion Monero Blockchain Explorer

(no javascript - no web analytics trackers - no images - open sourced)

+ +
+
+ + +
+