From 881b87b0de9f6f342fa8d09e7fd5ba7c551e01d9 Mon Sep 17 00:00:00 2001 From: kenshi84 Date: Fri, 17 Feb 2017 11:47:35 +0900 Subject: [PATCH] show number of non-ringct inputs --- src/page.h | 5 ++++ src/templates/index2.html | 4 +-- src/templates/mempool.html | 4 +-- src/tools.cpp | 52 ++++++++++++++++++++++++++++++++++++++ src/tools.h | 6 +++++ 5 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/page.h b/src/page.h index af4cf8e..dafe98a 100644 --- a/src/page.h +++ b/src/page.h @@ -108,6 +108,7 @@ struct tx_details crypto::public_key pk; uint64_t xmr_inputs; uint64_t xmr_outputs; + uint64_t num_nonrct_inputs; uint64_t fee; uint64_t mixin_no; uint64_t size; @@ -171,6 +172,7 @@ struct tx_details {"sum_outputs_short" , xmr_amount_to_str(xmr_outputs, "{:0.3f}")}, {"no_inputs" , static_cast(input_key_imgs.size())}, {"no_outputs" , static_cast(output_pub_keys.size())}, + {"no_nonrct_inputs" , num_nonrct_inputs}, {"mixin" , mixin_str}, {"blk_height" , blk_height}, {"version" , std::to_string(version)}, @@ -513,6 +515,7 @@ public: // sum xmr in inputs and ouputs in the given tx pair sum_inputs = xmreg::sum_money_in_inputs(_tx_info.tx_json); pair sum_outputs = xmreg::sum_money_in_outputs(_tx_info.tx_json); + uint64_t num_nonrct_inputs = xmreg::count_nonrct_inputs(_tx_info.tx_json); sum_money_in_outputs(_tx_info.tx_json); @@ -560,6 +563,7 @@ public: {"xmr_outputs" , xmreg::xmr_amount_to_str(sum_outputs.first, "{:0.3f}")}, {"no_inputs" , sum_inputs.second}, {"no_outputs" , sum_outputs.second}, + {"no_nonrct_inputs", num_nonrct_inputs}, {"is_ringct" , is_ringct_str}, {"rct_type" , rct_type_str}, {"mixin" , fmt::format("{:d}", mixin_no)}, @@ -4282,6 +4286,7 @@ private: // sum xmr in inputs and ouputs in the given tx txd.xmr_inputs = sum_money_in_inputs(tx); txd.xmr_outputs = sum_money_in_outputs(tx); + txd.num_nonrct_inputs = count_nonrct_inputs(tx); // get mixin number txd.mixin_no = get_mixin_no(tx); diff --git a/src/templates/index2.html b/src/templates/index2.html index 121cea5..121385b 100644 --- a/src/templates/index2.html +++ b/src/templates/index2.html @@ -44,7 +44,7 @@ tx hash fees outputs - in/out + in(nonrct)/out rct/type mixin tx size [kB] @@ -57,7 +57,7 @@ {{hash}} {{tx_fee_short}} {{sum_outputs_short}} - {{no_inputs}}/{{no_outputs}} + {{no_inputs}}({{no_nonrct_inputs}})/{{no_outputs}} {{#is_ringct}}yes/{{rct_type}}{{/is_ringct}} {{^is_ringct}}no{{/is_ringct}} diff --git a/src/templates/mempool.html b/src/templates/mempool.html index 532df0c..ecf22d0 100644 --- a/src/templates/mempool.html +++ b/src/templates/mempool.html @@ -10,7 +10,7 @@ transaction hash fee outputs - in/out + in(nonrct)/out rct/type mixin tx size [kB] @@ -21,7 +21,7 @@ {{hash}} {{fee}} {{xmr_outputs}} - {{no_inputs}}/{{no_outputs}} + {{no_inputs}}({{no_nonrct_inputs}})/{{no_outputs}} {{is_ringct}}{{rct_type}} {{mixin}} {{txsize}} diff --git a/src/tools.cpp b/src/tools.cpp index c3d9348..13c6530 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -395,6 +395,58 @@ sum_money_in_inputs(const string& json_str) return sum_xmr; }; +uint64_t +count_nonrct_inputs(const transaction& tx) +{ + uint64_t num {0}; + + size_t input_no = tx.vin.size(); + + for (size_t i = 0; i < input_no; ++i) + { + + if(tx.vin[i].type() != typeid(cryptonote::txin_to_key)) + { + continue; + } + + // get tx input key + const cryptonote::txin_to_key& tx_in_to_key + = boost::get(tx.vin[i]); + + if (tx_in_to_key.amount != 0) + ++num; + } + + return num; +} + +uint64_t +count_nonrct_inputs(const string& json_str) +{ + uint64_t num {0}; + + json j; + try + { + j = json::parse( json_str); + } + catch (std::invalid_argument& e) + { + cerr << "count_nonrct_inputs: " << e.what() << endl; + return num; + } + + for (json& vin: j["vin"]) + { + uint64_t amount = vin["key"]["amount"].get(); + if (amount != 0) + ++num; + } + + return num; +}; + array sum_money_in_tx(const transaction& tx) { diff --git a/src/tools.h b/src/tools.h index e207313..cef73df 100644 --- a/src/tools.h +++ b/src/tools.h @@ -139,6 +139,12 @@ sum_money_in_inputs(const transaction& tx); pair sum_money_in_inputs(const string& json_str); +uint64_t +count_nonrct_inputs(const transaction& tx); + +uint64_t +count_nonrct_inputs(const string& json_str); + array sum_money_in_tx(const transaction& tx);