Search for added and dev started

This commit is contained in:
moneroexamples 2016-04-24 11:42:49 +08:00
parent 917a9fcdfd
commit 9235222a60
3 changed files with 48 additions and 5 deletions

View File

@ -94,6 +94,12 @@ int main(int ac, const char* av[]) {
return xmrblocks.show_tx(tx_hash); 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") CROW_ROUTE(app, "/autorefresh")
([&]() { ([&]() {
uint64_t page_no {0}; uint64_t page_no {0};

View File

@ -431,7 +431,7 @@ namespace xmreg {
if (!mcore->get_block_by_height(_blk_height, blk)) if (!mcore->get_block_by_height(_blk_height, blk))
{ {
cerr << "Cant get block: " << _blk_height << endl; 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 // get block's hash
@ -615,7 +615,7 @@ namespace xmreg {
if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash)) if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash))
{ {
cerr << "Cant parse tx hash: " << tx_hash_str << endl; 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 // tx age
@ -628,7 +628,7 @@ namespace xmreg {
if (!mcore->get_tx(tx_hash, tx)) 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; << ". Check mempool now" << endl;
vector<pair<tx_info, transaction>> found_txs vector<pair<tx_info, transaction>> found_txs
@ -653,7 +653,7 @@ namespace xmreg {
else else
{ {
// tx is nowhere to be found :-( // 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); 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: private:
@ -947,7 +971,7 @@ namespace xmreg {
if (!parse_and_validate_tx_from_blob( if (!parse_and_validate_tx_from_blob(
tx_blob, tx)) tx_blob, tx))
{ {
cerr << "Cant parse tx from blob" << endl; cerr << "Cant get tx from blob" << endl;
continue; continue;
} }

View File

@ -56,6 +56,12 @@
text-decoration: none; text-decoration: none;
color: white; color: white;
} }
form {
display: inline-block;
text-align: center;
}
</style> </style>
</head> </head>
@ -66,3 +72,10 @@
<h1 class="center"><a href="/">Onion Monero Blockchain Explorer</a></h1> <h1 class="center"><a href="/">Onion Monero Blockchain Explorer</a></h1>
<h4 style="font-size: 15px; margin: 0px">(no javascript - no web analytics trackers - no images - open sourced)</h4> <h4 style="font-size: 15px; margin: 0px">(no javascript - no web analytics trackers - no images - open sourced)</h4>
</div> </div>
<div class="center">
<form action="/search" method="get" style="width:100%; margin-top:10px">
<input type="text" name="value" size="100">
<input type="submit" value="Search">
</form>
</div>