key image and output keys chekers, pusher, refresh are optional now

This commit is contained in:
moneroexamples 2017-02-28 07:10:50 +00:00
parent c1bc037add
commit 543ad9c3af
5 changed files with 154 additions and 90 deletions

View File

@ -149,10 +149,16 @@ Go to your browser: http://127.0.0.1:8081
```
./xmrblocks -h
xmrblocks, start Onion Monero Blockchain Explorer:
-h [ --help ] [=arg(=1)] (=0) produce help message
-t [ --testnet ] [=arg(=1)] (=0) use testnet blockchain
--enable-pusher [=arg(=1)] (=0) enable pushing signed tx
--enable-key-image-checker [=arg(=1)] (=0)
enable key images file checker
--enable-output-key-checker [=arg(=1)] (=0)
enable outputs key file checker
--enable-autorefresh-option [=arg(=1)] (=0)
enable users to have the index page on
autorefresh
-p [ --port ] arg (=8081) default port
-b [ --bc-path ] arg path to lmdb blockchain
--ssl-crt-file arg A path to crt file for ssl (https)

178
main.cpp
View File

@ -20,9 +20,12 @@ int main(int ac, const char* av[]) {
// get command line options
xmreg::CmdLineOptions opts {ac, av};
auto help_opt = opts.get_option<bool>("help");
auto testnet_opt = opts.get_option<bool>("testnet");
auto enable_pusher_opt = opts.get_option<bool>("enable-pusher");
auto help_opt = opts.get_option<bool>("help");
auto testnet_opt = opts.get_option<bool>("testnet");
auto enable_key_image_checker_opt = opts.get_option<bool>("enable-key-image-checker");
auto enable_output_key_checker_opt = opts.get_option<bool>("enable-output-key-checker");
auto enable_autorefresh_option_opt = opts.get_option<bool>("enable-autorefresh-option");
auto enable_pusher_opt = opts.get_option<bool>("enable-pusher");
// if help was chosen, display help text and finish
if (*help_opt)
@ -30,8 +33,11 @@ int main(int ac, const char* av[]) {
return EXIT_SUCCESS;
}
bool testnet {*testnet_opt};
bool enable_pusher {*enable_pusher_opt};
bool testnet {*testnet_opt};
bool enable_pusher {*enable_pusher_opt};
bool enable_key_image_checker {*enable_key_image_checker_opt};
bool enable_autorefresh_option {*enable_autorefresh_option_opt};
bool enable_output_key_checker {*enable_output_key_checker_opt};
auto port_opt = opts.get_option<string>("port");
auto bc_path_opt = opts.get_option<string>("bc-path");
@ -146,7 +152,10 @@ int main(int ac, const char* av[]) {
deamon_url,
custom_db_path_str,
testnet,
enable_pusher);
enable_pusher,
enable_key_image_checker,
enable_output_key_checker,
enable_autorefresh_option);
// crow instance
crow::SimpleApp app;
@ -184,7 +193,8 @@ int main(int ac, const char* av[]) {
CROW_ROUTE(app, "/myoutputs").methods("POST"_method)
([&](const crow::request& req) {
map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body);
map<std::string, std::string> post_body
= xmreg::parse_crow_post_data(req.body);
if (post_body.count("xmr_address") == 0
|| post_body.count("viewkey") == 0
@ -201,19 +211,22 @@ int main(int ac, const char* av[]) {
// using tx pusher
string raw_tx_data = post_body["raw_tx_data"];
return xmrblocks.show_my_outputs(tx_hash, xmr_address, viewkey, raw_tx_data);
return xmrblocks.show_my_outputs(tx_hash, xmr_address,
viewkey, raw_tx_data);
});
CROW_ROUTE(app, "/prove").methods("POST"_method)
([&](const crow::request& req) {
map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body);
map<std::string, std::string> post_body
= xmreg::parse_crow_post_data(req.body);
if (post_body.count("xmraddress") == 0
|| post_body.count("txprvkey") == 0
|| post_body.count("txhash") == 0)
{
return string("xmr address, tx private key or tx hash not provided");
return string("xmr address, tx private key or "
"tx hash not provided");
}
string tx_hash = post_body["txhash"];;
@ -223,84 +236,96 @@ int main(int ac, const char* av[]) {
return xmrblocks.show_prove(tx_hash, xmr_address, tx_prv_key);
});
CROW_ROUTE(app, "/rawtx")
([&](const crow::request& req) {
return xmrblocks.show_rawtx();
});
if (enable_pusher)
{
CROW_ROUTE(app, "/rawtx")
([&](const crow::request& req) {
return xmrblocks.show_rawtx();
});
CROW_ROUTE(app, "/checkandpush").methods("POST"_method)
([&](const crow::request& req) {
CROW_ROUTE(app, "/checkandpush").methods("POST"_method)
([&](const crow::request& req) {
map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body);
map<std::string, std::string> post_body
= xmreg::parse_crow_post_data(req.body);
if (post_body.count("rawtxdata") == 0 || post_body.count("action") == 0)
{
return string("Raw tx data or action not provided");
}
if (post_body.count("rawtxdata") == 0 || post_body.count("action") == 0)
{
return string("Raw tx data or action not provided");
}
string raw_tx_data = post_body["rawtxdata"];
string action = post_body["action"];
string raw_tx_data = post_body["rawtxdata"];
string action = post_body["action"];
if (action == "check")
return xmrblocks.show_checkrawtx(raw_tx_data, action);
else if (action == "push")
return xmrblocks.show_pushrawtx(raw_tx_data, action);
if (action == "check")
return xmrblocks.show_checkrawtx(raw_tx_data, action);
else if (action == "push")
return xmrblocks.show_pushrawtx(raw_tx_data, action);
});
});
}
CROW_ROUTE(app, "/rawkeyimgs")
([&](const crow::request& req) {
return xmrblocks.show_rawkeyimgs();
});
if (enable_key_image_checker)
{
CROW_ROUTE(app, "/rawkeyimgs")
([&](const crow::request& req) {
return xmrblocks.show_rawkeyimgs();
});
CROW_ROUTE(app, "/checkrawkeyimgs").methods("POST"_method)
([&](const crow::request& req) {
CROW_ROUTE(app, "/checkrawkeyimgs").methods("POST"_method)
([&](const crow::request& req) {
map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body);
map<std::string, std::string> post_body
= xmreg::parse_crow_post_data(req.body);
if (post_body.count("rawkeyimgsdata") == 0)
{
return string("Raw key images data not given");
}
if (post_body.count("rawkeyimgsdata") == 0)
{
return string("Raw key images data not given");
}
if (post_body.count("viewkey") == 0)
{
return string("Viewkey not provided. Cant decrypt key image file without it");
}
if (post_body.count("viewkey") == 0)
{
return string("Viewkey not provided. Cant decrypt key image file without it");
}
string raw_data = post_body["rawkeyimgsdata"];
string viewkey = post_body["viewkey"];
string raw_data = post_body["rawkeyimgsdata"];
string viewkey = post_body["viewkey"];
return xmrblocks.show_checkrawkeyimgs(raw_data, viewkey);
});
return xmrblocks.show_checkrawkeyimgs(raw_data, viewkey);
});
}
CROW_ROUTE(app, "/rawoutputkeys")
([&](const crow::request& req) {
return xmrblocks.show_rawoutputkeys();
});
if (enable_output_key_checker)
{
CROW_ROUTE(app, "/rawoutputkeys")
([&](const crow::request& req) {
return xmrblocks.show_rawoutputkeys();
});
CROW_ROUTE(app, "/checkrawoutputkeys").methods("POST"_method)
([&](const crow::request& req) {
CROW_ROUTE(app, "/checkrawoutputkeys").methods("POST"_method)
([&](const crow::request& req) {
map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body);
map<std::string, std::string> post_body
= xmreg::parse_crow_post_data(req.body);
if (post_body.count("rawoutputkeysdata") == 0)
{
return string("Raw output keys data not given");
}
if (post_body.count("rawoutputkeysdata") == 0)
{
return string("Raw output keys data not given");
}
if (post_body.count("viewkey") == 0)
{
return string("Viewkey not provided. Cant decrypt key image file without it");
}
if (post_body.count("viewkey") == 0)
{
return string("Viewkey not provided. Cant decrypt "
"key image file without it");
}
string raw_data = post_body["rawoutputkeysdata"];
string viewkey = post_body["viewkey"];
return xmrblocks.show_checkcheckrawoutput(raw_data, viewkey);
});
string raw_data = post_body["rawoutputkeysdata"];
string viewkey = post_body["viewkey"];
return xmrblocks.show_checkcheckrawoutput(raw_data, viewkey);
});
}
CROW_ROUTE(app, "/search").methods("GET"_method)
@ -320,19 +345,24 @@ int main(int ac, const char* av[]) {
return text;
});
CROW_ROUTE(app, "/autorefresh")
([&]() {
uint64_t page_no {0};
bool refresh_page {true};
return xmrblocks.index2(page_no, refresh_page);
});
if (enable_autorefresh_option)
{
CROW_ROUTE(app, "/autorefresh")
([&]() {
uint64_t page_no {0};
bool refresh_page {true};
return xmrblocks.index2(page_no, refresh_page);
});
}
// run the crow http server
if (use_ssl)
{
cout << "Staring in ssl mode" << endl;
app.port(app_port).ssl_file(ssl_crt_file, ssl_key_file).multithreaded().run();
app.port(app_port).ssl_file(ssl_crt_file, ssl_key_file)
.multithreaded().run();
}
else
{

View File

@ -27,6 +27,12 @@ namespace xmreg
"use testnet blockchain")
("enable-pusher", value<bool>()->default_value(false)->implicit_value(true),
"enable pushing signed tx")
("enable-key-image-checker", value<bool>()->default_value(false)->implicit_value(true),
"enable key images file checker")
("enable-output-key-checker", value<bool>()->default_value(false)->implicit_value(true),
"enable outputs key file checker")
("enable-autorefresh-option", value<bool>()->default_value(false)->implicit_value(true),
"enable users to have the index page on autorefresh")
("port,p", value<string>()->default_value("8081"),
"default port")
("bc-path,b", value<string>(),

View File

@ -259,6 +259,11 @@ class page {
bool enable_pusher;
bool enable_key_image_checker;
bool enable_output_key_checker;
bool enable_autorefresh_option;
bool have_custom_lmdb;
@ -269,7 +274,10 @@ public:
page(MicroCore* _mcore, Blockchain* _core_storage,
string _deamon_url, string _lmdb2_path,
bool _testnet, bool _enable_pusher)
bool _testnet, bool _enable_pusher,
bool _enable_key_image_checker,
bool _enable_output_key_checker,
bool _enable_autorefresh_option)
: mcore {_mcore},
core_storage {_core_storage},
rpc {_deamon_url},
@ -277,7 +285,10 @@ public:
lmdb2_path {_lmdb2_path},
testnet {_testnet},
enable_pusher {_enable_pusher},
have_custom_lmdb {false}
have_custom_lmdb {false},
enable_key_image_checker {_enable_key_image_checker},
enable_output_key_checker {_enable_output_key_checker},
enable_autorefresh_option {_enable_autorefresh_option}
{
css_styles = xmreg::read(TMPL_CSS_STYLES);
no_of_mempool_tx_of_frontpage = 25;
@ -344,6 +355,10 @@ public:
{"is_page_zero" , !bool(page_no)},
{"next_page" , std::to_string(page_no + 1)},
{"prev_page" , std::to_string((page_no > 0 ? page_no - 1 : 0))},
{"enable_pusher" , enable_pusher},
{"enable_key_image_checker" , enable_key_image_checker},
{"enable_output_key_checker", enable_output_key_checker},
{"enable_autorefresh_option", enable_autorefresh_option}
};
context.emplace("txs", mstch::array()); // will keep tx to show
@ -2541,6 +2556,7 @@ public:
string
show_checkrawkeyimgs(string raw_data, string viewkey_str)
{
clean_post_data(raw_data);
// remove white characters
@ -2904,7 +2920,6 @@ public:
string
show_checkcheckrawoutput(string raw_data, string viewkey_str)
{
clean_post_data(raw_data);
// remove white characters

View File

@ -3,19 +3,26 @@
<h3 style="font-size: 12px; margin-top: 20px">
Server time: {{server_timestamp}} | <a href="/mempool">Memory pool</a>
| <a href="/rawtx">Tx pusher </a>
| <a href="/rawkeyimgs">Key images checker</a>
| <a href="/rawoutputkeys">Output keys checker</a> |
{{#refresh}}
<a href="/">Autorefresh is ON (10 s)</a>
{{/refresh}}
{{^refresh}}
<a href="/autorefresh">Autorefresh is OFF</a>
{{/refresh}}
{{#enable_pusher}}
| <a href="/rawtx">Tx pusher </a>
{{/enable_pusher}}
{{#enable_key_image_checker}}
| <a href="/rawkeyimgs">Key images checker</a>
{{/enable_key_image_checker}}
{{#enable_output_key_checker}}
| <a href="/rawoutputkeys">Output keys checker</a>
{{/enable_output_key_checker}}
{{#enable_autorefresh_option}}
|
{{#refresh}}
<a href="/">Autorefresh is ON (10 s)</a>
{{/refresh}}
{{^refresh}}
<a href="/autorefresh">Autorefresh is OFF</a>
{{/refresh}}
{{/enable_autorefresh_option}}
{{#testnet}}
|
This is <span style="color:#ff6b62">testnet</span> blockchian
| This is <span style="color:#ff6b62">testnet</span> blockchian
{{/testnet}}
</h3>