possible spending calculation amended

master
moneroexamples 8 years ago
parent 1463563ba2
commit 7da52875a8

@ -1560,7 +1560,8 @@ public:
{"mine_output" , mine_output}, {"mine_output" , mine_output},
{"out_idx" , to_string(output_idx_in_tx)}, {"out_idx" , to_string(output_idx_in_tx)},
{"formed_output_pk", out_pub_key_str}, {"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) if (mine_output)
@ -1573,16 +1574,26 @@ public:
found_something = true; found_something = true;
show_key_images = true; show_key_images = true;
sum_mixin_xmr += amount;
}
} // for (const pair<txout_to_key, uint64_t>& mix_out: txd.output_pub_keys)
has_found_outputs = !found_outputs.empty(); // 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<txout_to_key, uint64_t>& mix_out: txd.output_pub_keys)
has_mixin_outputs = found_something; has_found_outputs = !found_outputs.empty();
has_mixin_outputs = found_something; has_mixin_outputs = found_something;
@ -1594,16 +1605,27 @@ public:
context.emplace("outputs", outputs); context.emplace("outputs", outputs);
context["found_our_outputs"] = (sum_xmr > 0); context["found_our_outputs"] = (sum_xmr > 0);
context["sum_xmr"] = xmreg::xmr_amount_to_str(sum_xmr); context["sum_xmr"] = xmreg::xmr_amount_to_str(sum_xmr);
context.emplace("inputs", inputs); context.emplace("inputs", inputs);
context["show_inputs"] = show_key_images; context["show_inputs"] = show_key_images;
context["inputs_no"] = inputs.size();
context["sum_mixin_xmr"] = xmreg::xmr_amount_to_str(sum_mixin_xmr); 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 // read my_outputs.html

@ -40,7 +40,7 @@
<div class="center"> <div class="center">
<table class="center" > <table class="center" >
<tr> <tr>
<td>Stealth address</td> <td>output public key</td>
<td>amount</td> <td>amount</td>
<td>output match?</td> <td>output match?</td>
</tr> </tr>
@ -76,7 +76,7 @@
{{#show_inputs}} {{#show_inputs}}
<h3>Inputs</h3> <h3>Inputs ({{inputs_no}})</h3>
<div class="center"> <div class="center">
{{#inputs}} {{#inputs}}
<h4>Key image: {{key_image}}, amount {{key_image_amount}}</h4> <h4>Key image: {{key_image}}, amount {{key_image_amount}}</h4>
@ -87,7 +87,7 @@
<table class="center"> <table class="center">
<tr> <tr>
<td style="text-align: center;"> <td style="text-align: center;">
Mixin {{mixin_pub_key}} might use our outputs Mixin {{mixin_pub_key}} might use your outputs
<br/> <br/>
from tx of public key: <a href="/tx/{{mix_tx_hash}}">{{mix_tx_pub_key}}</a> from tx of public key: <a href="/tx/{{mix_tx_hash}}">{{mix_tx_pub_key}}</a>
</td> </td>
@ -99,7 +99,7 @@
<tr> <tr>
<td>output public key</td> <td>output public key</td>
<td>amount</td> <td>amount</td>
<td>is ours?</td> <td>output match?</td>
</tr> </tr>
{{#found_outputs}} {{#found_outputs}}
<tr> <tr>
@ -107,7 +107,7 @@
<td>{{amount}}</td> <td>{{amount}}</td>
<td> <td>
{{#mine_output}} {{#mine_output}}
<span style="color: #008009;font-weight: bold">{{mine_output}}</span> <span style="color: #008009;font-weight: bold">{{mine_output}}</span>{{#out_in_match}}*{{/out_in_match}}
{{/mine_output}} {{/mine_output}}
{{^mine_output}} {{^mine_output}}
{{mine_output}} {{mine_output}}
@ -130,10 +130,14 @@
<h3> <h3>
Sum XMR from matched mixin's outputs: {{sum_mixin_xmr}} Sum XMR from matched mixin's outputs: {{sum_mixin_xmr}}
<br/> <br/>
<span style="font-size: 16px"> Possible spending is: {{possible_spending}}</span> <span style="font-size: 16px"> Possible spending is:
{{possible_spending}} (tx fee included)
</span>
<br/> <br/>
<span style="font-size: 14px">Note: without private spendkey, it is impossible to know whether this is your real spending. <span style="font-size: 14px">Note: without private spendkey,
So do not take this number seriously. It is just a guess.</span> it is impossible to know whether this is your real spending. <br/>
So do not take this number seriously.
It is probably totally wrong anyway.</span>
</h3> </h3>
{{/show_inputs}} {{/show_inputs}}

@ -245,14 +245,23 @@ parse(const std::string& str, string format="%Y-%m-%d %H:%M:%S");
static static
string 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 = "?"; string amount_str = "?";
if (xmr_amount > 0) if (!zero_to_question_mark)
{ {
amount_str = fmt::format(_format, XMR_AMOUNT(xmr_amount)); 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; return amount_str;
} }

Loading…
Cancel
Save