mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
decoding of ringct amount in our outputs added
This commit is contained in:
parent
32c75e1a46
commit
8740fd19a7
5 changed files with 138 additions and 13 deletions
|
@ -19,6 +19,9 @@
|
|||
#include "cryptonote_core/blockchain.h"
|
||||
#include "blockchain_db/lmdb/db_lmdb.h"
|
||||
|
||||
#include "ringct/rctTypes.h"
|
||||
#include "ringct/rctOps.h"
|
||||
#include "ringct/rctSigs.h"
|
||||
|
||||
#include "common/base58.h"
|
||||
|
||||
|
|
84
src/page.h
84
src/page.h
|
@ -1010,6 +1010,13 @@ namespace xmreg {
|
|||
|
||||
uint64_t inputs_xmr_sum {0};
|
||||
|
||||
// initialize with some large and some numbers
|
||||
uint64_t min_mix_timestamp = server_timestamp*2L;
|
||||
|
||||
uint64_t max_mix_timestamp {0};
|
||||
|
||||
vector<vector<uint64_t>> mixin_timestamp_groups;
|
||||
|
||||
// make timescale maps for mixins in input
|
||||
for (const txin_to_key& in_key: txd.input_key_imgs)
|
||||
{
|
||||
|
@ -1024,8 +1031,6 @@ namespace xmreg {
|
|||
absolute_offsets,
|
||||
outputs);
|
||||
|
||||
vector<uint64_t> mixin_timestamps;
|
||||
|
||||
inputs.push_back(mstch::map {
|
||||
{"in_key_img", REMOVE_HASH_BRAKETS(fmt::format("{:s}", in_key.k_image))},
|
||||
{"amount" , fmt::format("{:0.12f}", XMR_AMOUNT(in_key.amount))},
|
||||
|
@ -1036,6 +1041,7 @@ namespace xmreg {
|
|||
|
||||
inputs_xmr_sum += in_key.amount;
|
||||
|
||||
vector<uint64_t> mixin_timestamps;
|
||||
|
||||
// get reference to mixins array created above
|
||||
mstch::array& mixins = boost::get<mstch::array>(
|
||||
|
@ -1096,6 +1102,12 @@ namespace xmreg {
|
|||
{"mix_idx" , fmt::format("{:02d}", count)},
|
||||
});
|
||||
|
||||
if (blk.timestamp < min_mix_timestamp)
|
||||
min_mix_timestamp = blk.timestamp;
|
||||
|
||||
if (blk.timestamp > max_mix_timestamp)
|
||||
max_mix_timestamp = blk.timestamp;
|
||||
|
||||
// get mixin timestamp from its orginal block
|
||||
mixin_timestamps.push_back(blk.timestamp);
|
||||
|
||||
|
@ -1103,10 +1115,23 @@ namespace xmreg {
|
|||
|
||||
} // for (const uint64_t &i: absolute_offsets)
|
||||
|
||||
mixin_timestamp_groups.push_back(mixin_timestamps);
|
||||
|
||||
input_idx++;
|
||||
} // for (const txin_to_key& in_key: txd.input_key_imgs)
|
||||
|
||||
min_mix_timestamp -= 3600;
|
||||
max_mix_timestamp += 3600;
|
||||
|
||||
// make timescale maps for mixins in input with adjusted range
|
||||
for (auto& mixn_timestamps: mixin_timestamp_groups)
|
||||
{
|
||||
// get mixins in time scale for visual representation
|
||||
pair<string, double> mixin_times_scale = xmreg::timestamps_time_scale(
|
||||
mixin_timestamps,
|
||||
server_timestamp, 170);
|
||||
mixn_timestamps,
|
||||
max_mix_timestamp,
|
||||
170,
|
||||
min_mix_timestamp);
|
||||
|
||||
// save resolution of mixin timescales
|
||||
timescale_scale = mixin_times_scale.second;
|
||||
|
@ -1114,13 +1139,14 @@ namespace xmreg {
|
|||
// save the string timescales for later to show
|
||||
mixins_timescales.push_back(mstch::map {
|
||||
{"timescale", mixin_times_scale.first}});
|
||||
}
|
||||
|
||||
input_idx++;
|
||||
} // for (const txin_to_key& in_key: txd.input_key_imgs)
|
||||
|
||||
context["inputs_xmr_sum"] = fmt::format("{:0.12f}", XMR_AMOUNT(inputs_xmr_sum));
|
||||
context["server_time"] = server_time_str;
|
||||
context["inputs"] = inputs;
|
||||
context["min_mix_time"] = xmreg::timestamp_to_str(min_mix_timestamp);
|
||||
context["max_mix_time"] = xmreg::timestamp_to_str(max_mix_timestamp);
|
||||
context["timescales"] = mixins_timescales;
|
||||
context["timescales_scale"] = fmt::format("{:0.2f}",
|
||||
timescale_scale / 3600.0 / 24.0); // in days
|
||||
|
@ -1233,7 +1259,7 @@ namespace xmreg {
|
|||
// parse string representing given monero address
|
||||
cryptonote::account_public_address address;
|
||||
|
||||
if (!xmreg::parse_str_address(xmr_address_str, address, 0))
|
||||
if (!xmreg::parse_str_address(xmr_address_str, address, testnet))
|
||||
{
|
||||
cerr << "Cant parse string address: " << xmr_address_str << endl;
|
||||
return string("Cant parse xmr address: " + xmr_address_str);
|
||||
|
@ -1278,7 +1304,8 @@ namespace xmreg {
|
|||
|
||||
blk_timestamp = xmreg::timestamp_to_str(tx_recieve_timestamp);
|
||||
|
||||
age = get_age(server_timestamp, tx_recieve_timestamp,
|
||||
age = get_age(server_timestamp,
|
||||
tx_recieve_timestamp,
|
||||
FULL_AGE_FORMAT);
|
||||
}
|
||||
else
|
||||
|
@ -1371,6 +1398,11 @@ namespace xmreg {
|
|||
|
||||
uint64_t sum_xmr {0};
|
||||
|
||||
std::vector<uint64_t> money_transfered(tx.vout.size());
|
||||
|
||||
std::deque<rct::key> mask(tx.vout.size());
|
||||
|
||||
uint64_t i {0};
|
||||
|
||||
for (pair<txout_to_key, uint64_t>& outp: txd.output_pub_keys)
|
||||
{
|
||||
|
@ -1388,18 +1420,50 @@ namespace xmreg {
|
|||
// check if generated public key matches the current output's key
|
||||
bool mine_output = (outp.first.key == pubkey);
|
||||
|
||||
// if mine output has RingCT, i.e., tx version is 2
|
||||
if (mine_output && tx.version == 2)
|
||||
{
|
||||
|
||||
uint64_t rct_amount {0};
|
||||
|
||||
bool r;
|
||||
|
||||
r = decode_ringct(tx.rct_signatures,
|
||||
txd.pk,
|
||||
prv_view_key,
|
||||
i,
|
||||
tx.rct_signatures.ecdhInfo[i].mask,
|
||||
money_transfered[i]);
|
||||
|
||||
if (!r)
|
||||
{
|
||||
cerr << "Cant decode ringCT!" << endl;
|
||||
}
|
||||
|
||||
outp.second = money_transfered[i];
|
||||
|
||||
cout << "i, money_transfered[i]"
|
||||
<< i << ","
|
||||
<< money_transfered[i]
|
||||
<< endl;
|
||||
}
|
||||
|
||||
if (mine_output)
|
||||
{
|
||||
sum_xmr += outp.second;
|
||||
}
|
||||
|
||||
outputs.push_back(mstch::map {
|
||||
{"out_pub_key" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", outp.first.key))},
|
||||
{"amount" , fmt::format("{:0.12f}", XMR_AMOUNT(outp.second))},
|
||||
{"out_pub_key" , REMOVE_HASH_BRAKETS(
|
||||
fmt::format("{:s}",
|
||||
outp.first.key))},
|
||||
{"amount" , fmt::format("{:0.12f}",
|
||||
XMR_AMOUNT(outp.second))},
|
||||
{"mine_output" , mine_output},
|
||||
{"output_idx" , fmt::format("{:02d}", output_idx++)}
|
||||
});
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
cout << "outputs.size(): " << outputs.size() << endl;
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
|
||||
|
||||
{{#has_inputs}}
|
||||
<h3>Inputs' mixins time scale (from genesis till {{server_time}};
|
||||
<h3>Inputs' mixins time scale (from {{min_mix_time}} till {{max_mix_time}};
|
||||
resolution: {{timescales_scale}} days)</h3>
|
||||
<div class="center">
|
||||
<ul class="center">
|
||||
|
|
|
@ -619,6 +619,55 @@ namespace xmreg
|
|||
}
|
||||
|
||||
|
||||
bool
|
||||
decode_ringct(const rct::rctSig& rv,
|
||||
const crypto::public_key pub,
|
||||
const crypto::secret_key &sec,
|
||||
unsigned int i,
|
||||
rct::key & mask,
|
||||
uint64_t & amount)
|
||||
{
|
||||
crypto::key_derivation derivation;
|
||||
|
||||
bool r = crypto::generate_key_derivation(pub, sec, derivation);
|
||||
|
||||
if (!r)
|
||||
{
|
||||
cerr <<"Failed to generate key derivation to decode rct output " << i << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
crypto::secret_key scalar1;
|
||||
|
||||
crypto::derivation_to_scalar(derivation, i, scalar1);
|
||||
|
||||
try
|
||||
{
|
||||
switch (rv.type)
|
||||
{
|
||||
case rct::RCTTypeSimple:
|
||||
amount = rct::decodeRctSimple(rv,
|
||||
rct::sk2rct(scalar1),
|
||||
i,
|
||||
mask);
|
||||
case rct::RCTTypeFull:
|
||||
amount = rct::decodeRct(rv,
|
||||
rct::sk2rct(scalar1),
|
||||
i,
|
||||
mask);
|
||||
default:
|
||||
cerr << "Unsupported rct type: " << rv.type << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
cerr << "Failed to decode input " << i << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -215,6 +215,15 @@ namespace xmreg
|
|||
uint64_t time0 = 1397818193 /* timestamp of the second block */);
|
||||
|
||||
|
||||
bool
|
||||
decode_ringct(const rct::rctSig & rv,
|
||||
const crypto::public_key pub,
|
||||
const crypto::secret_key &sec,
|
||||
unsigned int i,
|
||||
rct::key & mask,
|
||||
uint64_t & amount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif //XMREG01_TOOLS_H
|
||||
|
|
Loading…
Reference in a new issue