From e376b87cfbe9c9db4feb9e873bb1e07984d25bb6 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sat, 23 Apr 2016 14:14:22 +0800 Subject: [PATCH] ring signatures added to tx info --- src/page.h | 87 ++++++++++++++++++++++++++++++++++--------- src/templates/tx.html | 50 ++++++++++++++----------- 2 files changed, 99 insertions(+), 38 deletions(-) diff --git a/src/page.h b/src/page.h index 5f2fe25..8a97370 100644 --- a/src/page.h +++ b/src/page.h @@ -55,6 +55,8 @@ namespace xmreg { size_t version; uint64_t unlock_time; + std::vector > signatures; + // key images of inputs vector input_key_imgs; @@ -70,20 +72,53 @@ namespace xmreg { string tx_pk_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", pk)); - return mstch::map { - {"hash" , tx_hash_str}, - {"pub_key" , tx_pk_str}, - {"tx_fee" , fmt::format("{:0.6f}", XMR_AMOUNT(fee))}, - {"sum_inputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_inputs))}, - {"sum_outputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_outputs))}, - {"no_inputs" , input_key_imgs.size()}, - {"no_outputs" , output_pub_keys.size()}, - {"mixin" , std::to_string(mixin_no - 1)}, - {"version" , std::to_string(version)}, - {"unlock_time" , std::to_string(unlock_time)}, - {"tx_size" , fmt::format("{:0.4f}", static_cast(size)/1024.0)} + mstch::map txd_map { + {"hash" , tx_hash_str}, + {"pub_key" , tx_pk_str}, + {"tx_fee" , fmt::format("{:0.6f}", XMR_AMOUNT(fee))}, + {"sum_inputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_inputs))}, + {"sum_outputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_outputs))}, + {"no_inputs" , input_key_imgs.size()}, + {"no_outputs" , output_pub_keys.size()}, + {"mixin" , std::to_string(mixin_no - 1)}, + {"version" , std::to_string(version)}, + {"unlock_time" , std::to_string(unlock_time)}, + {"tx_size" , fmt::format("{:0.4f}", static_cast(size)/1024.0)} }; + + + return txd_map; } + + mstch::array + get_ring_sig_for_input(uint64_t in_i) + { + mstch::array ring_sigs {}; + + if (in_i >= signatures.size()) + { + return ring_sigs; + } + + for (const crypto::signature &sig: signatures.at(in_i)) + { + cout << print_sig(sig) << endl; + ring_sigs.push_back(mstch::map{{"ring_sig", print_signature(sig)}}); + } + + return ring_sigs; + } + + string + print_signature(const signature& sig) + { + stringstream ss; + + ss << epee::string_tools::pod_to_hex(sig.c) + << epee::string_tools::pod_to_hex(sig.r); + + return ss.str(); + } }; class page { @@ -593,12 +628,22 @@ namespace xmreg { cerr << "Cant get block: " << tx_blk_height << endl; } - cout << "tx_blk_height: " << tx_blk_height << endl; + + // calculate difference between tx and server timestamps + pair age = get_age(server_timestamp, + blk.timestamp, FULL_AGE_FORMAT); + // initalise page tempate map with basic info about blockchain mstch::map context { {"tx_hash" , tx_hash_str}, - {"blk_height" , tx_blk_height}, + {"tx_pub_key" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", txd.pk))}, + {"blk_height" , tx_blk_height}, + {"tx_size" , fmt::format("{:0.2f}", + static_cast(txd.size) / 1024.0)}, + {"tx_fee" , fmt::format("{:0.12f}", XMR_AMOUNT(txd.fee))}, + {"blk_timestamp" , xmreg::timestamp_to_str(blk.timestamp)}, + {"delta_time" , age.first}, {"inputs_no" , txd.input_key_imgs.size()}, {"outputs_no" , txd.output_pub_keys.size()} }; @@ -632,10 +677,13 @@ namespace xmreg { inputs.push_back(mstch::map { {"in_key_img", REMOVE_HASH_BRAKETS(fmt::format("{:s}", in_key.k_image))}, {"amount" , fmt::format("{:0.12f}", XMR_AMOUNT(in_key.amount))}, - {"input_idx" , fmt::format("{:02d}", input_idx++)}, + {"input_idx" , fmt::format("{:02d}", input_idx)}, {"mixins" , mstch::array{}}, + {"ring_sigs" , txd.get_ring_sig_for_input(input_idx)} }); + + // get reference to mixins array created above mstch::array& mixins = boost::get( boost::get(inputs.back())["mixins"]); @@ -698,7 +746,8 @@ namespace xmreg { mixin_timestamps.push_back(blk.timestamp); ++count; - } + + } // for (const uint64_t &i: absolute_offsets) // get mixins in time scale for visual representation pair mixin_times_scale = xmreg::timestamps_time_scale( @@ -711,7 +760,9 @@ namespace xmreg { // save the string timescales for later to show mixins_timescales.push_back(mstch::map { {"timescale", mixin_times_scale.first}}); - } + + input_idx++; + } // for (const txin_to_key& in_key: txd.input_key_imgs) context["server_time"] = server_time_str; context["inputs"] = inputs; @@ -780,6 +831,8 @@ namespace xmreg { txd.input_key_imgs = get_key_images(tx); txd.output_pub_keys = get_ouputs(tx); + // get tx signatures for each input + txd.signatures = tx.signatures; // get tx version txd.version = tx.version; diff --git a/src/templates/tx.html b/src/templates/tx.html index faa3301..a344899 100644 --- a/src/templates/tx.html +++ b/src/templates/tx.html @@ -1,7 +1,8 @@
-

Tx hash (block height): {{tx_hash}} ({{blk_height}})

+

Tx hash: {{tx_hash}}

+

Tx public key: {{tx_pub_key}}

{{#have_prev_hash}} @@ -14,22 +15,14 @@ - +
- - - - - - - - - - - - - - + + + + + +
Timestamp [UCT]:{{blk_timestamp}}Age {{age_format}}:{{blk_age}}Δ [h:m:s]:{{delta_time}}
Major.minor version:{{major_ver}}.{{minor_ver}}Block reward:{{blk_reward}}Block size [kB]:{{blk_size}}
nonce:{{blk_nonce}}Total fees:{{sum_fees}}No of txs:{{no_txs}}
Block: {{blk_height}}Timestamp [UCT]: {{blk_timestamp}}Age [y:d:h:m:s]: {{delta_time}}Fee: {{tx_fee}}Tx size: {{tx_size}} kB
@@ -37,7 +30,7 @@
- + {{#outputs}} @@ -89,14 +82,29 @@ - - {{/mixins}}
out_pub_keyOutputs public keys amount
{{mix_timestamp}} {{mix_age}}
+ + + + + + + + + {{#ring_sigs}} + + + + {{/ring_sigs}} +
Ring signature
{{ring_sig}}
+ + + + + {{/inputs}}