adding timestamp to key images

This commit is contained in:
moneroexamples 2016-10-24 14:22:26 +08:00
parent f3411767cc
commit 566201c4bc
2 changed files with 80 additions and 11 deletions

View File

@ -2026,12 +2026,30 @@ namespace xmreg {
{"key_imgs" , mstch::array{}}
};
unique_ptr<xmreg::MyLMDB> mylmdb;
if (bf::is_directory(lmdb2_path))
{
mylmdb = make_unique<xmreg::MyLMDB>(lmdb2_path);
}
else
{
cout << "Custom lmdb database seem does not exist at: " << lmdb2_path << endl;
}
size_t no_key_images = (decoded_raw_data.size() - header_lenght) / record_lenght;
//vector<pair<crypto::key_image, crypto::signature>> signed_key_images;
mstch::array& key_imgs_ctx = boost::get<mstch::array>(context["key_imgs"]);
for (size_t n = 0; n < no_key_images; ++n)
{
const char* record_ptr = decoded_raw_data.data() + header_lenght + n * record_lenght;
@ -2042,12 +2060,53 @@ namespace xmreg {
crypto::signature signature
= *reinterpret_cast<const crypto::signature*>(record_ptr + key_img_size);
key_imgs_ctx.push_back(mstch::map{
vector<string> found_tx_hashes;
if (mylmdb)
{
mylmdb->search(epee::string_tools::pod_to_hex(key_image),
found_tx_hashes, "key_images");
}
mstch::map key_img_info {
{"key_no" , fmt::format("{:03d}", n)},
{"key_image" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", key_image))},
{"signature" , fmt::format("{:s}", signature)},
{"is_spent" , core_storage->have_tx_keyimg_as_spent(key_image)}
});
{"is_spent" , core_storage->have_tx_keyimg_as_spent(key_image)},
{"tx_hash_found" , !found_tx_hashes.empty()},
{"tx_hash" , string{}},
};
if (!found_tx_hashes.empty())
{
string tx_hash_str = found_tx_hashes.at(0);
key_img_info["tx_hash"] = tx_hash_str;
key_img_info["timestamp"] = "0";
transaction tx;
if (mcore->get_tx(tx_hash_str, tx))
{
crypto::hash tx_hash;
epee::string_tools::hex_to_pod(tx_hash_str, tx_hash);
// get timestamp of the tx's block
uint64_t blk_height = core_storage
->get_db().get_tx_block_height(tx_hash);
uint64_t blk_timestamp = core_storage
->get_db().get_block_timestamp(blk_height);
key_img_info["timestamp"] = xmreg::timestamp_to_str(blk_timestamp);
}
}
key_imgs_ctx.push_back(key_img_info);
//signed_key_images.push_back(make_pair(key_image, signature));
}

View File

@ -25,17 +25,27 @@
<div class="center">
<table class="center" style="width:80%">
<tr><td>Key no.</td><td>Key image</td><td>Is spent?</td></tr>
<tr><td>Key no.</td><td>Key image</td><td>Timestamp</td></td><td>Is spent?</td></tr>
{{#key_imgs}}
<tr>
<td>{{key_no}}</td>
<td>{{key_image}}</td>
{{#is_spent}}
<td><span style="color: #008009;font-weight: bold">{{is_spent}}</span></td>
{{/is_spent}}
{{^is_spent}}
<td>{{is_spent}}</td>
{{/is_spent}}
<td>
{{#tx_hash_found}}
<a href="/tx/{{tx_hash}}">{{key_image}}</a>
{{/tx_hash_found}}
{{^tx_hash_found}}
{{key_image}}
{{/tx_hash_found}}
</td>
<td>{{timestamp}}</td>
<td>
{{#is_spent}}
<span style="color: #008009;font-weight: bold">{{is_spent}}</span>
{{/is_spent}}
{{^is_spent}}
{{is_spent}}
{{/is_spent}}
</td>
</tr>
{{/key_imgs}}
</table>