From fc17deb58c79f795456e5b0624a37030a6b80753 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Mon, 24 Oct 2016 12:12:40 +0800 Subject: [PATCH] basic signed key images info shown --- main.cpp | 20 +++++ src/page.h | 137 +++++++++++++++++++++++++---- src/templates/checkrawkeyimgs.html | 45 ++++++++++ src/templates/rawkeyimgs.html | 35 ++++++++ src/templates/rawtx.html | 6 -- 5 files changed, 219 insertions(+), 24 deletions(-) create mode 100644 src/templates/checkrawkeyimgs.html create mode 100644 src/templates/rawkeyimgs.html diff --git a/main.cpp b/main.cpp index e1c56e9..0e4864b 100644 --- a/main.cpp +++ b/main.cpp @@ -234,6 +234,26 @@ int main(int ac, const char* av[]) { }); + CROW_ROUTE(app, "/rawkeyimgs") + ([&](const crow::request& req) { + return xmrblocks.show_rawkeyimgs(); + }); + + CROW_ROUTE(app, "/checkrawkeyimgs").methods("POST"_method) + ([&](const crow::request& req) { + + map post_body = xmreg::parse_crow_post_data(req.body); + + if (post_body.count("rawkeyimgsdata") == 0) + { + return string("Raw key images data not given"); + } + + string raw_data = post_body["rawkeyimgsdata"]; + + return xmrblocks.show_checkrawkeyimgs(raw_data); + }); + CROW_ROUTE(app, "/search").methods("GET"_method) ([&](const crow::request& req) { diff --git a/src/page.h b/src/page.h index 4e48a47..aa522cb 100644 --- a/src/page.h +++ b/src/page.h @@ -25,24 +25,26 @@ #include #include -#define TMPL_DIR "./templates" -#define TMPL_PARIALS_DIR TMPL_DIR "/partials" -#define TMPL_CSS_STYLES TMPL_DIR "/css/style.css" -#define TMPL_INDEX TMPL_DIR "/index.html" -#define TMPL_INDEX2 TMPL_DIR "/index2.html" -#define TMPL_MEMPOOL TMPL_DIR "/mempool.html" -#define TMPL_HEADER TMPL_DIR "/header.html" -#define TMPL_FOOTER TMPL_DIR "/footer.html" -#define TMPL_BLOCK TMPL_DIR "/block.html" -#define TMPL_TX TMPL_DIR "/tx.html" -#define TMPL_ADDRESS TMPL_DIR "/address.html" -#define TMPL_MY_OUTPUTS TMPL_DIR "/my_outputs.html" -#define TMPL_SEARCH_RESULTS TMPL_DIR "/search_results.html" -#define TMPL_MY_RAWTX TMPL_DIR "/rawtx.html" -#define TMPL_MY_CHECKRAWTX TMPL_DIR "/checkrawtx.html" -#define TMPL_MY_PUSHRAWTX TMPL_DIR "/pushrawtx.html" - - +#define TMPL_DIR "./templates" +#define TMPL_PARIALS_DIR TMPL_DIR "/partials" +#define TMPL_CSS_STYLES TMPL_DIR "/css/style.css" +#define TMPL_INDEX TMPL_DIR "/index.html" +#define TMPL_INDEX2 TMPL_DIR "/index2.html" +#define TMPL_MEMPOOL TMPL_DIR "/mempool.html" +#define TMPL_HEADER TMPL_DIR "/header.html" +#define TMPL_FOOTER TMPL_DIR "/footer.html" +#define TMPL_BLOCK TMPL_DIR "/block.html" +#define TMPL_TX TMPL_DIR "/tx.html" +#define TMPL_ADDRESS TMPL_DIR "/address.html" +#define TMPL_MY_OUTPUTS TMPL_DIR "/my_outputs.html" +#define TMPL_SEARCH_RESULTS TMPL_DIR "/search_results.html" +#define TMPL_MY_RAWTX TMPL_DIR "/rawtx.html" +#define TMPL_MY_CHECKRAWTX TMPL_DIR "/checkrawtx.html" +#define TMPL_MY_PUSHRAWTX TMPL_DIR "/pushrawtx.html" +#define TMPL_MY_RAWKEYIMGS TMPL_DIR "/rawkeyimgs.html" +#define TMPL_MY_CHECKRAWKEYIMGS TMPL_DIR "/checkrawkeyimgs.html" + +#define KEY_IMAGE_EXPORT_FILE_MAGIC "Monero key image export\001" namespace xmreg { @@ -1963,6 +1965,105 @@ namespace xmreg { } + string + show_rawkeyimgs() + { + // initalize page template context map + mstch::map context { + {"testnet" , testnet} + }; + + // read checkrawtx.html + string rawkeyimgs_html = xmreg::read(TMPL_MY_RAWKEYIMGS); + + // add header and footer + string full_page = rawkeyimgs_html + xmreg::read(TMPL_FOOTER); + + add_css_style(context); + + // render the page + return mstch::render(full_page, context); + } + + string + show_checkrawkeyimgs(string raw_data) + { + // remove white characters + boost::trim(raw_data); + boost::erase_all(raw_data, "\r\n"); + boost::erase_all(raw_data, "\n"); + + string decoded_raw_data = epee::string_encoding::base64_decode(raw_data); + + + const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC); + + if (strncmp(decoded_raw_data.c_str(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen) == 0) + { + cout << "KEY_IMAGE_EXPORT_FILE_MAGIC data given" << endl; + } + + // header is magic + public spend and keys + const size_t header_lenght = magiclen + 2 * sizeof(crypto::public_key); + const size_t key_img_size = sizeof(crypto::key_image); + const size_t record_lenght = key_img_size + sizeof(crypto::signature); + + if ((decoded_raw_data.size() - header_lenght) % record_lenght) + { + cerr << "Bad data size from submitted key images raw data" << endl; + return string {"Bad data size from submitted key images raw data"}; + } + + // get xmr address stored in this key image file + const account_public_address* xmr_address = + reinterpret_cast( + decoded_raw_data.data() + magiclen); + + // initalize page template context map + mstch::map context { + {"testnet" , testnet}, + {"address" , xmreg::print_address(*xmr_address, testnet)}, + {"key_imgs" , mstch::array{}} + }; + + size_t no_key_images = (decoded_raw_data.size() - header_lenght) / record_lenght; + + //vector> signed_key_images; + + mstch::array& key_imgs_ctx = boost::get(context["key_imgs"]); + + for (size_t n = 0; n < no_key_images; ++n) + { + const char* record_ptr = decoded_raw_data.data() + header_lenght + n * record_lenght; + + crypto::key_image key_image + = *reinterpret_cast(record_ptr); + + crypto::signature signature + = *reinterpret_cast(record_ptr + key_img_size); + + key_imgs_ctx.push_back(mstch::map{ + {"key_no" , fmt::format("{:03d}", n)}, + {"key_image" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", key_image))}, + {"signature" , fmt::format("{:s}", signature)}, + {"is_spent" , core_storage->have_tx_keyimg_as_spent(key_image)} + }); + + //signed_key_images.push_back(make_pair(key_image, signature)); + } + + string checkrawkeyimgs_html = xmreg::read(TMPL_MY_CHECKRAWKEYIMGS); + + // add footer + string full_page = checkrawkeyimgs_html + xmreg::read(TMPL_FOOTER); + + add_css_style(context); + + // render the page + return mstch::render(full_page, context); + } + + string search(string search_text) { diff --git a/src/templates/checkrawkeyimgs.html b/src/templates/checkrawkeyimgs.html new file mode 100644 index 0000000..4460abc --- /dev/null +++ b/src/templates/checkrawkeyimgs.html @@ -0,0 +1,45 @@ + + + + + + {{#refresh}} + + {{/refresh}} + Onion Monero Blockchain Explorer + + + + + +
+ +
+

Onion Monero Signed Key Images Checker

+

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

+
+ +

Key images for address: {{address}}

+ +
+ + + {{#key_imgs}} + + + + {{#is_spent}} + + {{/is_spent}} + {{^is_spent}} + + {{/is_spent}} + + {{/key_imgs}} +
Key no.Key imageIs spent?
{{key_no}}{{key_image}}{{is_spent}}{{is_spent}}
+
+ + +
\ No newline at end of file diff --git a/src/templates/rawkeyimgs.html b/src/templates/rawkeyimgs.html new file mode 100644 index 0000000..555f395 --- /dev/null +++ b/src/templates/rawkeyimgs.html @@ -0,0 +1,35 @@ + + + + + + {{#refresh}} + + {{/refresh}} + Onion Monero Blockchain Explorer + + + + + +
+ +
+

Onion Monero Signed Key Images Checker

+

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

+
+ +
+
+ Paste base64 encoded, signed key images data here
+ (In Linux, can get base64 signed raw tx data: base64 signed_key_images | xclip -selection clipboard)
+ +
+ +
+
+ + +
\ No newline at end of file diff --git a/src/templates/rawtx.html b/src/templates/rawtx.html index ca95672..7330423 100644 --- a/src/templates/rawtx.html +++ b/src/templates/rawtx.html @@ -21,12 +21,6 @@

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

- {{^testnet}} - - {{/testnet}} - {{#testnet}} - - {{/testnet}}