better error messages added to key image file checker

master
moneroexamples 8 years ago
parent 3a405627bb
commit 8a731907f5

@ -2031,18 +2031,52 @@ public:
string decoded_raw_data = epee::string_encoding::base64_decode(raw_data); string decoded_raw_data = epee::string_encoding::base64_decode(raw_data);
secret_key prv_view_key; secret_key prv_view_key;
// initalize page template context map
mstch::map context{
{"testnet" , testnet},
{"has_error", false},
{"error_msg", string{}},
};
// read page template
string checkrawkeyimgs_html = xmreg::read(TMPL_MY_CHECKRAWKEYIMGS);
// add footer
string full_page = checkrawkeyimgs_html + xmreg::read(TMPL_FOOTER);
add_css_style(context);
if (viewkey_str.empty())
{
string error_msg = fmt::format("View key not given. Cant decode "
"the key image data without it!");
context["has_error"] = true;
context["error_msg"] = error_msg;
return mstch::render(full_page, context);
}
if (!xmreg::parse_str_secret_key(viewkey_str, prv_view_key)) if (!xmreg::parse_str_secret_key(viewkey_str, prv_view_key))
{ {
cerr << "Cant parse the private key: " << viewkey_str << endl; string error_msg = fmt::format("Cant parse the private key: " + viewkey_str);
return string("Cant parse private key: " + viewkey_str);
context["has_error"] = true;
context["error_msg"] = error_msg;
return mstch::render(full_page, context);
} }
const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC); const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC);
if (!strncmp(decoded_raw_data.c_str(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen) == 0) if (!strncmp(decoded_raw_data.c_str(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen) == 0)
{ {
cout << "This does not seem to be key image export data" << endl; string error_msg = fmt::format("This does not seem to be key image export data.");
return string {"This does not seem to be key image export data"};
context["has_error"] = true;
context["error_msg"] = error_msg;
return mstch::render(full_page, context);
} }
// decrypt key images data using private view key // decrypt key images data using private view key
@ -2052,8 +2086,13 @@ public:
if (decoded_raw_data.empty()) if (decoded_raw_data.empty())
{ {
return string {"Failed to authenticate key images data. " string error_msg = fmt::format("Failed to authenticate key images data. "
"Maybe wrong viewkey was porvided?"}; "Maybe wrong viewkey was porvided?");
context["has_error"] = true;
context["error_msg"] = error_msg;
return mstch::render(full_page, context);
} }
// header is public spend and keys // header is public spend and keys
@ -2064,8 +2103,13 @@ public:
if (decoded_raw_data.size() < header_lenght) if (decoded_raw_data.size() < header_lenght)
{ {
cerr << "Bad data size from submitted key images raw data" << endl; string error_msg = fmt::format("Bad data size from submitted key images raw data.");
return string {"Bad data size from submitted key images raw data"};
context["has_error"] = true;
context["error_msg"] = error_msg;
return mstch::render(full_page, context);
} }
// get xmr address stored in this key image file // get xmr address stored in this key image file
@ -2073,15 +2117,11 @@ public:
reinterpret_cast<const account_public_address*>( reinterpret_cast<const account_public_address*>(
decoded_raw_data.data()); decoded_raw_data.data());
// initalize page template context map context.insert({"address" , REMOVE_HASH_BRAKETS(xmreg::print_address(*xmr_address, testnet))});
mstch::map context { context.insert({"viewkey" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", prv_view_key))});
{"testnet" , testnet}, context.insert({"has_total_xmr" , false});
{"address" , REMOVE_HASH_BRAKETS(xmreg::print_address(*xmr_address, testnet))}, context.insert({"total_xmr" , string{}});
{"viewkey" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", prv_view_key))}, context.insert({"key_imgs" , mstch::array{}});
{"has_total_xmr" , false},
{"total_xmr" , string{}},
{"key_imgs" , mstch::array{}}
};
unique_ptr<xmreg::MyLMDB> mylmdb; unique_ptr<xmreg::MyLMDB> mylmdb;
@ -2189,13 +2229,6 @@ public:
context["total_xmr"] = xmreg::xmr_amount_to_str(total_xmr); context["total_xmr"] = xmreg::xmr_amount_to_str(total_xmr);
} }
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 // render the page
return mstch::render(full_page, context); return mstch::render(full_page, context);
} }

@ -21,6 +21,12 @@
<h4 style="font-size: 15px; margin: 0px">(no javascript - no cookies - no web analytics trackers - no images - open sourced)</h4> <h4 style="font-size: 15px; margin: 0px">(no javascript - no cookies - no web analytics trackers - no images - open sourced)</h4>
</div> </div>
{{#has_error}}
<h4 style="color:red">Attempt failed</h4>
<h4>{{error_msg}}</h4>
{{/has_error}}
{{^has_error}}
<h4>Key images for address: {{address}}</h4> <h4>Key images for address: {{address}}</h4>
<h4>Viewkey: {{viewkey}}</h4> <h4>Viewkey: {{viewkey}}</h4>
{{#has_total_xmr}} {{#has_total_xmr}}
@ -69,4 +75,6 @@
</div> </div>
{{/has_error}}
</div> </div>
Loading…
Cancel
Save