fix: ouputs incorrectly calculated

master
moneroexamples 9 years ago
parent fcada6849b
commit 12381f2e5a

@ -245,8 +245,10 @@ namespace xmreg {
// fmt::print("Receive time: {:s}\n", // fmt::print("Receive time: {:s}\n",
// xmreg::timestamp_to_str(_tx_info.receive_time)); // 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); uint64_t sum_outputs = sum_xmr_outputs(_tx_info.tx_json);
// get mixin number in each transaction // get mixin number in each transaction
vector<uint64_t> mixin_numbers = get_mixin_no_in_txs(_tx_info.tx_json); vector<uint64_t> 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)}, {"timestamp" , xmreg::timestamp_to_str(_tx_info.receive_time)},
{"hash" , fmt::format("<{:s}>", _tx_info.id_hash)}, {"hash" , fmt::format("<{:s}>", _tx_info.id_hash)},
{"fee" , fmt::format("{:0.4f}", XMR_AMOUNT(_tx_info.fee))}, {"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))}, {"xmr_outputs" , fmt::format("{:0.4f}", XMR_AMOUNT(sum_outputs))},
{"mixin" , fmt::format("{:d}", mixin_numbers.at(0))} {"mixin" , fmt::format("{:d}", mixin_numbers.at(0))}
}); });
@ -273,7 +276,7 @@ namespace xmreg {
uint64_t uint64_t
sum_xmr_outputs(const string& json_str) sum_xmr_outputs(const string& json_str)
{ {
uint64_t sum_xmr; uint64_t sum_xmr {0};
rapidjson::Document json; rapidjson::Document json;
@ -304,6 +307,45 @@ namespace xmreg {
return sum_xmr; 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<uint64_t> vector<uint64_t>
get_mixin_no_in_txs(const string& json_str) get_mixin_no_in_txs(const string& json_str)
{ {

@ -25,7 +25,7 @@
<td>block hash</td> <td>block hash</td>
<td>reward (w/ fees)</td> <td>reward (w/ fees)</td>
<td>no_of_txs</td> <td>no_of_txs</td>
<td>xmr_outputs</td> <td>inputs/outputs</td>
<td>mixin_range</td> <td>mixin_range</td>
</tr> </tr>
{{#blocks}} {{#blocks}}
@ -35,7 +35,7 @@
<td>{{hash}}</td> <td>{{hash}}</td>
<td>{{block_reward}}</td> <td>{{block_reward}}</td>
<td>{{notx}}</td> <td>{{notx}}</td>
<td>{{xmr_outputs}}</td> <td>{{xmr_inputs}}/{{xmr_outputs}}</td>
<td>{{mixin_range}}</td> <td>{{mixin_range}}</td>
</tr> </tr>
{{/blocks}} {{/blocks}}

@ -9,7 +9,7 @@
<td>timestamp</td> <td>timestamp</td>
<td>tx hash</td> <td>tx hash</td>
<td>tx fee</td> <td>tx fee</td>
<td>xmr_outputs</td> <td>inputs/outputs</td>
<td>mixin</td> <td>mixin</td>
</tr> </tr>
{{#mempooltxs}} {{#mempooltxs}}
@ -18,7 +18,7 @@
<td>{{timestamp}}</td> <td>{{timestamp}}</td>
<td>{{hash}}</td> <td>{{hash}}</td>
<td>{{fee}}</td> <td>{{fee}}</td>
<td>{{xmr_outputs}}</td> <td>{{xmr_inputs}}/{{xmr_outputs}}</td>
<td>{{mixin}}</td> <td>{{mixin}}</td>
</tr> </tr>
{{/mempooltxs}} {{/mempooltxs}}

Loading…
Cancel
Save