From f290c1db43a5e415aef14d929a9689227369f57f Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sat, 2 Sep 2017 08:59:45 +0800 Subject: [PATCH] add prove and myoutpus shortcut links --- main.cpp | 38 +++++++++++++++++++++++++++++++++-- src/page.h | 15 +++++++++++--- src/templates/my_outputs.html | 3 +++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index f085994..e7ba34e 100644 --- a/main.cpp +++ b/main.cpp @@ -253,6 +253,12 @@ main(int ac, const char* av[]) // crow instance crow::SimpleApp app; + // get domian url based on the request + auto get_domain = [&use_ssl](crow::request const& req) { + return (use_ssl ? "https://" : "http://") + + req.get_header_value("Host"); + }; + CROW_ROUTE(app, "/") ([&](const crow::request& req) { return crow::response(xmrblocks.index2()); @@ -304,8 +310,22 @@ main(int ac, const char* av[]) // using tx pusher string raw_tx_data = post_body["raw_tx_data"]; + string domain = get_domain(req); + + return xmrblocks.show_my_outputs(tx_hash, xmr_address, + viewkey, raw_tx_data, + domain); + }); + + CROW_ROUTE(app, "/myoutputs///") + ([&](const crow::request& req, string tx_hash, + string xmr_address, string viewkey) { + + string domain = get_domain(req); + return xmrblocks.show_my_outputs(tx_hash, xmr_address, - viewkey, raw_tx_data); + viewkey, string {}, + domain); }); CROW_ROUTE(app, "/prove").methods("POST"_method) @@ -326,7 +346,21 @@ main(int ac, const char* av[]) string tx_prv_key = post_body["txprvkey"];; string xmr_address = post_body["xmraddress"];; - return xmrblocks.show_prove(tx_hash, xmr_address, tx_prv_key); + string domain = get_domain(req); + + return xmrblocks.show_prove(tx_hash, xmr_address, + tx_prv_key, domain); + }); + + + CROW_ROUTE(app, "/prove///") + ([&](const crow::request& req, string tx_hash, + string xmr_address, string tx_prv_key) { + + string domain = get_domain(req); + + return xmrblocks.show_prove(tx_hash, xmr_address, + tx_prv_key, domain); }); if (enable_pusher) diff --git a/src/page.h b/src/page.h index f6e44a3..50e2549 100644 --- a/src/page.h +++ b/src/page.h @@ -1412,6 +1412,7 @@ namespace xmreg string xmr_address_str, string viewkey_str, /* or tx_prv_key_str when tx_prove == true */ string raw_tx_data, + string domain, bool tx_prove = false) { @@ -1595,6 +1596,11 @@ namespace xmreg string pid_str = pod_to_hex(txd.payment_id); string pid8_str = pod_to_hex(txd.payment_id8); + string shortcut_url = domain + + (tx_prove ? "/prove" : "/myoutputs") + + "/" + tx_hash_str + + "/" + xmr_address_str + + "/" + viewkey_str; // initalise page tempate map with basic info about blockchain mstch::map context { @@ -1616,7 +1622,8 @@ namespace xmreg {"payment_id" , pid_str}, {"payment_id8" , pid8_str}, {"decrypted_payment_id8", string{}}, - {"tx_prove" , tx_prove} + {"tx_prove" , tx_prove}, + {"shortcut_url" , shortcut_url} }; string server_time_str = xmreg::timestamp_to_str_gm(server_timestamp, "%F"); @@ -2096,12 +2103,14 @@ namespace xmreg string show_prove(string tx_hash_str, string xmr_address_str, - string tx_prv_key_str) + string tx_prv_key_str, + string domain) { string raw_tx_data {""}; // not using it in prove tx. only for outputs return show_my_outputs(tx_hash_str, xmr_address_str, - tx_prv_key_str, raw_tx_data, true); + tx_prv_key_str, raw_tx_data, + domain, true); } string diff --git a/src/templates/my_outputs.html b/src/templates/my_outputs.html index ac02d5f..b245cfe 100644 --- a/src/templates/my_outputs.html +++ b/src/templates/my_outputs.html @@ -76,6 +76,9 @@ 0.000000000000 {{/found_our_outputs}} +

+ link to this page +