From 12381f2e5a401c4d54dd607dc6d96380e9c5b295 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 13 Apr 2016 08:10:21 +0800 Subject: [PATCH] fix: ouputs incorrectly calculated --- src/page.h | 44 +++++++++++++++++++++++++++++++++++++- src/templates/index.html | 4 ++-- src/templates/mempool.html | 4 ++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/page.h b/src/page.h index 14c5337..15338a5 100644 --- a/src/page.h +++ b/src/page.h @@ -245,8 +245,10 @@ namespace xmreg { // fmt::print("Receive time: {:s}\n", // xmreg::timestamp_to_str(_tx_info.receive_time)); + uint64_t sum_inputs = sum_xmr_inputs(_tx_info.tx_json); uint64_t sum_outputs = sum_xmr_outputs(_tx_info.tx_json); + // get mixin number in each transaction vector mixin_numbers = get_mixin_no_in_txs(_tx_info.tx_json); @@ -255,6 +257,7 @@ namespace xmreg { {"timestamp" , xmreg::timestamp_to_str(_tx_info.receive_time)}, {"hash" , fmt::format("<{:s}>", _tx_info.id_hash)}, {"fee" , fmt::format("{:0.4f}", XMR_AMOUNT(_tx_info.fee))}, + {"xmr_inputs" , fmt::format("{:0.4f}", XMR_AMOUNT(sum_inputs))}, {"xmr_outputs" , fmt::format("{:0.4f}", XMR_AMOUNT(sum_outputs))}, {"mixin" , fmt::format("{:d}", mixin_numbers.at(0))} }); @@ -273,7 +276,7 @@ namespace xmreg { uint64_t sum_xmr_outputs(const string& json_str) { - uint64_t sum_xmr; + uint64_t sum_xmr {0}; rapidjson::Document json; @@ -304,6 +307,45 @@ namespace xmreg { return sum_xmr; } + uint64_t + sum_xmr_inputs(const string& json_str) + { + uint64_t sum_xmr {0}; + + rapidjson::Document json; + + if (json.Parse(json_str.c_str()).HasParseError()) + { + cerr << "Failed to parse JSON" << endl; + return 0; + } + + + // get information about inputs + const rapidjson::Value& vin = json["vin"]; + + if (vin.IsArray()) + { + // print("Input key images:\n"); + + for (rapidjson::SizeType i = 0; i < vin.Size(); ++i) + { + if (vin[i].HasMember("key")) + { + const rapidjson::Value& key_img = vin[i]["key"]; + + // print(" - {:s}, {:0.8f} xmr\n", + // key_img["k_image"].GetString(), + // XMR_AMOUNT(key_img["amount"].GetUint64())); + + sum_xmr += key_img["amount"].GetUint64(); + } + } + } + + return sum_xmr; + } + vector get_mixin_no_in_txs(const string& json_str) { diff --git a/src/templates/index.html b/src/templates/index.html index 9359e36..0b7d95e 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -25,7 +25,7 @@ block hash reward (w/ fees) no_of_txs - xmr_outputs + inputs/outputs mixin_range {{#blocks}} @@ -35,7 +35,7 @@ {{hash}} {{block_reward}} {{notx}} - {{xmr_outputs}} + {{xmr_inputs}}/{{xmr_outputs}} {{mixin_range}} {{/blocks}} diff --git a/src/templates/mempool.html b/src/templates/mempool.html index 5c6ac25..369ad6a 100644 --- a/src/templates/mempool.html +++ b/src/templates/mempool.html @@ -9,7 +9,7 @@ timestamp tx hash tx fee - xmr_outputs + inputs/outputs mixin {{#mempooltxs}} @@ -18,7 +18,7 @@ {{timestamp}} {{hash}} {{fee}} - {{xmr_outputs}} + {{xmr_inputs}}/{{xmr_outputs}} {{mixin}} {{/mempooltxs}}