From 51b1a6494d98a7784c820559effe7ae9ce62ec47 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Fri, 22 Jul 2016 09:36:37 +0000 Subject: [PATCH] searching by payment id in integrated addresses added --- src/page.h | 72 +++++++++++++++++++++++++++++++++----- src/templates/address.html | 27 +++++++++----- 2 files changed, 82 insertions(+), 17 deletions(-) diff --git a/src/page.h b/src/page.h index eb5115e..0a3b75e 100644 --- a/src/page.h +++ b/src/page.h @@ -1415,8 +1415,6 @@ namespace xmreg { // 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; @@ -1432,12 +1430,37 @@ namespace xmreg { + 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); } + // check if integrated monero address is given based on its length + // if yes, then show its public components search tx based on encrypted id + if (search_text.length() == 106) + { + + cryptonote::account_public_address address; + + bool has_payment_id; + + crypto::hash8 encrypted_payment_id; + + bool testnet; + + if (!get_account_integrated_address_from_str(address, + has_payment_id, + encrypted_payment_id, + testnet, + search_text)) + { + cerr << "Cant parse string integerated address: " << search_text << endl; + return string("Cant parse address (probably incorrect format): ") + + search_text; + } + + return show_integrated_address_details(address, encrypted_payment_id, testnet); + } + + // second let try searching for tx result_html = show_tx(search_text); @@ -1688,10 +1711,11 @@ namespace xmreg { 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}, + {"xmr_address" , REMOVE_HASH_BRAKETS(address_str)}, + {"public_viewkey" , REMOVE_HASH_BRAKETS(pub_viewkey_str)}, + {"public_spendkey" , REMOVE_HASH_BRAKETS(pub_spendkey_str)}, + {"is_integrated_addr" , false}, + {"testnet" , testnet}, }; // read address.html @@ -1704,6 +1728,36 @@ namespace xmreg { return mstch::render(full_page, context); } + // ; + string + show_integrated_address_details(const account_public_address& address, + const crypto::hash8& encrypted_payment_id, + 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); + string enc_payment_id_str = fmt::format("{:s}", encrypted_payment_id); + + 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)}, + {"encrypted_payment_id" , REMOVE_HASH_BRAKETS(enc_payment_id_str)}, + {"is_integrated_addr" , true}, + {"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 index 581725a..72ab5ff 100644 --- a/src/templates/address.html +++ b/src/templates/address.html @@ -5,23 +5,34 @@
{{#testnet}} -

Testnet address: Yes

+

Testnet address: Yes

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

Testnet address: No

+

Testnet address: No

{{/testnet}}

Associated public keys

-

Public view key: {{public_viewkey}}

-

Public spend key: {{public_spendkey}}

+

View key: {{public_viewkey}}

+

Spend key: {{public_spendkey}}

+
+ {{#is_integrated_addr}} +

Encrypted payment id: {{encrypted_payment_id}}

+
+

+ Search for transactions associated with this encrypted payment id +

+ {{/is_integrated_addr}} + {{^is_integrated_addr}} +

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

+ {{/is_integrated_addr}}
-

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

+