From 840e81426e29ab94bb16a0e3aa85792661b39a3c Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 21 Jul 2016 19:04:23 +0800 Subject: [PATCH] showing public address components added --- src/page.h | 54 +++++++++++++++++++++++++++++++++++++- src/templates/address.html | 28 ++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/templates/address.html diff --git a/src/page.h b/src/page.h index 63cdde2..eb5115e 100644 --- a/src/page.h +++ b/src/page.h @@ -33,6 +33,7 @@ #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" @@ -1407,7 +1408,34 @@ namespace xmreg { { return result_html; } + } + + + // check if monero address is given based on its length + // if yes, then we can only show its public components + if (search_text.length() == 95) + { + cout << "address is given " << endl; + + // parse string representing given monero address + cryptonote::account_public_address address; + + bool testnet {false}; + + if (search_text[0] == '9' || search_text[0] == 'A') + testnet = true; + if (!xmreg::parse_str_address(search_text, address, testnet)) + { + cerr << "Cant parse string address: " << search_text << endl; + return string("Cant parse address (probably incorrect format): ") + + search_text; + } + + cout << "public spend key: " << address.m_spend_public_key << endl; + cout << "public view key: " << address.m_view_public_key << endl; + + return show_address_details(address, testnet); } // second let try searching for tx @@ -1646,12 +1674,36 @@ namespace xmreg { } - result_html = show_search_results(search_text, all_possible_tx_hashes); return result_html; } + string + show_address_details(const account_public_address& address, bool testnet = false) + { + + string address_str = xmreg::print_address(address, testnet); + string pub_viewkey_str = fmt::format("{:s}", address.m_view_public_key); + string pub_spendkey_str = fmt::format("{:s}", address.m_spend_public_key); + + mstch::map context { + {"xmr_address" , REMOVE_HASH_BRAKETS(address_str)}, + {"public_viewkey" , REMOVE_HASH_BRAKETS(pub_viewkey_str)}, + {"public_spendkey" , REMOVE_HASH_BRAKETS(pub_spendkey_str)}, + {"testnet" , testnet}, + }; + + // read address.html + string address_html = xmreg::read(TMPL_ADDRESS); + + // add header and footer + string full_page = get_full_page(address_html); + + // render the page + return mstch::render(full_page, context); + } + map> search_txs(vector txs, const string& search_text) diff --git a/src/templates/address.html b/src/templates/address.html new file mode 100644 index 0000000..581725a --- /dev/null +++ b/src/templates/address.html @@ -0,0 +1,28 @@ + +
+
+

Address:
{{xmr_address}}

+
+ + {{#testnet}} +

Testnet address: Yes

+ {{/testnet}} + {{^testnet}} +

Testnet address: No

+ {{/testnet}} + +
+

Associated public keys

+ +

Public view key: {{public_viewkey}}

+

Public spend key: {{public_spendkey}}

+ +
+

+ Transactions:
Sorry, its not possible to find txs associated with + normal addresses in Monero +

+ +
+
+