From 7da52875a86f5b65057d0c749df3bca3535aefd3 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 19 Jan 2017 04:22:01 +0000 Subject: [PATCH] possible spending calculation amended --- src/page.h | 40 +++++++++++++++++++++++++++-------- src/templates/my_outputs.html | 20 +++++++++++------- src/tools.h | 13 ++++++++++-- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/page.h b/src/page.h index c510728..9008600 100644 --- a/src/page.h +++ b/src/page.h @@ -1560,7 +1560,8 @@ public: {"mine_output" , mine_output}, {"out_idx" , to_string(output_idx_in_tx)}, {"formed_output_pk", out_pub_key_str}, - {"amount" , xmreg::xmr_amount_to_str(amount)}, + {"out_in_match" , (amount == in_key.amount)}, + {"amount" , xmreg::xmr_amount_to_str(amount)} }); if (mine_output) @@ -1573,17 +1574,27 @@ public: found_something = true; show_key_images = true; - sum_mixin_xmr += amount; + + + // for regular txs, just concentrated on outputs + // which have same amount as the key image. + // for ringct its not possible to know for sure amount + // in key image without spend key, so we just use all + if (mixin_tx.version < 2 && amount == in_key.amount) + { + sum_mixin_xmr += amount; + } + else if (mixin_tx.version == 2) // ringct + { + sum_mixin_xmr += amount; + } + } } // for (const pair& mix_out: txd.output_pub_keys) has_found_outputs = !found_outputs.empty(); - - - has_mixin_outputs = found_something; - has_mixin_outputs = found_something; } // for (const cryptonote::output_data_t& output_data: mixin_outputs) @@ -1594,16 +1605,27 @@ public: context.emplace("outputs", outputs); + context["found_our_outputs"] = (sum_xmr > 0); context["sum_xmr"] = xmreg::xmr_amount_to_str(sum_xmr); context.emplace("inputs", inputs); + context["show_inputs"] = show_key_images; + context["inputs_no"] = inputs.size(); context["sum_mixin_xmr"] = xmreg::xmr_amount_to_str(sum_mixin_xmr); - // (outcoming - incoming) - fee - uint64_t possible_spending = (sum_mixin_xmr - sum_xmr) - txd.fee; - context["possible_spending"] = xmreg::xmr_amount_to_str(possible_spending); + + + uint64_t possible_spending {0}; + + if (sum_mixin_xmr > (sum_xmr + txd.fee)) + { + // (outcoming - incoming) - fee + possible_spending = (sum_mixin_xmr - sum_xmr) - txd.fee; + } + context["possible_spending"] = xmreg::xmr_amount_to_str( + possible_spending, "{:0.12f}", false); // read my_outputs.html diff --git a/src/templates/my_outputs.html b/src/templates/my_outputs.html index 5cfc5d8..48ec321 100644 --- a/src/templates/my_outputs.html +++ b/src/templates/my_outputs.html @@ -40,7 +40,7 @@
- + @@ -76,7 +76,7 @@ {{#show_inputs}} -

Inputs

+

Inputs ({{inputs_no}})

{{#inputs}}

Key image: {{key_image}}, amount {{key_image_amount}}

@@ -87,7 +87,7 @@
Stealth addressoutput public key amount output match?
@@ -99,7 +99,7 @@ - + {{#found_outputs}} @@ -107,7 +107,7 @@
- Mixin {{mixin_pub_key}} might use our outputs + Mixin {{mixin_pub_key}} might use your outputs
from tx of public key: {{mix_tx_pub_key}}
output public key amountis ours?output match?
{{amount}} {{#mine_output}} - {{mine_output}} + {{mine_output}}{{#out_in_match}}*{{/out_in_match}} {{/mine_output}} {{^mine_output}} {{mine_output}} @@ -130,10 +130,14 @@

Sum XMR from matched mixin's outputs: {{sum_mixin_xmr}}
- Possible spending is: {{possible_spending}} + Possible spending is: + {{possible_spending}} (tx fee included) +
- Note: without private spendkey, it is impossible to know whether this is your real spending. - So do not take this number seriously. It is just a guess. + Note: without private spendkey, + it is impossible to know whether this is your real spending.
+ So do not take this number seriously. + It is probably totally wrong anyway.

{{/show_inputs}} diff --git a/src/tools.h b/src/tools.h index a8d499b..e207313 100644 --- a/src/tools.h +++ b/src/tools.h @@ -245,14 +245,23 @@ parse(const std::string& str, string format="%Y-%m-%d %H:%M:%S"); static string -xmr_amount_to_str(const uint64_t& xmr_amount, string _format="{:0.12f}") +xmr_amount_to_str(const uint64_t& xmr_amount, + string _format="{:0.12f}", + bool zero_to_question_mark=true) { string amount_str = "?"; - if (xmr_amount > 0) + if (!zero_to_question_mark) { amount_str = fmt::format(_format, XMR_AMOUNT(xmr_amount)); } + else + { + if (xmr_amount > 0 && zero_to_question_mark == true) + { + amount_str = fmt::format(_format, XMR_AMOUNT(xmr_amount)); + } + } return amount_str; }