2016-04-08 06:54:04 +00:00
|
|
|
//
|
|
|
|
// Created by mwo on 8/04/16.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef CROWXMR_PAGE_H
|
|
|
|
#define CROWXMR_PAGE_H
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-08 09:32:12 +00:00
|
|
|
#include "mstch/mstch.hpp"
|
|
|
|
|
2016-11-23 01:28:10 +00:00
|
|
|
#include "version.h"
|
2016-04-08 09:32:12 +00:00
|
|
|
|
2016-04-08 06:54:04 +00:00
|
|
|
#include "monero_headers.h"
|
2016-04-08 09:32:12 +00:00
|
|
|
|
|
|
|
#include "MicroCore.h"
|
2016-04-08 06:54:04 +00:00
|
|
|
#include "tools.h"
|
2016-04-12 22:20:14 +00:00
|
|
|
#include "rpccalls.h"
|
2017-04-28 07:24:19 +00:00
|
|
|
|
2017-05-16 05:29:24 +00:00
|
|
|
#include "CurrentBlockchainStatus.h"
|
2017-05-27 23:53:36 +00:00
|
|
|
#include "MempoolStatus.h"
|
2017-05-16 05:29:24 +00:00
|
|
|
|
2016-08-20 10:08:11 +00:00
|
|
|
#include "../ext/crow/http_request.h"
|
2016-04-08 06:54:04 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
#include "../ext/vpetrigocaches/cache.hpp"
|
|
|
|
#include "../ext/vpetrigocaches/lru_cache_policy.hpp"
|
|
|
|
#include "../ext/vpetrigocaches/fifo_cache_policy.hpp"
|
2017-04-28 07:24:19 +00:00
|
|
|
|
2016-04-12 03:31:26 +00:00
|
|
|
#include <algorithm>
|
2016-04-18 01:40:57 +00:00
|
|
|
#include <limits>
|
2016-04-18 05:57:38 +00:00
|
|
|
#include <ctime>
|
2016-04-12 03:31:26 +00:00
|
|
|
|
2016-11-29 06:07:16 +00:00
|
|
|
#define TMPL_DIR "./templates"
|
|
|
|
#define TMPL_PARIALS_DIR TMPL_DIR "/partials"
|
|
|
|
#define TMPL_CSS_STYLES TMPL_DIR "/css/style.css"
|
|
|
|
#define TMPL_INDEX TMPL_DIR "/index.html"
|
|
|
|
#define TMPL_INDEX2 TMPL_DIR "/index2.html"
|
|
|
|
#define TMPL_MEMPOOL TMPL_DIR "/mempool.html"
|
2017-05-25 05:21:17 +00:00
|
|
|
#define TMPL_MEMPOOL_ERROR TMPL_DIR "/mempool_error.html"
|
2016-11-29 06:07:16 +00:00
|
|
|
#define TMPL_HEADER TMPL_DIR "/header.html"
|
|
|
|
#define TMPL_FOOTER TMPL_DIR "/footer.html"
|
|
|
|
#define TMPL_BLOCK TMPL_DIR "/block.html"
|
|
|
|
#define TMPL_TX TMPL_DIR "/tx.html"
|
|
|
|
#define TMPL_ADDRESS TMPL_DIR "/address.html"
|
|
|
|
#define TMPL_MY_OUTPUTS TMPL_DIR "/my_outputs.html"
|
|
|
|
#define TMPL_SEARCH_RESULTS TMPL_DIR "/search_results.html"
|
|
|
|
#define TMPL_MY_RAWTX TMPL_DIR "/rawtx.html"
|
|
|
|
#define TMPL_MY_CHECKRAWTX TMPL_DIR "/checkrawtx.html"
|
|
|
|
#define TMPL_MY_PUSHRAWTX TMPL_DIR "/pushrawtx.html"
|
|
|
|
#define TMPL_MY_RAWKEYIMGS TMPL_DIR "/rawkeyimgs.html"
|
|
|
|
#define TMPL_MY_CHECKRAWKEYIMGS TMPL_DIR "/checkrawkeyimgs.html"
|
|
|
|
#define TMPL_MY_RAWOUTPUTKEYS TMPL_DIR "/rawoutputkeys.html"
|
|
|
|
#define TMPL_MY_CHECKRAWOUTPUTKEYS TMPL_DIR "/checkrawoutputkeys.html"
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2016-04-08 06:54:04 +00:00
|
|
|
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
// basic info about tx to be stored in cashe.
|
|
|
|
// we need to store block_no and timestamp,
|
|
|
|
// as this time and number of confirmation needs
|
|
|
|
// to be updated between requests. Just cant
|
|
|
|
// get it from cash, as it will be old very soon
|
|
|
|
struct tx_info_cache
|
|
|
|
{
|
|
|
|
uint64_t block_no;
|
|
|
|
uint64_t timestamp;
|
|
|
|
mstch::map tx_map;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
// custom key for use in cache.
|
|
|
|
// cache uses unordeded map for keys
|
|
|
|
struct key
|
|
|
|
{
|
|
|
|
crypto::hash tx_hash;
|
|
|
|
bool detailed;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
bool operator==(const key &other) const
|
|
|
|
{
|
|
|
|
return (tx_hash == other.tx_hash && detailed == other.detailed);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
// indect overload of hash for tx_info_cache::key
|
|
|
|
namespace std
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 05:45:30 +00:00
|
|
|
template<>
|
|
|
|
struct hash<tx_info_cache::key>
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 05:45:30 +00:00
|
|
|
size_t operator()(const tx_info_cache::key& k) const
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 05:45:30 +00:00
|
|
|
size_t const h1 ( std::hash<crypto::hash>{}(k.tx_hash) );
|
|
|
|
size_t const h2 ( std::hash<bool>{}(k.detailed) );
|
|
|
|
return h1 ^ (h2 << 1);
|
|
|
|
};
|
|
|
|
};
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-04-24 01:11:08 +00:00
|
|
|
|
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
namespace xmreg
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
using namespace cryptonote;
|
|
|
|
using namespace crypto;
|
|
|
|
using namespace std;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
using epee::string_tools::pod_to_hex;
|
|
|
|
using epee::string_tools::hex_to_pod;
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2016-11-23 22:11:23 +00:00
|
|
|
/**
|
|
|
|
* @brief The tx_details struct
|
|
|
|
*
|
|
|
|
* Basic information about tx
|
|
|
|
*
|
|
|
|
*/
|
2017-04-28 07:24:19 +00:00
|
|
|
struct tx_details
|
2016-04-17 01:44:24 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash hash;
|
|
|
|
crypto::hash prefix_hash;
|
|
|
|
crypto::public_key pk;
|
|
|
|
uint64_t xmr_inputs;
|
|
|
|
uint64_t xmr_outputs;
|
|
|
|
uint64_t num_nonrct_inputs;
|
|
|
|
uint64_t fee;
|
|
|
|
uint64_t mixin_no;
|
|
|
|
uint64_t size;
|
|
|
|
uint64_t blk_height;
|
|
|
|
size_t version;
|
|
|
|
uint64_t unlock_time;
|
|
|
|
uint64_t no_confirmations;
|
|
|
|
vector<uint8_t> extra;
|
2016-12-26 04:21:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash payment_id = null_hash; // normal
|
|
|
|
crypto::hash8 payment_id8 = null_hash8; // encrypted
|
2016-04-25 03:54:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
std::vector<std::vector<crypto::signature>> signatures;
|
2016-09-07 02:00:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// key images of inputs
|
|
|
|
vector<txin_to_key> input_key_imgs;
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// public keys and xmr amount of outputs
|
|
|
|
vector<pair<txout_to_key, uint64_t>> output_pub_keys;
|
2016-04-19 07:13:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map
|
|
|
|
get_mstch_map() const
|
2016-04-17 01:44:24 +00:00
|
|
|
{
|
2016-04-25 03:54:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string mixin_str {"N/A"};
|
|
|
|
string fee_str {"N/A"};
|
|
|
|
string fee_short_str {"N/A"};
|
2016-05-01 03:31:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const double& xmr_amount = XMR_AMOUNT(fee);
|
|
|
|
|
|
|
|
if (!input_key_imgs.empty())
|
|
|
|
{
|
2017-05-18 22:58:30 +00:00
|
|
|
mixin_str = std::to_string(mixin_no);
|
2017-04-28 07:24:19 +00:00
|
|
|
fee_str = fmt::format("{:0.6f}", xmr_amount);
|
|
|
|
fee_short_str = fmt::format("{:0.3f}", xmr_amount);
|
|
|
|
}
|
2016-05-01 03:31:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const double& tx_size = static_cast<double>(size)/1024.0;
|
|
|
|
|
|
|
|
mstch::map txd_map {
|
|
|
|
{"hash" , pod_to_hex(hash)},
|
|
|
|
{"prefix_hash" , pod_to_hex(prefix_hash)},
|
|
|
|
{"pub_key" , pod_to_hex(pk)},
|
|
|
|
{"tx_fee" , fee_str},
|
|
|
|
{"tx_fee_short" , fee_short_str},
|
|
|
|
{"sum_inputs" , xmr_amount_to_str(xmr_inputs , "{:0.6f}")},
|
|
|
|
{"sum_outputs" , xmr_amount_to_str(xmr_outputs, "{:0.6f}")},
|
|
|
|
{"sum_inputs_short" , xmr_amount_to_str(xmr_inputs , "{:0.3f}")},
|
|
|
|
{"sum_outputs_short" , xmr_amount_to_str(xmr_outputs, "{:0.3f}")},
|
|
|
|
{"no_inputs" , static_cast<uint64_t>(input_key_imgs.size())},
|
|
|
|
{"no_outputs" , static_cast<uint64_t>(output_pub_keys.size())},
|
|
|
|
{"no_nonrct_inputs" , num_nonrct_inputs},
|
|
|
|
{"mixin" , mixin_str},
|
|
|
|
{"blk_height" , blk_height},
|
|
|
|
{"version" , version},
|
|
|
|
{"has_payment_id" , payment_id != null_hash},
|
|
|
|
{"has_payment_id8" , payment_id8 != null_hash8},
|
|
|
|
{"payment_id" , pod_to_hex(payment_id)},
|
|
|
|
{"confirmations" , no_confirmations},
|
|
|
|
{"extra" , get_extra_str()},
|
|
|
|
{"payment_id8" , pod_to_hex(payment_id8)},
|
|
|
|
{"unlock_time" , unlock_time},
|
|
|
|
{"tx_size" , fmt::format("{:0.4f}", tx_size)},
|
|
|
|
{"tx_size_short" , fmt::format("{:0.2f}", tx_size)}
|
|
|
|
};
|
2016-04-30 12:16:44 +00:00
|
|
|
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return txd_map;
|
|
|
|
}
|
2016-04-23 06:14:22 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
get_extra_str() const
|
|
|
|
{
|
|
|
|
return epee::string_tools::buff_to_hex_nodelimer(
|
|
|
|
string{reinterpret_cast<const char*>(extra.data()), extra.size()});
|
|
|
|
}
|
2016-04-30 12:16:44 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array
|
|
|
|
get_ring_sig_for_input(uint64_t in_i)
|
|
|
|
{
|
|
|
|
mstch::array ring_sigs {};
|
2016-04-30 12:16:44 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (in_i >= signatures.size())
|
|
|
|
{
|
|
|
|
return ring_sigs;
|
|
|
|
}
|
2016-04-30 12:16:44 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const crypto::signature &sig: signatures.at(in_i))
|
|
|
|
{
|
|
|
|
ring_sigs.push_back(mstch::map{
|
|
|
|
{"ring_sig", print_signature(sig)}
|
|
|
|
});
|
|
|
|
}
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return ring_sigs;
|
|
|
|
}
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
print_signature(const signature& sig)
|
|
|
|
{
|
|
|
|
stringstream ss;
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
ss << epee::string_tools::pod_to_hex(sig.c)
|
|
|
|
<< epee::string_tools::pod_to_hex(sig.r);
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
};
|
2016-04-23 06:14:22 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
class page
|
|
|
|
{
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
static const bool FULL_AGE_FORMAT {true};
|
2016-04-08 06:54:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
MicroCore* mcore;
|
|
|
|
Blockchain* core_storage;
|
|
|
|
rpccalls rpc;
|
2016-04-22 02:10:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
atomic<time_t> server_timestamp;
|
2016-04-08 09:32:12 +00:00
|
|
|
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool testnet;
|
2016-11-24 01:59:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool enable_pusher;
|
2017-02-28 07:10:50 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool enable_key_image_checker;
|
|
|
|
bool enable_output_key_checker;
|
|
|
|
bool enable_mixins_details;
|
|
|
|
bool enable_mempool_cache;
|
|
|
|
bool enable_tx_cache;
|
|
|
|
bool enable_block_cache;
|
|
|
|
bool show_cache_times;
|
2017-02-28 07:10:50 +00:00
|
|
|
|
2017-02-28 00:02:06 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool enable_autorefresh_option;
|
2016-09-06 11:19:10 +00:00
|
|
|
|
2017-01-20 02:25:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t no_of_mempool_tx_of_frontpage;
|
|
|
|
uint64_t no_blocks_on_index;
|
2017-05-25 05:21:17 +00:00
|
|
|
uint64_t network_info_timeout;
|
2017-05-28 01:10:42 +00:00
|
|
|
uint64_t mempool_info_timeout;
|
2017-03-03 00:02:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string testnet_url;
|
|
|
|
string mainnet_url;
|
2017-01-20 02:25:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// instead of constatnly reading template files
|
|
|
|
// from hard drive for each request, we can read
|
|
|
|
// them only once, when the explorer starts into this map
|
|
|
|
// this will improve performance of the explorer and reduce
|
|
|
|
// read operation in OS
|
|
|
|
map<string, string> template_file;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// alias for easy class typing
|
|
|
|
template <typename Key, typename Value>
|
|
|
|
using lru_cache_t = caches::fixed_sized_cache<Key, Value, caches::LRUCachePolicy<Key>>;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// alias for easy class typing
|
|
|
|
template <typename Key, typename Value>
|
|
|
|
using fifo_cache_t = caches::fixed_sized_cache<Key, Value, caches::FIFOCachePolicy<Key>>;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// this struct is used to keep info about mempool
|
|
|
|
// txs in FIFO cache. Should speed up processing
|
|
|
|
// mempool txs for each request
|
|
|
|
struct mempool_tx_info
|
|
|
|
{
|
|
|
|
uint64_t sum_inputs;
|
|
|
|
uint64_t sum_outputs;
|
|
|
|
uint64_t no_inputs;
|
|
|
|
uint64_t no_outputs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t num_nonrct_inputs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t mixin_no;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string hash;
|
|
|
|
string fee;
|
|
|
|
string xmr_inputs_str;
|
|
|
|
string xmr_outputs_str;
|
|
|
|
string timestamp;
|
|
|
|
|
|
|
|
string txsize;
|
|
|
|
};
|
|
|
|
|
|
|
|
// cache of txs in mempool, so that we dont
|
|
|
|
// parse their json for each request
|
|
|
|
fifo_cache_t<string, mempool_tx_info> mempool_tx_json_cache;
|
|
|
|
|
2017-05-28 00:55:58 +00:00
|
|
|
// to keep network_info in cache
|
|
|
|
// and to show previous info in case current querry for
|
|
|
|
// the current info timesout.
|
|
|
|
struct network_info
|
|
|
|
{
|
|
|
|
uint64_t difficulty;
|
|
|
|
uint64_t hash_rate;
|
|
|
|
uint64_t fee_per_kb;
|
|
|
|
uint64_t alt_blocks_no;
|
|
|
|
uint64_t tx_pool_size;
|
|
|
|
uint64_t info_timestamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
atomic<network_info> previous_network_info;
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// cache of txs_map of txs in blocks. this is useful for
|
|
|
|
// index2 page, so that we dont parse txs in each block
|
|
|
|
// for each request.
|
|
|
|
fifo_cache_t<uint64_t, vector<pair<crypto::hash, mstch::node>>> block_tx_cache;
|
|
|
|
|
|
|
|
lru_cache_t<tx_info_cache::key, tx_info_cache> tx_context_cache;
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
page(MicroCore* _mcore,
|
|
|
|
Blockchain* _core_storage,
|
|
|
|
string _deamon_url,
|
|
|
|
bool _testnet,
|
|
|
|
bool _enable_pusher,
|
|
|
|
bool _enable_key_image_checker,
|
|
|
|
bool _enable_output_key_checker,
|
|
|
|
bool _enable_autorefresh_option,
|
|
|
|
bool _enable_mixins_details,
|
|
|
|
bool _enable_mempool_cache,
|
|
|
|
bool _enable_tx_cache,
|
|
|
|
bool _enable_block_cache,
|
|
|
|
bool _show_cache_times,
|
|
|
|
uint64_t _no_blocks_on_index,
|
2017-05-25 05:21:17 +00:00
|
|
|
uint64_t _network_info_timeout,
|
2017-05-28 01:10:42 +00:00
|
|
|
uint64_t _mempool_info_timeout,
|
2017-04-28 07:24:19 +00:00
|
|
|
string _testnet_url,
|
|
|
|
string _mainnet_url)
|
|
|
|
: mcore {_mcore},
|
|
|
|
core_storage {_core_storage},
|
|
|
|
rpc {_deamon_url},
|
|
|
|
server_timestamp {std::time(nullptr)},
|
|
|
|
testnet {_testnet},
|
|
|
|
enable_pusher {_enable_pusher},
|
|
|
|
enable_key_image_checker {_enable_key_image_checker},
|
|
|
|
enable_output_key_checker {_enable_output_key_checker},
|
|
|
|
enable_autorefresh_option {_enable_autorefresh_option},
|
|
|
|
enable_mixins_details {_enable_mixins_details},
|
|
|
|
enable_mempool_cache {_enable_mempool_cache},
|
|
|
|
enable_tx_cache {_enable_tx_cache},
|
|
|
|
enable_block_cache {_enable_block_cache},
|
|
|
|
show_cache_times {_show_cache_times},
|
|
|
|
no_blocks_on_index {_no_blocks_on_index},
|
2017-05-25 05:21:17 +00:00
|
|
|
network_info_timeout {_network_info_timeout},
|
2017-05-28 01:10:42 +00:00
|
|
|
mempool_info_timeout {_mempool_info_timeout},
|
2017-04-28 07:24:19 +00:00
|
|
|
testnet_url {_testnet_url},
|
|
|
|
mainnet_url {_mainnet_url},
|
|
|
|
mempool_tx_json_cache(1000),
|
|
|
|
block_tx_cache(200),
|
|
|
|
tx_context_cache(1000)
|
|
|
|
{
|
|
|
|
|
|
|
|
no_of_mempool_tx_of_frontpage = 25;
|
|
|
|
|
2017-05-28 00:55:58 +00:00
|
|
|
// initialized stored network info atomic
|
|
|
|
previous_network_info = network_info {0, 0, 0, 0, 0, 0};
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// read template files for all the pages
|
|
|
|
// into template_file map
|
|
|
|
|
|
|
|
template_file["css_styles"] = xmreg::read(TMPL_CSS_STYLES);
|
|
|
|
template_file["header"] = xmreg::read(TMPL_HEADER);
|
|
|
|
template_file["footer"] = get_footer();
|
|
|
|
template_file["index2"] = get_full_page(xmreg::read(TMPL_INDEX2));
|
|
|
|
template_file["mempool"] = xmreg::read(TMPL_MEMPOOL);
|
2017-05-25 05:21:17 +00:00
|
|
|
template_file["mempool_error"] = xmreg::read(TMPL_MEMPOOL_ERROR);
|
2017-04-28 07:24:19 +00:00
|
|
|
template_file["mempool_full"] = get_full_page(template_file["mempool"]);
|
|
|
|
template_file["block"] = get_full_page(xmreg::read(TMPL_BLOCK));
|
|
|
|
template_file["tx"] = get_full_page(xmreg::read(TMPL_TX));
|
|
|
|
template_file["my_outputs"] = get_full_page(xmreg::read(TMPL_MY_OUTPUTS));
|
|
|
|
template_file["rawtx"] = get_full_page(xmreg::read(TMPL_MY_RAWTX));
|
|
|
|
template_file["checkrawtx"] = get_full_page(xmreg::read(TMPL_MY_CHECKRAWTX));
|
|
|
|
template_file["pushrawtx"] = get_full_page(xmreg::read(TMPL_MY_PUSHRAWTX));
|
|
|
|
template_file["rawkeyimgs"] = get_full_page(xmreg::read(TMPL_MY_RAWKEYIMGS));
|
|
|
|
template_file["rawoutputkeys"] = get_full_page(xmreg::read(TMPL_MY_RAWOUTPUTKEYS));
|
|
|
|
template_file["checkrawkeyimgs"] = get_full_page(xmreg::read(TMPL_MY_CHECKRAWKEYIMGS));
|
|
|
|
template_file["checkoutputkeys"] = get_full_page(xmreg::read(TMPL_MY_CHECKRAWOUTPUTKEYS));
|
|
|
|
template_file["address"] = get_full_page(xmreg::read(TMPL_ADDRESS));
|
|
|
|
template_file["search_results"] = get_full_page(xmreg::read(TMPL_SEARCH_RESULTS));
|
|
|
|
template_file["tx_details"] = xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_details.html");
|
|
|
|
template_file["tx_table_header"] = xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_table_header.html");
|
|
|
|
template_file["tx_table_row"] = xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_table_row.html");
|
|
|
|
}
|
2017-03-03 01:03:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
/**
|
2016-11-23 22:11:23 +00:00
|
|
|
* @brief show recent transactions and mempool
|
|
|
|
* @param page_no block page to show
|
|
|
|
* @param refresh_page enable autorefresh
|
|
|
|
* @return rendered index page
|
|
|
|
*/
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
index2(uint64_t page_no = 0, bool refresh_page = false)
|
|
|
|
{
|
2017-05-15 06:19:57 +00:00
|
|
|
|
|
|
|
// we get network info, such as current hash rate
|
|
|
|
// but since this makes a rpc call to deamon, we make it as an async
|
|
|
|
// call. this way we dont have to wait with execution of the rest of the
|
|
|
|
// index2 method, until deamon gives as the required result.
|
|
|
|
std::future<json> network_info_ftr = std::async(std::launch::async, [&]
|
|
|
|
{
|
|
|
|
json j_info;
|
|
|
|
|
|
|
|
if (!get_monero_network_info(j_info))
|
|
|
|
{
|
|
|
|
return json{};
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t fee_estimated {0};
|
|
|
|
|
|
|
|
// get dynamic fee estimate from last 10 blocks
|
|
|
|
if (!get_dynamic_per_kb_fee_estimate(fee_estimated))
|
|
|
|
{
|
|
|
|
return json{};
|
|
|
|
}
|
|
|
|
|
|
|
|
j_info["fee_per_kb"] = fee_estimated;
|
|
|
|
|
|
|
|
return j_info;
|
|
|
|
});
|
|
|
|
|
2017-05-25 06:00:16 +00:00
|
|
|
|
|
|
|
// get mempool for the front page also using async future
|
|
|
|
std::future<string> mempool_ftr = std::async(std::launch::async, [&]
|
|
|
|
{
|
|
|
|
// get memory pool rendered template
|
|
|
|
return mempool(false, no_of_mempool_tx_of_frontpage);
|
|
|
|
});
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//get current server timestamp
|
|
|
|
server_timestamp = std::time(nullptr);
|
2016-04-08 06:54:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t local_copy_server_timestamp = server_timestamp;
|
2016-04-08 06:54:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// number of last blocks to show
|
|
|
|
uint64_t no_of_last_blocks {no_blocks_on_index + 1};
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get the current blockchain height. Just to check
|
|
|
|
uint64_t height = core_storage->get_current_blockchain_height();
|
|
|
|
|
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"testnet_url" , testnet_url},
|
|
|
|
{"mainnet_url" , mainnet_url},
|
|
|
|
{"refresh" , refresh_page},
|
|
|
|
{"height" , height},
|
|
|
|
{"server_timestamp" , xmreg::timestamp_to_str_gm(local_copy_server_timestamp)},
|
|
|
|
{"age_format" , string("[h:m:d]")},
|
|
|
|
{"page_no" , page_no},
|
|
|
|
{"total_page_no" , (height / no_of_last_blocks)},
|
|
|
|
{"is_page_zero" , !bool(page_no)},
|
|
|
|
{"no_of_last_blocks" , no_of_last_blocks},
|
|
|
|
{"next_page" , (page_no + 1)},
|
|
|
|
{"prev_page" , (page_no > 0 ? page_no - 1 : 0)},
|
|
|
|
{"enable_pusher" , enable_pusher},
|
|
|
|
{"enable_key_image_checker" , enable_key_image_checker},
|
|
|
|
{"enable_output_key_checker", enable_output_key_checker},
|
|
|
|
{"enable_autorefresh_option", enable_autorefresh_option},
|
|
|
|
{"show_cache_times" , show_cache_times}
|
|
|
|
};
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-05-18 23:26:26 +00:00
|
|
|
// std::list<block> atl_blks;
|
|
|
|
//
|
|
|
|
// if (core_storage->get_alternative_blocks(atl_blks))
|
|
|
|
// {
|
|
|
|
// for (const block& alt_blk: atl_blks)
|
|
|
|
// {
|
|
|
|
// //cout << "alt_blk: " << get_block_height(alt_blk) << endl;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("txs", mstch::array()); // will keep tx to show
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get reference to txs mstch map to be field below
|
|
|
|
mstch::array& txs = boost::get<mstch::array>(context["txs"]);
|
2017-01-18 00:37:15 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// calculate starting and ending block numbers to show
|
|
|
|
int64_t start_height = height - no_of_last_blocks * (page_no + 1);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if start height is not below range
|
|
|
|
start_height = start_height < 0 ? 0 : start_height;
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
int64_t end_height = start_height + no_of_last_blocks - 1;
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
vector<double> blk_sizes;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// measure time of cache based execution, and non-cached execution
|
|
|
|
double duration_cached {0.0};
|
|
|
|
double duration_non_cached {0.0};
|
|
|
|
uint64_t cache_hits {0};
|
|
|
|
uint64_t cache_misses {0};
|
2017-01-18 00:37:15 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// loop index
|
|
|
|
int64_t i = end_height;
|
2017-01-18 00:37:15 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// iterate over last no_of_last_blocks of blocks
|
|
|
|
while (i >= start_height)
|
|
|
|
{
|
|
|
|
// get block at the given height i
|
|
|
|
block blk;
|
2017-01-18 00:37:15 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_block_by_height(i, blk))
|
|
|
|
{
|
|
|
|
cerr << "Cant get block: " << i << endl;
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block's hash
|
|
|
|
crypto::hash blk_hash = core_storage->get_block_id_by_height(i);
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block size in kB
|
|
|
|
double blk_size = static_cast<double>(core_storage->get_db().get_block_size(i))/1024.0;
|
2016-05-01 03:31:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string blk_size_str = fmt::format("{:0.2f}", blk_size);
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
blk_sizes.push_back(blk_size);
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove "<" and ">" from the hash string
|
|
|
|
string blk_hash_str = pod_to_hex(blk_hash);
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block age
|
|
|
|
pair<string, string> age = get_age(local_copy_server_timestamp, blk.timestamp);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["age_format"] = age.second;
|
|
|
|
|
|
|
|
|
|
|
|
if (enable_block_cache && block_tx_cache.Contains(i))
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// get txs info in the ith block from
|
|
|
|
// our cache
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// start measure time here
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const vector<pair<crypto::hash, mstch::node>>& txd_pairs
|
|
|
|
= block_tx_cache.Get(i);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// copy tx maps from txs_maps_tmp into txs array,
|
|
|
|
// that will go to templates
|
|
|
|
for (const pair<crypto::hash, mstch::node>& txd_pair: txd_pairs)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// we need to check if the given transaction is still
|
|
|
|
// in the same block as when it was cached. it is possible
|
|
|
|
// the block got orphaned, and this tx is in mempool
|
|
|
|
// or different block, and what we have in cache
|
|
|
|
// is thus wrong
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// but we do this only for first top blocks. no sense
|
|
|
|
// doing it for all blocks
|
|
|
|
|
|
|
|
bool is_tx_still_in_block_as_expected {true};
|
|
|
|
|
|
|
|
if (i + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE > height)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
const crypto::hash& tx_hash = txd_pair.first;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (core_storage->have_tx(tx_hash))
|
|
|
|
{
|
|
|
|
try
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_height_in_blockchain =
|
|
|
|
core_storage->get_db().get_tx_block_height(tx_hash);
|
|
|
|
|
|
|
|
// check if height of the given tx that we have in cache,
|
|
|
|
// denoted by i, is same as what is acctually stored
|
|
|
|
// in blockchain
|
|
|
|
if (tx_height_in_blockchain == i)
|
|
|
|
{
|
|
|
|
is_tx_still_in_block_as_expected = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if no tx in the given block, just stop
|
|
|
|
// any futher search. no need. we are going
|
|
|
|
// to ditch the cache, in a monent
|
|
|
|
is_tx_still_in_block_as_expected = false;
|
|
|
|
break;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
catch (const TX_DNE& e)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "Tx from cache" << pod_to_hex(tx_hash)
|
|
|
|
<< " is no longer in the blockchain "
|
|
|
|
<< endl;
|
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
is_tx_still_in_block_as_expected = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
else
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
|
|
|
is_tx_still_in_block_as_expected = false;
|
|
|
|
break;
|
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
} // if (i + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE > height)
|
|
|
|
|
|
|
|
|
|
|
|
if (!is_tx_still_in_block_as_expected)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// if some tx in cache is not in blockchain
|
|
|
|
// where it should be, its probably better to
|
|
|
|
// ditch entire cache, as redo it below.
|
|
|
|
|
|
|
|
block_tx_cache.Clear();
|
|
|
|
txs.clear();
|
|
|
|
i = end_height;
|
|
|
|
continue; // reado the main loop
|
2017-04-28 05:45:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if we got to here, it means that everything went fine
|
|
|
|
// and no unexpeced things happended.
|
|
|
|
mstch::map txd_map = boost::get<mstch::map>(txd_pair.second);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// now we need to update age of txs from cashe
|
|
|
|
if (!boost::get<string>(txd_map["age"]).empty())
|
|
|
|
{
|
|
|
|
txd_map["age"] = age.first;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txs.push_back(txd_map);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (const pair<crypto::hash, mstch::map>& txd_pair: txd_pairs)
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>
|
|
|
|
(std::chrono::steady_clock::now() - start);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// cout << "block_tx_json_cache from cache" << endl;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
duration_cached += duration.count();
|
2016-05-01 02:13:44 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++cache_hits;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// this is new block. not in cashe.
|
|
|
|
// need to process its txs and add to cache
|
2016-05-01 02:13:44 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// start measure time here
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get all transactions in the block found
|
|
|
|
// initialize the first list with transaction for solving
|
|
|
|
// the block i.e. coinbase.
|
|
|
|
list<cryptonote::transaction> blk_txs {blk.miner_tx};
|
|
|
|
list<crypto::hash> missed_txs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!core_storage->get_transactions(blk.tx_hashes, blk_txs, missed_txs))
|
|
|
|
{
|
|
|
|
cerr << "Cant get transactions in block: " << i << endl;
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_i {0};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// this vector will go into block_tx cache
|
|
|
|
// tx_hash , txd_map
|
|
|
|
vector<pair<crypto::hash, mstch::node>> txd_pairs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for(auto it = blk_txs.begin(); it != blk_txs.end(); ++it)
|
|
|
|
{
|
|
|
|
const cryptonote::transaction& tx = *it;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const tx_details& txd = get_tx_details(tx, false, i, height);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map txd_map = txd.get_mstch_map();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//add age to the txd mstch map
|
|
|
|
txd_map.insert({"height" , i});
|
|
|
|
txd_map.insert({"blk_hash" , blk_hash_str});
|
|
|
|
txd_map.insert({"age" , age.first});
|
|
|
|
txd_map.insert({"is_ringct" , (tx.version > 1)});
|
|
|
|
txd_map.insert({"rct_type" , tx.rct_signatures.type});
|
|
|
|
txd_map.insert({"blk_size" , blk_size_str});
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// do not show block info for other than first tx in a block
|
|
|
|
if (tx_i > 0)
|
|
|
|
{
|
|
|
|
txd_map["height"] = string("");
|
|
|
|
txd_map["age"] = string("");
|
|
|
|
txd_map["blk_size"] = string("");
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txd_pairs.emplace_back(txd.hash, txd_map);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++tx_i;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for(list<cryptonote::transaction>::reverse_iterator rit = blk_txs.rbegin();
|
|
|
|
|
|
|
|
// copy tx maps from txs_maps_tmp into txs array,
|
|
|
|
// that will go to templates
|
|
|
|
for (const pair<crypto::hash, mstch::node>& txd_pair: txd_pairs)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
txs.push_back(boost::get<mstch::map>(txd_pair.second));
|
2017-04-28 05:45:30 +00:00
|
|
|
}
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>
|
|
|
|
(std::chrono::steady_clock::now() - start);
|
|
|
|
|
|
|
|
duration_non_cached += duration.count();
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++cache_misses;
|
2017-01-11 03:43:20 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (enable_block_cache)
|
|
|
|
{
|
|
|
|
// save in block_tx cache
|
|
|
|
block_tx_cache.Put(i, txd_pairs);
|
|
|
|
}
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // else if (block_tx_json_cache.Contains(i))
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
--i; // go to next block number
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // while (i <= end_height)
|
2016-05-01 03:31:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// calculate median size of the blocks shown
|
|
|
|
double blk_size_median = xmreg::calc_median(blk_sizes.begin(), blk_sizes.end());
|
2016-05-01 04:17:19 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["blk_size_median"] = fmt::format("{:0.2f}", blk_size_median);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// save computational times for disply in the frontend
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["construction_time_cached"] = fmt::format(
|
|
|
|
"{:0.4f}", duration_cached/1.0e6);
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["construction_time_non_cached"] = fmt::format(
|
|
|
|
"{:0.4f}", duration_non_cached/1.0e6);
|
2017-01-18 00:37:15 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["construction_time_total"] = fmt::format(
|
|
|
|
"{:0.4f}", (duration_non_cached+duration_cached)/1.0e6);
|
2017-01-18 00:37:15 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["cache_hits"] = cache_hits;
|
|
|
|
context["cache_misses"] = cache_misses;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-15 06:19:57 +00:00
|
|
|
// now time to check if we have our networkinfo from network_info future
|
2017-05-25 06:00:16 +00:00
|
|
|
// wait a bit (300 millisecond max) if not, just in case, but we dont wait more.
|
2017-05-15 06:19:57 +00:00
|
|
|
// if its not ready by now, forget about it.
|
|
|
|
|
|
|
|
std::future_status ftr_status = network_info_ftr.wait_for(
|
2017-05-28 01:10:42 +00:00
|
|
|
std::chrono::milliseconds(network_info_timeout));
|
2017-05-28 00:55:58 +00:00
|
|
|
|
|
|
|
network_info current_network_info {0, 0, 0, 0, 0, 0};
|
|
|
|
|
|
|
|
bool is_network_info_current {false};
|
2017-05-15 06:19:57 +00:00
|
|
|
|
|
|
|
if (ftr_status == std::future_status::ready)
|
|
|
|
{
|
|
|
|
json j_network_info = network_info_ftr.get();
|
|
|
|
|
|
|
|
if (!j_network_info.empty())
|
|
|
|
{
|
2017-05-28 00:55:58 +00:00
|
|
|
current_network_info.difficulty = j_network_info["difficulty"];
|
|
|
|
current_network_info.hash_rate = j_network_info["hash_rate"];
|
|
|
|
current_network_info.fee_per_kb = j_network_info["fee_per_kb"];
|
|
|
|
current_network_info.tx_pool_size = j_network_info["tx_pool_size"];
|
|
|
|
current_network_info.alt_blocks_no = j_network_info["alt_blocks_count"];
|
|
|
|
current_network_info.info_timestamp = local_copy_server_timestamp;
|
2017-05-15 06:19:57 +00:00
|
|
|
|
2017-05-28 00:55:58 +00:00
|
|
|
previous_network_info = current_network_info;
|
2017-05-15 06:19:57 +00:00
|
|
|
|
2017-05-28 00:55:58 +00:00
|
|
|
is_network_info_current = true;
|
2017-05-15 06:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-28 00:55:58 +00:00
|
|
|
current_network_info = previous_network_info;
|
|
|
|
cerr << "network_info future not ready yet, use the previous_network_info." << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// perapre network info mstch::map for the front page
|
|
|
|
|
|
|
|
string hash_rate;
|
|
|
|
|
|
|
|
if (testnet)
|
|
|
|
{
|
|
|
|
hash_rate = std::to_string(current_network_info.hash_rate) + " H/s";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash_rate = fmt::format("{:0.3f} MH/s", current_network_info.hash_rate/1.0e6);
|
2017-05-25 06:00:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-28 00:55:58 +00:00
|
|
|
pair<string, string> network_info_age = get_age(local_copy_server_timestamp,
|
|
|
|
current_network_info.info_timestamp);
|
|
|
|
|
|
|
|
// if network info is younger than 2 minute, assume its current. No sense
|
|
|
|
// showing that it is not current if its less then block time.
|
|
|
|
|
|
|
|
if (local_copy_server_timestamp - current_network_info.info_timestamp < 120)
|
|
|
|
{
|
|
|
|
is_network_info_current = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
context["network_info"] = mstch::map {
|
2017-05-31 23:49:23 +00:00
|
|
|
{"difficulty" , current_network_info.difficulty},
|
|
|
|
{"hash_rate" , hash_rate},
|
|
|
|
{"fee_per_kb" , print_money(current_network_info.fee_per_kb)},
|
|
|
|
{"alt_blocks_no" , current_network_info.alt_blocks_no},
|
|
|
|
{"tx_pool_size" , current_network_info.tx_pool_size},
|
|
|
|
{"is_current_info" , is_network_info_current},
|
|
|
|
{"is_pool_size_zero" , (current_network_info.tx_pool_size == 0)},
|
|
|
|
{"age" , network_info_age.first},
|
|
|
|
{"age_format" , network_info_age.second},
|
2017-05-28 00:55:58 +00:00
|
|
|
};
|
|
|
|
|
2017-05-25 06:00:16 +00:00
|
|
|
string mempool_html {"Cant get mempool_pool"};
|
|
|
|
|
|
|
|
// get mempool data for the front page, if ready. If not, then just skip.
|
|
|
|
std::future_status mempool_ftr_status = mempool_ftr.wait_for(
|
2017-05-28 01:10:42 +00:00
|
|
|
std::chrono::milliseconds(mempool_info_timeout));
|
2017-05-25 05:21:17 +00:00
|
|
|
|
2017-05-25 06:00:16 +00:00
|
|
|
if (mempool_ftr_status == std::future_status::ready)
|
|
|
|
{
|
|
|
|
mempool_html = mempool_ftr.get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "mempool future not ready yet, skipping." << endl;
|
2017-05-25 23:55:08 +00:00
|
|
|
mempool_html = mstch::render(template_file["mempool_error"], context);
|
2017-05-15 06:19:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 05:29:24 +00:00
|
|
|
if (CurrentBlockchainStatus::is_thread_running())
|
|
|
|
{
|
2017-05-17 05:30:36 +00:00
|
|
|
CurrentBlockchainStatus::Emission current_values
|
|
|
|
= CurrentBlockchainStatus::get_emission();
|
2017-05-16 05:29:24 +00:00
|
|
|
|
2017-05-25 06:00:16 +00:00
|
|
|
string emission_blk_no = std::to_string(current_values.blk_no - 1);
|
2017-05-17 05:30:36 +00:00
|
|
|
string emission_coinbase = xmr_amount_to_str(current_values.coinbase, "{:0.3f}");
|
|
|
|
string emission_fee = xmr_amount_to_str(current_values.fee, "{:0.3f}");
|
2017-05-16 05:29:24 +00:00
|
|
|
|
|
|
|
context["emission"] = mstch::map {
|
|
|
|
{"blk_no" , emission_blk_no},
|
2017-05-17 05:30:36 +00:00
|
|
|
{"amount" , emission_coinbase},
|
|
|
|
{"fee_amount", emission_fee}
|
2017-05-16 05:29:24 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "emission thread not running, skipping." << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get memory pool rendered template
|
2017-05-25 05:21:17 +00:00
|
|
|
//string mempool_html = mempool(false, no_of_mempool_tx_of_frontpage);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// append mempool_html to the index context map
|
|
|
|
context["mempool_info"] = mempool_html;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["index2"], context);
|
|
|
|
}
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
/**
|
2017-05-25 05:21:17 +00:00
|
|
|
* Render mempool data
|
|
|
|
*/
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
mempool(bool add_header_and_footer = false, uint64_t no_of_mempool_tx = 25)
|
|
|
|
{
|
2017-06-02 02:14:42 +00:00
|
|
|
std::vector<MempoolStatus::mempool_tx> mempool_txs
|
|
|
|
= MempoolStatus::get_mempool_txs();
|
2016-05-01 03:31:57 +00:00
|
|
|
|
2017-06-02 02:34:27 +00:00
|
|
|
// size of mempool in bytes
|
|
|
|
uint64_t mempool_size_bytes = MempoolStatus::mempool_size;
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalise page tempate map with basic info about mempool
|
|
|
|
mstch::map context {
|
|
|
|
{"mempool_size" , mempool_txs.size()},
|
|
|
|
{"show_cache_times" , show_cache_times}
|
|
|
|
};
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("mempooltxs" , mstch::array());
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get reference to blocks template map to be field below
|
|
|
|
mstch::array& txs = boost::get<mstch::array>(context["mempooltxs"]);
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// process only up to no_of_mempool_tx txs of mempool.
|
|
|
|
// this is useful from the front page were we show by default
|
|
|
|
// only 25 mempool txs. this way, we just parse 25 txs, rather
|
|
|
|
// than potentially hundrets just to ditch most of them later.
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (add_header_and_footer == false)
|
|
|
|
{
|
|
|
|
// this is to show limited number of txs in mempool
|
|
|
|
// for example, in the front page
|
|
|
|
no_of_mempool_tx = mempool_txs.size() > no_of_mempool_tx
|
|
|
|
? no_of_mempool_tx
|
|
|
|
: mempool_txs.size();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if we are adding footers and headers, means we
|
|
|
|
// disply mempool on its own page, thus show all mempoool txs.
|
|
|
|
no_of_mempool_tx = mempool_txs.size();
|
|
|
|
}
|
2016-05-01 02:02:37 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
double duration_cached {0.0};
|
|
|
|
double duration_non_cached {0.0};
|
|
|
|
uint64_t cache_hits {0};
|
|
|
|
uint64_t cache_misses {0};
|
2017-01-17 00:40:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t local_copy_server_timestamp = server_timestamp;
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for each transaction in the memory pool
|
|
|
|
for (size_t i = 0; i < no_of_mempool_tx; ++i)
|
|
|
|
{
|
|
|
|
// get transaction info of the tx in the mempool
|
2017-06-02 02:14:42 +00:00
|
|
|
const MempoolStatus::mempool_tx& mempool_tx = mempool_txs.at(i);
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// calculate difference between tx in mempool and server timestamps
|
|
|
|
array<size_t, 5> delta_time = timestamp_difference(
|
|
|
|
local_copy_server_timestamp,
|
2017-06-02 02:14:42 +00:00
|
|
|
mempool_tx.info.receive_time);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// use only hours, so if we have days, add
|
|
|
|
// it to hours
|
|
|
|
uint64_t delta_hours {delta_time[1]*24 + delta_time[2]};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
|
|
|
|
delta_hours,
|
|
|
|
delta_time[3], delta_time[4]);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if more than 99 hourse, change formating
|
|
|
|
// for the template
|
|
|
|
if (delta_hours > 99)
|
|
|
|
{
|
|
|
|
age_str = fmt::format("{:03d}:{:02d}:{:02d}",
|
|
|
|
delta_hours,
|
|
|
|
delta_time[3], delta_time[4]);
|
|
|
|
}
|
2017-01-17 00:40:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// sum xmr in inputs and ouputs in the given tx
|
|
|
|
uint64_t sum_inputs {0};
|
|
|
|
uint64_t sum_outputs {0};
|
|
|
|
uint64_t no_inputs {0};
|
|
|
|
uint64_t no_outputs {0};
|
|
|
|
uint64_t num_nonrct_inputs {0};
|
|
|
|
uint64_t mixin_no {0};
|
2017-04-06 01:08:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string hash_str;
|
|
|
|
string fee_str;
|
|
|
|
string xmr_inputs_str;
|
|
|
|
string xmr_outputs_str;
|
|
|
|
string timestamp_str;
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string txsize;
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// get the above incormation from json of that tx
|
2016-05-01 02:02:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json j_tx;
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
if (enable_mempool_cache
|
|
|
|
&& mempool_tx_json_cache.Contains(mempool_tx.info.id_hash))
|
2017-04-28 07:24:19 +00:00
|
|
|
{
|
|
|
|
// maybe its already in cashe, so we can save some time
|
|
|
|
// by using this, rather then making parsing json
|
|
|
|
// and calculating it from json
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// start measure time here
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
const mempool_tx_info& cached_tx_info
|
|
|
|
= mempool_tx_json_cache.Get(mempool_tx.info.id_hash);
|
2017-01-11 01:43:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
sum_inputs = cached_tx_info.sum_inputs;
|
|
|
|
sum_outputs = cached_tx_info.sum_outputs;
|
|
|
|
no_inputs = cached_tx_info.no_inputs;
|
|
|
|
no_outputs = cached_tx_info.no_outputs;
|
|
|
|
num_nonrct_inputs = cached_tx_info.num_nonrct_inputs;
|
|
|
|
mixin_no = cached_tx_info.mixin_no;
|
|
|
|
hash_str = cached_tx_info.hash;
|
|
|
|
fee_str = cached_tx_info.fee;
|
|
|
|
xmr_inputs_str = cached_tx_info.xmr_inputs_str;
|
|
|
|
xmr_outputs_str = cached_tx_info.xmr_outputs_str;
|
|
|
|
timestamp_str = cached_tx_info.timestamp;
|
|
|
|
txsize = cached_tx_info.txsize;
|
2017-03-03 09:09:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>
|
|
|
|
(std::chrono::steady_clock::now() - start);
|
2017-01-11 03:43:20 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// cout << "block_tx_json_cache from cache" << endl;
|
2017-03-03 09:09:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
duration_cached += duration.count();
|
2017-03-03 09:09:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++cache_hits;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "getting json from cash for: " << _tx_info.id_hash << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// its not in cash. Its new tx in mempool, so
|
|
|
|
// construct this data and save into cash for later use
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// start measure time here
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
j_tx = json::parse(mempool_tx.info.tx_json);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// sum xmr in inputs and ouputs in the given tx
|
|
|
|
const array<uint64_t, 6>& sum_data = summary_of_in_out_rct(j_tx);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
sum_outputs = sum_data[0];
|
|
|
|
sum_inputs = sum_data[1];
|
|
|
|
no_outputs = sum_data[2];
|
|
|
|
no_inputs = sum_data[3];
|
|
|
|
mixin_no = sum_data[4];
|
|
|
|
num_nonrct_inputs = sum_data[5];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
hash_str = mempool_tx.info.id_hash;
|
|
|
|
fee_str = xmreg::xmr_amount_to_str(mempool_tx.info.fee, "{:0.3f}");
|
2017-04-28 07:24:19 +00:00
|
|
|
xmr_inputs_str = xmreg::xmr_amount_to_str(sum_inputs , "{:0.3f}");
|
|
|
|
xmr_outputs_str = xmreg::xmr_amount_to_str(sum_outputs, "{:0.3f}");
|
2017-06-02 02:14:42 +00:00
|
|
|
timestamp_str = xmreg::timestamp_to_str_gm(mempool_tx.info.receive_time);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txsize = fmt::format("{:0.2f}",
|
2017-06-02 02:14:42 +00:00
|
|
|
static_cast<double>(mempool_tx.info.blob_size)/1024.0);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>
|
|
|
|
(std::chrono::steady_clock::now() - start);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// cout << "block_tx_json_cache from cache" << endl;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
duration_non_cached += duration.count();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++cache_misses;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (enable_mempool_cache)
|
|
|
|
{
|
|
|
|
// save in mempool cache
|
|
|
|
mempool_tx_json_cache.Put(
|
2017-06-02 02:14:42 +00:00
|
|
|
mempool_tx.info.id_hash,
|
2017-04-28 07:24:19 +00:00
|
|
|
mempool_tx_info {
|
|
|
|
sum_inputs, sum_outputs,
|
|
|
|
no_inputs, no_outputs,
|
|
|
|
num_nonrct_inputs, mixin_no,
|
|
|
|
hash_str, fee_str,
|
|
|
|
xmr_inputs_str, xmr_outputs_str,
|
|
|
|
timestamp_str, txsize
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} // else if (mempool_tx_json_cache.Contains(_tx_info.id_hash))
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
|
|
|
catch (std::invalid_argument& e)
|
|
|
|
{
|
|
|
|
cerr << " j_tx = json::parse(_tx_info.tx_json): " << e.what() << endl;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// set output page template map
|
|
|
|
txs.push_back(mstch::map {
|
2017-06-02 02:14:42 +00:00
|
|
|
{"timestamp_no" , mempool_tx.info.receive_time},
|
2017-04-28 07:24:19 +00:00
|
|
|
{"timestamp" , timestamp_str},
|
|
|
|
{"age" , age_str},
|
|
|
|
{"hash" , hash_str},
|
|
|
|
{"fee" , fee_str},
|
|
|
|
{"xmr_inputs" , xmr_inputs_str},
|
|
|
|
{"xmr_outputs" , xmr_outputs_str},
|
|
|
|
{"no_inputs" , no_inputs},
|
|
|
|
{"no_outputs" , no_outputs},
|
|
|
|
{"no_nonrct_inputs", num_nonrct_inputs},
|
2017-05-18 22:58:30 +00:00
|
|
|
{"mixin" , mixin_no+1},
|
2017-04-28 07:24:19 +00:00
|
|
|
{"txsize" , txsize}
|
|
|
|
});
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-01-11 01:43:23 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
|
2017-01-11 01:43:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.insert({"mempool_size_kB",
|
|
|
|
fmt::format("{:0.2f}",
|
|
|
|
static_cast<double>(mempool_size_bytes)/1024.0)});
|
2017-01-17 00:40:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["construction_time_cached"] = fmt::format(
|
|
|
|
"{:0.4f}", duration_cached/1.0e6);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["construction_time_non_cached"] = fmt::format(
|
|
|
|
"{:0.4f}", duration_non_cached/1.0e6);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["construction_time_total"] = fmt::format(
|
|
|
|
"{:0.4f}", (duration_non_cached+duration_cached)/1.0e6);
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["cache_hits"] = cache_hits;
|
|
|
|
context["cache_misses"] = cache_misses;
|
2017-01-17 00:40:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (add_header_and_footer)
|
|
|
|
{
|
|
|
|
// this is when mempool is on its own page, /mempool
|
|
|
|
add_css_style(context);
|
2017-01-12 02:55:38 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["partial_mempool_shown"] = false;
|
2017-01-12 02:55:38 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["mempool_full"], context);
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// this is for partial disply on front page.
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["mempool_fits_on_front_page"] = (mempool_txs.size() <= no_of_mempool_tx);
|
|
|
|
context["no_of_mempool_tx_of_frontpage"] = no_of_mempool_tx;
|
2017-01-20 01:43:09 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["partial_mempool_shown"] = true;
|
2017-01-20 02:25:42 +00:00
|
|
|
|
2017-01-20 01:43:09 +00:00
|
|
|
// render the page
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(template_file["mempool"], context);
|
2017-01-20 01:43:09 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 02:25:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_block(uint64_t _blk_height)
|
|
|
|
{
|
2017-01-20 02:25:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block at the given height i
|
|
|
|
block blk;
|
2017-01-20 01:43:09 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "_blk_height: " << _blk_height << endl;
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t current_blockchain_height
|
|
|
|
= core_storage->get_current_blockchain_height();
|
2016-04-15 02:59:41 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (_blk_height > current_blockchain_height)
|
|
|
|
{
|
|
|
|
cerr << "Cant get block: " << _blk_height
|
|
|
|
<< " since its higher than current blockchain height"
|
|
|
|
<< " i.e., " << current_blockchain_height
|
|
|
|
<< endl;
|
|
|
|
return fmt::format("Cant get block {:d} since its higher than current blockchain height!",
|
|
|
|
_blk_height);
|
|
|
|
}
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2016-09-22 05:06:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_block_by_height(_blk_height, blk))
|
|
|
|
{
|
|
|
|
cerr << "Cant get block: " << _blk_height << endl;
|
|
|
|
return fmt::format("Cant get block {:d}!", _blk_height);
|
|
|
|
}
|
2016-04-12 22:36:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block's hash
|
|
|
|
crypto::hash blk_hash = core_storage->get_block_id_by_height(_blk_height);
|
2016-04-12 22:20:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash prev_hash = blk.prev_id;
|
|
|
|
crypto::hash next_hash = null_hash;
|
2016-09-22 05:06:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (_blk_height + 1 <= current_blockchain_height)
|
|
|
|
{
|
|
|
|
next_hash = core_storage->get_block_id_by_height(_blk_height + 1);
|
|
|
|
}
|
2016-09-22 05:06:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool have_next_hash = (next_hash == null_hash ? false : true);
|
|
|
|
bool have_prev_hash = (prev_hash == null_hash ? false : true);
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove "<" and ">" from the hash string
|
|
|
|
string prev_hash_str = pod_to_hex(prev_hash);
|
|
|
|
string next_hash_str = pod_to_hex(next_hash);
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove "<" and ">" from the hash string
|
|
|
|
string blk_hash_str = pod_to_hex(blk_hash);
|
2016-11-28 05:08:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block timestamp in user friendly format
|
|
|
|
string blk_timestamp = xmreg::timestamp_to_str_gm(blk.timestamp);
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get age of the block relative to the server time
|
|
|
|
pair<string, string> age = get_age(server_timestamp, blk.timestamp);
|
2016-04-12 07:15:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get time from the last block
|
|
|
|
string delta_time {"N/A"};
|
2016-10-12 00:55:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (have_prev_hash)
|
|
|
|
{
|
|
|
|
block prev_blk = core_storage->get_db().get_block(prev_hash);
|
2016-04-15 23:07:47 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
pair<string, string> delta_diff = get_age(blk.timestamp, prev_blk.timestamp);
|
2016-10-12 00:55:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
delta_time = delta_diff.first;
|
|
|
|
}
|
2016-11-21 21:24:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block size in bytes
|
|
|
|
uint64_t blk_size = core_storage->get_db().get_block_size(_blk_height);
|
|
|
|
|
|
|
|
// miner reward tx
|
|
|
|
transaction coinbase_tx = blk.miner_tx;
|
|
|
|
|
|
|
|
// transcation in the block
|
|
|
|
vector<crypto::hash> tx_hashes = blk.tx_hashes;
|
|
|
|
|
|
|
|
bool have_txs = !blk.tx_hashes.empty();
|
|
|
|
|
|
|
|
// sum of all transactions in the block
|
|
|
|
uint64_t sum_fees = 0;
|
|
|
|
|
|
|
|
// get tx details for the coinbase tx, i.e., miners reward
|
|
|
|
tx_details txd_coinbase = get_tx_details(blk.miner_tx, true,
|
|
|
|
_blk_height, current_blockchain_height);
|
|
|
|
|
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"blk_hash" , blk_hash_str},
|
|
|
|
{"blk_height" , _blk_height},
|
|
|
|
{"blk_timestamp" , blk_timestamp},
|
|
|
|
{"blk_timestamp_epoch" , blk.timestamp},
|
|
|
|
{"prev_hash" , prev_hash_str},
|
|
|
|
{"next_hash" , next_hash_str},
|
|
|
|
{"have_next_hash" , have_next_hash},
|
|
|
|
{"have_prev_hash" , have_prev_hash},
|
|
|
|
{"have_txs" , have_txs},
|
|
|
|
{"no_txs" , std::to_string(
|
|
|
|
blk.tx_hashes.size())},
|
|
|
|
{"blk_age" , age.first},
|
|
|
|
{"delta_time" , delta_time},
|
|
|
|
{"blk_nonce" , blk.nonce},
|
|
|
|
{"age_format" , age.second},
|
|
|
|
{"major_ver" , std::to_string(blk.major_version)},
|
|
|
|
{"minor_ver" , std::to_string(blk.minor_version)},
|
|
|
|
{"blk_size" , fmt::format("{:0.4f}",
|
|
|
|
static_cast<double>(blk_size) / 1024.0)},
|
|
|
|
};
|
|
|
|
context.emplace("coinbase_txs", mstch::array{{txd_coinbase.get_mstch_map()}});
|
|
|
|
context.emplace("blk_txs" , mstch::array());
|
2016-10-12 00:55:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// .push_back(txd_coinbase.get_mstch_map()
|
2016-10-12 00:55:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// boost::get<mstch::array>(context["blk_txs"]).push_back(txd_coinbase.get_mstch_map());
|
2016-04-15 23:07:47 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// now process nomral transactions
|
|
|
|
// get reference to blocks template map to be field below
|
|
|
|
mstch::array& txs = boost::get<mstch::array>(context["blk_txs"]);
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// timescale representation for each tx in the block
|
|
|
|
vector<string> mixin_timescales_str;
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for each transaction in the block
|
|
|
|
for (size_t i = 0; i < blk.tx_hashes.size(); ++i)
|
|
|
|
{
|
|
|
|
// get transaction info of the tx in the mempool
|
|
|
|
const crypto::hash& tx_hash = blk.tx_hashes.at(i);
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove "<" and ">" from the hash string
|
|
|
|
string tx_hash_str = pod_to_hex(tx_hash);
|
2016-04-16 03:44:58 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get transaction
|
|
|
|
transaction tx;
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(tx_hash, tx))
|
|
|
|
{
|
|
|
|
cerr << "Cant get tx: " << tx_hash << endl;
|
|
|
|
continue;
|
|
|
|
}
|
2016-04-15 23:07:47 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx, false,
|
|
|
|
_blk_height,
|
|
|
|
current_blockchain_height);
|
2016-04-17 05:09:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add fee to the rest
|
|
|
|
sum_fees += txd.fee;
|
2016-04-17 01:44:24 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get mixins in time scale for visual representation
|
|
|
|
//string mixin_times_scale = xmreg::timestamps_time_scale(mixin_timestamps,
|
|
|
|
// server_timestamp);
|
2016-04-17 01:44:24 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add tx details mstch map to context
|
|
|
|
txs.push_back(txd.get_mstch_map());
|
|
|
|
}
|
2016-04-17 01:44:24 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add total fees in the block to the context
|
|
|
|
context["sum_fees"]
|
|
|
|
= xmreg::xmr_amount_to_str(sum_fees, "{:0.6f}");
|
2016-04-17 05:09:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get xmr in the block reward
|
|
|
|
context["blk_reward"]
|
|
|
|
= xmreg::xmr_amount_to_str(txd_coinbase.xmr_outputs - sum_fees, "{:0.6f}");
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["block"], context);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_block(string _blk_hash)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash blk_hash;
|
2016-04-17 05:09:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_secret_key(_blk_hash, blk_hash))
|
|
|
|
{
|
|
|
|
cerr << "Cant parse blk hash: " << blk_hash << endl;
|
|
|
|
return fmt::format("Cant get block {:s} due to block hash parse error!", blk_hash);
|
|
|
|
}
|
2016-04-17 05:09:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t blk_height;
|
2016-04-17 05:09:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (core_storage->have_block(blk_hash))
|
|
|
|
{
|
|
|
|
blk_height = core_storage->get_db().get_block_height(blk_hash);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "Cant get block: " << blk_hash << endl;
|
|
|
|
return fmt::format("Cant get block {:s} for some uknown reason", blk_hash);
|
|
|
|
}
|
2016-04-15 23:07:47 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return show_block(blk_height);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_tx(string tx_hash_str, uint16_t with_ring_signatures = 0)
|
2016-04-15 23:07:47 +00:00
|
|
|
{
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// parse tx hash string to hash object
|
|
|
|
crypto::hash tx_hash;
|
2016-04-15 23:07:47 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash))
|
2016-04-15 23:07:47 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "Cant parse tx hash: " << tx_hash_str << endl;
|
|
|
|
return string("Cant get tx hash due to parse error: " + tx_hash_str);
|
|
|
|
}
|
2016-04-15 23:07:47 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// tx age
|
|
|
|
pair<string, string> age;
|
2016-04-15 23:07:47 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string blk_timestamp {"N/A"};
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get transaction
|
|
|
|
transaction tx;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool show_more_details_link {true};
|
2017-02-16 23:37:25 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(tx_hash, tx))
|
2016-04-15 23:07:47 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "Cant get tx in blockchain: " << tx_hash
|
|
|
|
<< ". \n Check mempool now" << endl;
|
2016-04-15 23:07:47 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
vector<MempoolStatus::mempool_tx> found_txs;
|
2017-05-04 00:52:52 +00:00
|
|
|
|
|
|
|
search_mempool(tx_hash, found_txs);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!found_txs.empty())
|
|
|
|
{
|
|
|
|
// there should be only one tx found
|
2017-06-02 02:14:42 +00:00
|
|
|
tx = found_txs.at(0).tx;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// since its tx in mempool, it has no blk yet
|
|
|
|
// so use its recive_time as timestamp to show
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_recieve_timestamp
|
2017-06-02 02:14:42 +00:00
|
|
|
= found_txs.at(0).info.receive_time;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
blk_timestamp = xmreg::timestamp_to_str_gm(tx_recieve_timestamp);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
age = get_age(server_timestamp, tx_recieve_timestamp,
|
|
|
|
FULL_AGE_FORMAT);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for mempool tx, we dont show more details, e.g., json tx representation
|
|
|
|
// so no need for the link
|
|
|
|
// show_more_details_link = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// tx is nowhere to be found :-(
|
|
|
|
return string("Cant get tx: " + tx_hash_str);
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map tx_context;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (enable_tx_cache && tx_context_cache.Contains({tx_hash, with_ring_signatures}))
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// with_ring_signatures == 0 means that cache is not used
|
|
|
|
// when obtaining detailed information about tx is requested.
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// we are going to measure time for the construction of the
|
|
|
|
// tx context from cashe. just for fun, to see if cache is any faster.
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const tx_info_cache& tx_info_cashed
|
|
|
|
= tx_context_cache.Get({tx_hash, with_ring_signatures});
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context = tx_info_cashed.tx_map;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "get tx from cash: " << tx_hash_str <<endl;
|
|
|
|
//cout << " - tx_blk_height: " << boost::get<uint64_t>(tx_context["tx_blk_height"]) <<endl;
|
|
|
|
//cout << " - blk_timestamp_uint: " << boost::get<uint64_t>(tx_context["blk_timestamp_uint"]) <<endl;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// now have to update age and confirmation numbers of the tx.
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_blk_height = boost::get<uint64_t>(tx_context["tx_blk_height"]);
|
|
|
|
uint64_t blk_timestamp_uint = boost::get<uint64_t>(tx_context["blk_timestamp_uint"]);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (tx_blk_height > 0)
|
|
|
|
{
|
|
|
|
// seems to be in blockchain. off course it could have been orphaned
|
|
|
|
// so double check if its for sure in blockchain
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (core_storage->have_tx(tx_hash))
|
|
|
|
{
|
|
|
|
// ok, it is still in blockchain
|
|
|
|
// update its age and number of confirmations
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
pair<string, string> age
|
|
|
|
= get_age(std::time(nullptr),
|
|
|
|
blk_timestamp_uint,
|
|
|
|
FULL_AGE_FORMAT);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["delta_time"] = age.first;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t bc_height = core_storage->get_current_blockchain_height();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["confirmations"] = bc_height - (tx_blk_height - 1);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// marke it as from cashe. useful if we want to show
|
|
|
|
// info about cashed/not cashed in frontend.
|
|
|
|
tx_context["from_cache"] = true;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>
|
|
|
|
(std::chrono::steady_clock::now() - start);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["construction_time"] = fmt::format(
|
|
|
|
"{:0.4f}", static_cast<double>(duration.count())/1.0e6);
|
|
|
|
|
|
|
|
// normally we should update this into in the cache.
|
|
|
|
// but since we make this check all the time,
|
|
|
|
// we can skip updating cashed version
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // if (core_storage->have_tx(tx_hash))
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// its not in blockchain, but it was there when we cashed it.
|
|
|
|
// so we update it in cash, as it should be back in mempool
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context = construct_tx_context(tx, with_ring_signatures);
|
|
|
|
|
|
|
|
tx_context_cache.Put(
|
|
|
|
{tx_hash, with_ring_signatures},
|
|
|
|
tx_info_cache {
|
|
|
|
boost::get<uint64_t>(tx_context["tx_blk_height"]),
|
|
|
|
boost::get<uint64_t>(tx_context["blk_timestamp_uint"]),
|
|
|
|
tx_context}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} // if (tx_blk_height > 0)
|
2017-04-28 05:45:30 +00:00
|
|
|
else
|
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// the tx was cashed when in mempool.
|
|
|
|
// since then, it might have been included in some block.
|
|
|
|
// so we check it.
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (core_storage->have_tx(tx_hash))
|
|
|
|
{
|
|
|
|
// checking if in blockchain already
|
|
|
|
// it was before in mempool, but now maybe already in blockchain
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context = construct_tx_context(tx, with_ring_signatures);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context_cache.Put(
|
|
|
|
{tx_hash, with_ring_signatures},
|
|
|
|
tx_info_cache {
|
|
|
|
boost::get<uint64_t>(tx_context["tx_blk_height"]),
|
|
|
|
boost::get<uint64_t>(tx_context["blk_timestamp_uint"]),
|
|
|
|
tx_context});
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // if (core_storage->have_tx(tx_hash))
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// still seems to be in mempool only.
|
|
|
|
// so just get its time duration, as its read only
|
|
|
|
// from cache
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["from_cache"] = true;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>
|
|
|
|
(std::chrono::steady_clock::now() - start);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["construction_time"] = fmt::format(
|
|
|
|
"{:0.4f}", static_cast<double>(duration.count())/1.0e6);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // else if (tx_blk_height > 0)
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // if (tx_context_cache.Contains(tx_hash))
|
|
|
|
else
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// we are going to measure time for the construction of the
|
|
|
|
// tx context. just for fun, to see if cache is any faster.
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context = construct_tx_context(tx, with_ring_signatures);
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>
|
|
|
|
(std::chrono::steady_clock::now() - start);
|
2017-02-16 23:37:25 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (enable_tx_cache)
|
|
|
|
{
|
|
|
|
tx_context_cache.Put(
|
|
|
|
{tx_hash, with_ring_signatures},
|
|
|
|
tx_info_cache {
|
|
|
|
boost::get<uint64_t>(tx_context["tx_blk_height"]),
|
|
|
|
boost::get<uint64_t>(tx_context["blk_timestamp_uint"]),
|
|
|
|
tx_context});
|
|
|
|
}
|
2016-04-18 05:57:38 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["construction_time"] = fmt::format(
|
|
|
|
"{:0.4f}", static_cast<double>(duration.count())/1.0e6);
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // else if (tx_context_cache.Contains(tx_hash))
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["show_more_details_link"] = show_more_details_link;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (boost::get<bool>(tx_context["has_error"]))
|
|
|
|
{
|
|
|
|
return boost::get<string>(tx_context["error_msg"]);
|
|
|
|
}
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , this->testnet},
|
|
|
|
{"show_cache_times" , show_cache_times},
|
|
|
|
{"txs" , mstch::array{}}
|
|
|
|
};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
boost::get<mstch::array>(context["txs"]).push_back(tx_context);
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
map<string, string> partials {
|
|
|
|
{"tx_details", template_file["tx_details"]},
|
|
|
|
};
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["tx"], context, partials);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_my_outputs(string tx_hash_str,
|
|
|
|
string xmr_address_str,
|
|
|
|
string viewkey_str, /* or tx_prv_key_str when tx_prove == true */
|
|
|
|
string raw_tx_data,
|
|
|
|
bool tx_prove = false)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove white characters
|
|
|
|
boost::trim(tx_hash_str);
|
|
|
|
boost::trim(xmr_address_str);
|
|
|
|
boost::trim(viewkey_str);
|
|
|
|
boost::trim(raw_tx_data);
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (tx_hash_str.empty())
|
|
|
|
{
|
|
|
|
return string("tx hash not provided!");
|
|
|
|
}
|
2016-10-04 05:59:31 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (xmr_address_str.empty())
|
|
|
|
{
|
|
|
|
return string("Monero address not provided!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewkey_str.empty())
|
|
|
|
{
|
|
|
|
if (!tx_prove)
|
|
|
|
return string("Viewkey not provided!");
|
|
|
|
else
|
|
|
|
return string("Tx private key not provided!");
|
|
|
|
}
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// parse tx hash string to hash object
|
|
|
|
crypto::hash tx_hash;
|
2016-10-04 05:59:31 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash))
|
|
|
|
{
|
|
|
|
cerr << "Cant parse tx hash: " << tx_hash_str << endl;
|
|
|
|
return string("Cant get tx hash due to parse error: " + tx_hash_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse string representing given monero address
|
|
|
|
cryptonote::account_public_address address;
|
2016-10-04 05:59:31 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// parse string representing given private key
|
|
|
|
crypto::secret_key prv_view_key;
|
|
|
|
|
|
|
|
if (!xmreg::parse_str_secret_key(viewkey_str, prv_view_key))
|
|
|
|
{
|
|
|
|
cerr << "Cant parse the private key: " << viewkey_str << endl;
|
|
|
|
return string("Cant parse private key: " + viewkey_str);
|
|
|
|
}
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-02-21 01:13:09 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// just to see how would having spend keys could worked
|
|
|
|
// this is from testnet wallet: A2VTvE8bC9APsWFn3mQzgW8Xfcy2SP2CRUArD6ZtthNaWDuuvyhtBcZ8WDuYMRt1HhcnNQvpXVUavEiZ9waTbyBhP6RM8TV
|
|
|
|
// view key: 041a241325326f9d86519b714a9b7f78b29111551757eeb6334d39c21f8b7400
|
|
|
|
// example tx: 430b070e213659a864ec82d674fddb5ccf7073cae231b019ba1ebb4bfdc07a15
|
2017-02-21 01:13:09 +00:00
|
|
|
// string spend_key_str("643fedcb8dca1f3b406b84575ecfa94ba01257d56f20d55e8535385503dacc08");
|
|
|
|
//
|
|
|
|
// crypto::secret_key prv_spend_key;
|
|
|
|
// if (!xmreg::parse_str_secret_key(spend_key_str, prv_spend_key))
|
|
|
|
// {
|
|
|
|
// cerr << "Cant parse the prv_spend_key : " << spend_key_str << endl;
|
|
|
|
// return string("Cant parse prv_spend_key : " + spend_key_str);
|
|
|
|
// }
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// tx age
|
|
|
|
pair<string, string> age;
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string blk_timestamp {"N/A"};
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get transaction
|
|
|
|
transaction tx;
|
2017-01-28 06:04:25 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!raw_tx_data.empty())
|
2017-01-28 06:04:25 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// we want to check outputs of tx submited through tx pusher.
|
|
|
|
// it is raw tx data, it is not in blockchain nor in mempool.
|
|
|
|
// so we need to reconstruct tx object from this string
|
2017-01-28 06:04:25 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cryptonote::blobdata tx_data_blob;
|
2017-01-28 06:04:25 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!epee::string_tools::parse_hexstr_to_binbuff(raw_tx_data, tx_data_blob))
|
|
|
|
{
|
|
|
|
string msg = fmt::format("Cant obtain tx_data_blob from raw_tx_data");
|
2017-01-28 06:04:25 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << msg << endl;
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return msg;
|
|
|
|
}
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash tx_hash_from_blob;
|
|
|
|
crypto::hash tx_prefix_hash_from_blob;
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!cryptonote::parse_and_validate_tx_from_blob(tx_data_blob,
|
|
|
|
tx,
|
|
|
|
tx_hash_from_blob,
|
|
|
|
tx_prefix_hash_from_blob))
|
|
|
|
{
|
|
|
|
string msg = fmt::format("cant parse_and_validate_tx_from_blob");
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << msg << endl;
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return msg;
|
|
|
|
}
|
2016-10-04 05:05:45 +00:00
|
|
|
|
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
else if (!mcore->get_tx(tx_hash, tx))
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "Cant get tx in blockchain: " << tx_hash
|
|
|
|
<< ". \n Check mempool now" << endl;
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
vector<MempoolStatus::mempool_tx> found_txs;
|
2017-05-04 00:52:52 +00:00
|
|
|
|
|
|
|
search_mempool(tx_hash, found_txs);
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!found_txs.empty())
|
|
|
|
{
|
|
|
|
// there should be only one tx found
|
2017-06-02 02:14:42 +00:00
|
|
|
tx = found_txs.at(0).tx;
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// since its tx in mempool, it has no blk yet
|
|
|
|
// so use its recive_time as timestamp to show
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_recieve_timestamp
|
2017-06-02 02:14:42 +00:00
|
|
|
= found_txs.at(0).info.receive_time;
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
blk_timestamp = xmreg::timestamp_to_str_gm(tx_recieve_timestamp);
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
age = get_age(server_timestamp,
|
|
|
|
tx_recieve_timestamp,
|
|
|
|
FULL_AGE_FORMAT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// tx is nowhere to be found :-(
|
|
|
|
return string("Cant get tx: " + tx_hash_str);
|
|
|
|
}
|
|
|
|
}
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx);
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_blk_height {0};
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool tx_blk_found {false};
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tx_blk_height = core_storage->get_db().get_tx_block_height(tx_hash);
|
|
|
|
tx_blk_found = true;
|
|
|
|
}
|
|
|
|
catch (exception& e)
|
|
|
|
{
|
|
|
|
cerr << "Cant get block height: " << tx_hash
|
|
|
|
<< e.what() << endl;
|
|
|
|
}
|
2016-10-04 05:05:45 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block cointaining this tx
|
|
|
|
block blk;
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (tx_blk_found && !mcore->get_block_by_height(tx_blk_height, blk))
|
|
|
|
{
|
|
|
|
cerr << "Cant get block: " << tx_blk_height << endl;
|
|
|
|
}
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string tx_blk_height_str {"N/A"};
|
2016-04-22 06:15:06 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (tx_blk_found)
|
|
|
|
{
|
|
|
|
// calculate difference between tx and server timestamps
|
|
|
|
age = get_age(server_timestamp, blk.timestamp, FULL_AGE_FORMAT);
|
2017-01-10 07:42:55 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
blk_timestamp = xmreg::timestamp_to_str_gm(blk.timestamp);
|
2016-04-22 06:15:06 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_blk_height_str = std::to_string(tx_blk_height);
|
|
|
|
}
|
2016-04-22 06:15:06 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// payments id. both normal and encrypted (payment_id8)
|
|
|
|
string pid_str = pod_to_hex(txd.payment_id);
|
|
|
|
string pid8_str = pod_to_hex(txd.payment_id8);
|
|
|
|
|
|
|
|
|
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"tx_hash" , tx_hash_str},
|
|
|
|
{"tx_prefix_hash" , pod_to_hex(txd.prefix_hash)},
|
|
|
|
{"xmr_address" , xmr_address_str},
|
|
|
|
{"viewkey" , viewkey_str},
|
|
|
|
{"tx_pub_key" , pod_to_hex(txd.pk)},
|
|
|
|
{"blk_height" , tx_blk_height_str},
|
|
|
|
{"tx_size" , fmt::format("{:0.4f}",
|
|
|
|
static_cast<double>(txd.size) / 1024.0)},
|
|
|
|
{"tx_fee" , xmreg::xmr_amount_to_str(txd.fee)},
|
|
|
|
{"blk_timestamp" , blk_timestamp},
|
|
|
|
{"delta_time" , age.first},
|
|
|
|
{"outputs_no" , static_cast<uint64_t>(txd.output_pub_keys.size())},
|
|
|
|
{"has_payment_id" , txd.payment_id != null_hash},
|
|
|
|
{"has_payment_id8" , txd.payment_id8 != null_hash8},
|
|
|
|
{"payment_id" , pid_str},
|
|
|
|
{"payment_id8" , pid8_str},
|
|
|
|
{"tx_prove" , tx_prove}
|
|
|
|
};
|
2016-04-22 06:15:06 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string server_time_str = xmreg::timestamp_to_str_gm(server_timestamp, "%F");
|
2017-01-10 07:42:55 +00:00
|
|
|
|
2016-04-22 06:15:06 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// public transaction key is combined with our viewkey
|
|
|
|
// to create, so called, derived key.
|
|
|
|
key_derivation derivation;
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
public_key pub_key = tx_prove ? address.m_view_public_key : txd.pk;
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "txd.pk: " << pod_to_hex(txd.pk) << endl;
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!generate_key_derivation(pub_key, prv_view_key, derivation))
|
|
|
|
{
|
|
|
|
cerr << "Cant get derived key for: " << "\n"
|
|
|
|
<< "pub_tx_key: " << pub_key << " and "
|
|
|
|
<< "prv_view_key" << prv_view_key << endl;
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return string("Cant get key_derivation");
|
|
|
|
}
|
2016-04-18 05:57:38 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array outputs;
|
2016-04-20 17:32:51 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t sum_xmr {0};
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
std::vector<uint64_t> money_transfered(tx.vout.size(), 0);
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//std::deque<rct::key> mask(tx.vout.size());
|
2017-01-10 07:42:55 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t output_idx {0};
|
2016-04-22 01:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (pair<txout_to_key, uint64_t>& outp: txd.output_pub_keys)
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2017-01-20 00:07:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get the tx output public key
|
|
|
|
// that normally would be generated for us,
|
|
|
|
// if someone had sent us some xmr.
|
|
|
|
public_key tx_pubkey;
|
2017-01-20 00:07:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
derive_public_key(derivation,
|
|
|
|
output_idx,
|
|
|
|
address.m_spend_public_key,
|
|
|
|
tx_pubkey);
|
2017-01-20 00:07:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << pod_to_hex(outp.first.key) << endl;
|
|
|
|
//cout << pod_to_hex(tx_pubkey) << endl;
|
2017-01-20 00:07:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if generated public key matches the current output's key
|
|
|
|
bool mine_output = (outp.first.key == tx_pubkey);
|
|
|
|
|
|
|
|
// if mine output has RingCT, i.e., tx version is 2
|
|
|
|
if (mine_output && tx.version == 2)
|
|
|
|
{
|
|
|
|
// cointbase txs have amounts in plain sight.
|
|
|
|
// so use amount from ringct, only for non-coinbase txs
|
|
|
|
if (!is_coinbase(tx))
|
2017-01-20 00:07:42 +00:00
|
|
|
{
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initialize with regular amount
|
|
|
|
uint64_t rct_amount = money_transfered[output_idx];
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool r;
|
2016-04-20 17:32:51 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
r = decode_ringct(tx.rct_signatures,
|
|
|
|
pub_key,
|
|
|
|
prv_view_key,
|
|
|
|
output_idx,
|
|
|
|
tx.rct_signatures.ecdhInfo[output_idx].mask,
|
|
|
|
rct_amount);
|
2016-08-20 10:25:18 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
cerr << "\nshow_my_outputs: Cant decode ringCT! " << endl;
|
|
|
|
}
|
2016-04-23 06:14:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
outp.second = rct_amount;
|
|
|
|
money_transfered[output_idx] = rct_amount;
|
|
|
|
}
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (mine_output)
|
|
|
|
{
|
|
|
|
sum_xmr += outp.second;
|
|
|
|
}
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
outputs.push_back(mstch::map {
|
|
|
|
{"out_pub_key" , pod_to_hex(outp.first.key)},
|
|
|
|
{"amount" , xmreg::xmr_amount_to_str(outp.second)},
|
|
|
|
{"mine_output" , mine_output},
|
|
|
|
{"output_idx" , fmt::format("{:02d}", output_idx)}
|
|
|
|
});
|
2017-02-21 01:13:09 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++output_idx;
|
|
|
|
}
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// we can also test ouputs used in mixins for key images
|
|
|
|
// this can show possible spending. Only possible, because
|
|
|
|
// without a spend key, we cant know for sure. It might be
|
|
|
|
// that our output was used by someone else for their mixins.
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool show_key_images {false};
|
2017-01-19 02:57:39 +00:00
|
|
|
|
2017-01-21 23:54:19 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array inputs;
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
vector<txin_to_key> input_key_imgs = xmreg::get_key_images(tx);
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// to hold sum of xmr in matched mixins, those that
|
|
|
|
// perfectly match mixin public key with outputs in mixn_tx.
|
|
|
|
uint64_t sum_mixin_xmr {0};
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// this is used for the final check. we assument that number of
|
|
|
|
// parefct matches must be equal to number of inputs in a tx.
|
|
|
|
uint64_t no_of_matched_mixins {0};
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const txin_to_key& in_key: input_key_imgs)
|
2016-12-20 07:08:33 +00:00
|
|
|
{
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get absolute offsets of mixins
|
|
|
|
std::vector<uint64_t> absolute_offsets
|
|
|
|
= cryptonote::relative_output_offsets_to_absolute(
|
|
|
|
in_key.key_offsets);
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get public keys of outputs used in the mixins that match to the offests
|
|
|
|
std::vector<cryptonote::output_data_t> mixin_outputs;
|
2017-01-18 06:46:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
core_storage->get_db().get_output_key(in_key.amount,
|
|
|
|
absolute_offsets,
|
|
|
|
mixin_outputs);
|
2017-01-18 06:46:50 +00:00
|
|
|
}
|
|
|
|
catch (const OUTPUT_DNE& e)
|
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "get_output_keys: " << e.what() << endl;
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-18 06:46:50 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
inputs.push_back(mstch::map{
|
|
|
|
{"key_image" , pod_to_hex(in_key.k_image)},
|
|
|
|
{"key_image_amount", xmreg::xmr_amount_to_str(in_key.amount)},
|
|
|
|
make_pair(string("mixins"), mstch::array{})
|
|
|
|
});
|
2017-01-18 06:46:50 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array& mixins = boost::get<mstch::array>(
|
|
|
|
boost::get<mstch::map>(inputs.back())["mixins"]
|
|
|
|
);
|
2017-01-18 06:46:50 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// to store our mixins found for the given key image
|
|
|
|
vector<map<string, string>> our_mixins_found;
|
|
|
|
|
|
|
|
// mixin counter
|
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
// there can be more than one our output used for mixin in a single
|
|
|
|
// input. For example, if two outputs are matched (marked by *) in html,
|
|
|
|
// one of them will be our real spending, and second will be used as a fake
|
|
|
|
// one. ideally, to determine which is which, spendkey is required.
|
|
|
|
// obvisouly we dont have it here, so we need to pick one in other way.
|
|
|
|
// for now I will just pick the first one we find, and threat it as the
|
|
|
|
// real spending output. The no_of_output_matches_found variable
|
|
|
|
// is used for this purporse.
|
|
|
|
// testnet tx 430b070e213659a864ec82d674fddb5ccf7073cae231b019ba1ebb4bfdc07a15
|
|
|
|
// and testnet wallet details provided earier for spend key,
|
|
|
|
// demonstrate this. this txs has one input that uses two of our ouputs.
|
|
|
|
// without spent key, its imposible to know which one is real spendking
|
|
|
|
// and which one is fake.
|
|
|
|
size_t no_of_output_matches_found {0};
|
|
|
|
|
|
|
|
// for each found output public key check if its ours or not
|
|
|
|
for (const uint64_t& abs_offset: absolute_offsets)
|
|
|
|
{
|
2017-01-18 06:46:50 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get basic information about mixn's output
|
|
|
|
cryptonote::output_data_t output_data = mixin_outputs.at(count);
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_out_index tx_out_idx;
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// get pair pair<crypto::hash, uint64_t> where first is tx hash
|
|
|
|
// and second is local index of the output i in that tx
|
|
|
|
tx_out_idx = core_storage->get_db()
|
|
|
|
.get_output_tx_and_index(in_key.amount, abs_offset);
|
|
|
|
}
|
|
|
|
catch (const OUTPUT_DNE& e)
|
|
|
|
{
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string out_msg = fmt::format(
|
|
|
|
"Output with amount {:d} and index {:d} does not exist!",
|
|
|
|
in_key.amount, abs_offset
|
|
|
|
);
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << out_msg << endl;
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string out_pub_key_str = pod_to_hex(output_data.pubkey);
|
2017-01-22 01:55:19 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "out_pub_key_str: " << out_pub_key_str << endl;
|
2016-12-20 07:08:33 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get mixin transaction
|
|
|
|
transaction mixin_tx;
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(tx_out_idx.first, mixin_tx))
|
|
|
|
{
|
|
|
|
cerr << "Cant get tx: " << tx_out_idx.first << endl;
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string mixin_tx_hash_str = pod_to_hex(tx_out_idx.first);
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mixins.push_back(mstch::map{
|
|
|
|
{"mixin_pub_key" , out_pub_key_str},
|
|
|
|
make_pair<string, mstch::array>("mixin_outputs" , mstch::array{}),
|
|
|
|
{"has_mixin_outputs" , false}
|
|
|
|
});
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array& mixin_outputs = boost::get<mstch::array>(
|
|
|
|
boost::get<mstch::map>(mixins.back())["mixin_outputs"]
|
|
|
|
);
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::node& has_mixin_outputs
|
|
|
|
= boost::get<mstch::map>(mixins.back())["has_mixin_outputs"];
|
2016-12-20 07:08:33 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool found_something {false};
|
2016-12-20 07:08:33 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
public_key mixin_tx_pub_key
|
|
|
|
= xmreg::get_tx_pub_key_from_received_outs(mixin_tx);
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string mixin_tx_pub_key_str = pod_to_hex(mixin_tx_pub_key);
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// public transaction key is combined with our viewkey
|
|
|
|
// to create, so called, derived key.
|
|
|
|
key_derivation derivation;
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!generate_key_derivation(mixin_tx_pub_key, prv_view_key, derivation))
|
|
|
|
{
|
|
|
|
cerr << "Cant get derived key for: " << "\n"
|
|
|
|
<< "pub_tx_key: " << mixin_tx_pub_key << " and "
|
|
|
|
<< "prv_view_key" << prv_view_key << endl;
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// <public_key , amount , out idx>
|
|
|
|
vector<tuple<txout_to_key, uint64_t, uint64_t>> output_pub_keys;
|
|
|
|
|
|
|
|
output_pub_keys = xmreg::get_ouputs_tuple(mixin_tx);
|
|
|
|
|
|
|
|
mixin_outputs.push_back(mstch::map{
|
|
|
|
{"mix_tx_hash" , mixin_tx_hash_str},
|
|
|
|
{"mix_tx_pub_key" , mixin_tx_pub_key_str},
|
|
|
|
make_pair<string, mstch::array>("found_outputs" , mstch::array{}),
|
|
|
|
{"has_found_outputs", false}
|
|
|
|
});
|
|
|
|
|
|
|
|
mstch::array& found_outputs = boost::get<mstch::array>(
|
|
|
|
boost::get<mstch::map>(mixin_outputs.back())["found_outputs"]
|
|
|
|
);
|
|
|
|
|
|
|
|
mstch::node& has_found_outputs
|
|
|
|
= boost::get<mstch::map>(mixin_outputs.back())["has_found_outputs"];
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for each output in mixin tx, find the one from key_image
|
|
|
|
// and check if its ours.
|
|
|
|
for (const auto& mix_out: output_pub_keys)
|
|
|
|
{
|
|
|
|
|
|
|
|
txout_to_key txout_k = std::get<0>(mix_out);
|
|
|
|
uint64_t amount = std::get<1>(mix_out);
|
|
|
|
uint64_t output_idx_in_tx = std::get<2>(mix_out);
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << " - " << pod_to_hex(txout_k.key) << endl;
|
2017-01-12 01:51:24 +00:00
|
|
|
|
2017-01-17 09:07:14 +00:00
|
|
|
// // analyze only those output keys
|
|
|
|
// // that were used in mixins
|
|
|
|
// if (txout_k.key != output_data.pubkey)
|
2016-12-20 07:08:33 +00:00
|
|
|
// {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get the tx output public key
|
|
|
|
// that normally would be generated for us,
|
|
|
|
// if someone had sent us some xmr.
|
|
|
|
public_key tx_pubkey_generated;
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
derive_public_key(derivation,
|
|
|
|
output_idx_in_tx,
|
|
|
|
address.m_spend_public_key,
|
|
|
|
tx_pubkey_generated);
|
2017-01-18 23:36:34 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if generated public key matches the current output's key
|
|
|
|
bool mine_output = (txout_k.key == tx_pubkey_generated);
|
2017-01-18 23:36:34 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (mine_output && mixin_tx.version == 2)
|
2017-01-10 09:58:52 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// cointbase txs have amounts in plain sight.
|
|
|
|
// so use amount from ringct, only for non-coinbase txs
|
|
|
|
if (!is_coinbase(mixin_tx))
|
2017-01-20 00:07:42 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// initialize with regular amount
|
|
|
|
uint64_t rct_amount = amount;
|
2017-01-20 00:07:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool r;
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
r = decode_ringct(mixin_tx.rct_signatures,
|
|
|
|
mixin_tx_pub_key,
|
|
|
|
prv_view_key,
|
|
|
|
output_idx_in_tx,
|
|
|
|
mixin_tx.rct_signatures.ecdhInfo[output_idx_in_tx].mask,
|
|
|
|
rct_amount);
|
2017-01-20 06:20:07 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
cerr << "show_my_outputs: key images: Cant decode ringCT!" << endl;
|
|
|
|
}
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
amount = rct_amount;
|
2017-01-19 02:57:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // if (mine_output && mixin_tx.version == 2)
|
2017-01-20 05:31:14 +00:00
|
|
|
}
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// makre only
|
|
|
|
bool output_match = (txout_k.key == output_data.pubkey);
|
|
|
|
|
|
|
|
// mark only first output_match as the "real" one
|
|
|
|
// due to luck of better method of gussing which output
|
|
|
|
// is real if two are found in a single input.
|
|
|
|
output_match = output_match && no_of_output_matches_found == 0;
|
|
|
|
|
|
|
|
// save our mixnin's public keys
|
|
|
|
found_outputs.push_back(mstch::map {
|
|
|
|
{"my_public_key" , pod_to_hex(txout_k.key)},
|
|
|
|
{"tx_hash" , tx_hash_str},
|
|
|
|
{"mine_output" , mine_output},
|
|
|
|
{"out_idx" , output_idx_in_tx},
|
|
|
|
{"formed_output_pk", out_pub_key_str},
|
|
|
|
{"out_in_match" , output_match},
|
|
|
|
{"amount" , xmreg::xmr_amount_to_str(amount)}
|
|
|
|
});
|
|
|
|
|
|
|
|
//cout << "txout_k.key == output_data.pubkey" << endl;
|
|
|
|
//cout << pod_to_hex(txout_k.key) << " == " << pod_to_hex(output_data.pubkey) << endl;
|
|
|
|
|
|
|
|
if (mine_output)
|
2017-01-19 04:22:01 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
found_something = true;
|
|
|
|
show_key_images = true;
|
|
|
|
|
|
|
|
// increase sum_mixin_xmr only when
|
|
|
|
// public key of an outputs used in ring signature,
|
|
|
|
// matches a public key in a mixin_tx
|
|
|
|
if (txout_k.key != output_data.pubkey)
|
2017-02-20 01:35:03 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
continue;
|
2017-02-20 01:35:03 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
// sum up only first output matched found in each input
|
|
|
|
if (no_of_output_matches_found == 0)
|
2017-02-20 01:35:03 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// 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
|
|
|
|
// for regular/old txs there must be also a match
|
|
|
|
// in amounts, not only in output public keys
|
|
|
|
if (mixin_tx.version < 2 && amount == in_key.amount)
|
|
|
|
{
|
|
|
|
sum_mixin_xmr += amount;
|
|
|
|
}
|
|
|
|
else if (mixin_tx.version == 2) // ringct
|
|
|
|
{
|
|
|
|
sum_mixin_xmr += amount;
|
|
|
|
}
|
2017-02-20 01:35:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
no_of_matched_mixins++;
|
|
|
|
}
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-02-21 01:13:09 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// generate key_image using this output
|
|
|
|
// just to see how would having spend keys worked
|
2017-02-21 01:13:09 +00:00
|
|
|
// crypto::key_image key_img;
|
|
|
|
//
|
|
|
|
// if (!xmreg::generate_key_image(derivation,
|
|
|
|
// output_idx_in_tx, /* position in the tx */
|
|
|
|
// prv_spend_key,
|
|
|
|
// address.m_spend_public_key,
|
|
|
|
// key_img)) {
|
|
|
|
// cerr << "Cant generate key image for output: "
|
|
|
|
// << pod_to_hex(output_data.pubkey) << endl;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// cout << "output_data.pubkey: " << pod_to_hex(output_data.pubkey)
|
|
|
|
// << ", key_img: " << pod_to_hex(key_img)
|
|
|
|
// << ", key_img == input_key: " << (key_img == in_key.k_image)
|
|
|
|
// << endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
no_of_output_matches_found++;
|
2017-02-20 01:35:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (const pair<txout_to_key, uint64_t>& mix_out: txd.output_pub_keys)
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
has_found_outputs = !found_outputs.empty();
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
has_mixin_outputs = found_something;
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++count;
|
2017-01-20 06:20:07 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (const cryptonote::output_data_t& output_data: mixin_outputs)
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2017-01-18 06:35:12 +00:00
|
|
|
|
2017-01-17 09:07:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (const txin_to_key& in_key: input_key_imgs)
|
2016-12-20 07:08:33 +00:00
|
|
|
|
2016-04-22 01:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("outputs", outputs);
|
2017-01-19 04:22:01 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["found_our_outputs"] = (sum_xmr > 0);
|
|
|
|
context["sum_xmr"] = xmreg::xmr_amount_to_str(sum_xmr);
|
2016-04-20 07:11:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("inputs", inputs);
|
2017-01-19 04:22:01 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["show_inputs"] = show_key_images;
|
|
|
|
context["inputs_no"] = static_cast<uint64_t>(inputs.size());
|
|
|
|
context["sum_mixin_xmr"] = xmreg::xmr_amount_to_str(
|
|
|
|
sum_mixin_xmr, "{:0.12f}", false);
|
2017-01-19 04:22:01 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t possible_spending {0};
|
2017-01-19 04:22:01 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// show spending only if sum of mixins is more than
|
|
|
|
// what we get + fee, and number of perferctly matched
|
|
|
|
// mixis is equal to number of inputs
|
|
|
|
if (sum_mixin_xmr > (sum_xmr + txd.fee)
|
2017-01-21 23:54:19 +00:00
|
|
|
&& no_of_matched_mixins == inputs.size())
|
2017-04-28 07:24:19 +00:00
|
|
|
{
|
|
|
|
// (outcoming - incoming) - fee
|
|
|
|
possible_spending = (sum_mixin_xmr - sum_xmr) - txd.fee;
|
|
|
|
}
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["possible_spending"] = xmreg::xmr_amount_to_str(
|
|
|
|
possible_spending, "{:0.12f}", false);
|
2016-05-10 00:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["my_outputs"], context);
|
|
|
|
}
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_prove(string tx_hash_str,
|
|
|
|
string xmr_address_str,
|
|
|
|
string tx_prv_key_str)
|
|
|
|
{
|
|
|
|
string raw_tx_data {""}; // not using it in prove tx. only for outputs
|
2016-08-20 10:25:18 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return show_my_outputs(tx_hash_str, xmr_address_str,
|
|
|
|
tx_prv_key_str, raw_tx_data, true);
|
|
|
|
}
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_rawtx()
|
|
|
|
{
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet}
|
|
|
|
};
|
2016-12-31 02:34:00 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-04-20 22:52:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["rawtx"], context);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-08-20 10:25:18 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_checkrawtx(string raw_tx_data, string action)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
clean_post_data(raw_tx_data);
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string decoded_raw_tx_data = epee::string_encoding::base64_decode(raw_tx_data);
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << decoded_raw_tx_data << endl;
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const size_t magiclen = strlen(UNSIGNED_TX_PREFIX);
|
2016-04-18 05:57:38 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string data_prefix = xmreg::make_printable(decoded_raw_tx_data.substr(0, magiclen));
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool unsigned_tx_given {false};
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (strncmp(decoded_raw_tx_data.c_str(), UNSIGNED_TX_PREFIX, magiclen) == 0)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
unsigned_tx_given = true;
|
|
|
|
}
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalize page template context map
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"unsigned_tx_given" , unsigned_tx_given},
|
|
|
|
{"have_raw_tx" , true},
|
|
|
|
{"has_error" , false},
|
|
|
|
{"error_msg" , string {}},
|
|
|
|
{"data_prefix" , data_prefix},
|
|
|
|
};
|
2016-04-18 05:57:38 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("txs", mstch::array{});
|
2016-05-09 05:48:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string full_page = template_file["checkrawtx"];
|
2016-05-09 05:48:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-05-09 05:48:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (unsigned_tx_given)
|
|
|
|
{
|
2016-05-09 05:48:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool r {false};
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string s = decoded_raw_tx_data.substr(magiclen);
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
::tools::wallet2::unsigned_tx_set exported_txs;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
std::istringstream iss(s);
|
|
|
|
boost::archive::portable_binary_iarchive ar(iss);
|
|
|
|
ar >> exported_txs;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cerr << "Failed to parse unsigned tx data " << endl;
|
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
mstch::array& txs = boost::get<mstch::array>(context["txs"]);
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const ::tools::wallet2::tx_construction_data& tx_cd: exported_txs.txes)
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
size_t no_of_sources = tx_cd.sources.size();
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const tx_destination_entry& tx_change = tx_cd.change_dts;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash payment_id = null_hash;
|
|
|
|
crypto::hash8 payment_id8 = null_hash8;
|
2016-10-19 02:46:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
get_payment_id(tx_cd.extra, payment_id, payment_id8);
|
2016-10-19 02:46:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// payments id. both normal and encrypted (payment_id8)
|
|
|
|
string pid_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", payment_id));
|
|
|
|
string pid8_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", payment_id8));
|
2016-10-19 02:46:33 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map tx_cd_data {
|
|
|
|
{"no_of_sources" , static_cast<uint64_t>(no_of_sources)},
|
|
|
|
{"use_rct" , tx_cd.use_rct},
|
|
|
|
{"change_amount" , xmreg::xmr_amount_to_str(tx_change.amount)},
|
|
|
|
{"has_payment_id" , (payment_id != null_hash)},
|
|
|
|
{"has_payment_id8" , (payment_id8 != null_hash8)},
|
|
|
|
{"payment_id" , pid_str},
|
|
|
|
{"payment_id8" , pid8_str},
|
|
|
|
};
|
|
|
|
tx_cd_data.emplace("dest_sources" , mstch::array{});
|
|
|
|
tx_cd_data.emplace("dest_infos" , mstch::array{});
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array& dest_sources = boost::get<mstch::array>(tx_cd_data["dest_sources"]);
|
|
|
|
mstch::array& dest_infos = boost::get<mstch::array>(tx_cd_data["dest_infos"]);
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const tx_destination_entry& a_dest: tx_cd.splitted_dsts)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map dest_info {
|
|
|
|
{"dest_address" , get_account_address_as_str(testnet, a_dest.addr)},
|
|
|
|
{"dest_amount" , xmreg::xmr_amount_to_str(a_dest.amount)}
|
|
|
|
};
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
dest_infos.push_back(dest_info);
|
2016-10-04 05:05:45 +00:00
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
vector<vector<uint64_t>> mixin_timestamp_groups;
|
|
|
|
vector<uint64_t> real_output_indices;
|
2016-10-13 04:02:17 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t sum_outputs_amounts {0};
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (size_t i = 0; i < no_of_sources; ++i)
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const tx_source_entry& tx_source = tx_cd.sources.at(i);
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map single_dest_source {
|
|
|
|
{"output_amount" , xmreg::xmr_amount_to_str(tx_source.amount)},
|
|
|
|
{"real_output" , static_cast<uint64_t>(tx_source.real_output)},
|
|
|
|
{"real_out_tx_key" , pod_to_hex(tx_source.real_out_tx_key)},
|
|
|
|
{"real_output_in_tx_index" , static_cast<uint64_t>(tx_source.real_output_in_tx_index)},
|
|
|
|
};
|
|
|
|
single_dest_source.emplace("outputs", mstch::array{});
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
sum_outputs_amounts += tx_source.amount;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "tx_source.real_output: " << tx_source.real_output << endl;
|
|
|
|
//cout << "tx_source.real_out_tx_key: " << tx_source.real_out_tx_key << endl;
|
|
|
|
//cout << "tx_source.real_output_in_tx_index: " << tx_source.real_output_in_tx_index << endl;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t index_of_real_output = tx_source.outputs[tx_source.real_output].first;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_out_index real_toi;
|
2016-10-12 02:26:31 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_source_amount = (tx_source.rct ? 0 : tx_source.amount);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// get tx of the real output
|
2017-04-28 07:24:19 +00:00
|
|
|
real_toi = core_storage->get_db()
|
|
|
|
.get_output_tx_and_index(tx_source_amount,
|
|
|
|
index_of_real_output);
|
2016-10-13 05:54:16 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
catch (const OUTPUT_DNE& e)
|
2016-10-13 05:54:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
string out_msg = fmt::format(
|
|
|
|
"Output with amount {:d} and index {:d} does not exist!",
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_source_amount, index_of_real_output
|
2016-10-13 05:54:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
cerr << out_msg << endl;
|
|
|
|
|
|
|
|
return string(out_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
transaction real_source_tx;
|
|
|
|
|
|
|
|
if (!mcore->get_tx(real_toi.first, real_source_tx))
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "Cant get tx in blockchain: " << real_toi.first << endl;
|
|
|
|
return string("Cant get tx: " + pod_to_hex(real_toi.first));
|
2016-10-04 05:05:45 +00:00
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details real_txd = get_tx_details(real_source_tx);
|
|
|
|
|
|
|
|
real_output_indices.push_back(tx_source.real_output);
|
|
|
|
|
|
|
|
public_key real_out_pub_key = real_txd.output_pub_keys[tx_source.real_output_in_tx_index].first.key;
|
|
|
|
|
|
|
|
//cout << "real_txd.hash: " << pod_to_hex(real_txd.hash) << endl;
|
|
|
|
//cout << "real_txd.pk: " << pod_to_hex(real_txd.pk) << endl;
|
|
|
|
//cout << "real_out_pub_key: " << pod_to_hex(real_out_pub_key) << endl;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array& outputs = boost::get<mstch::array>(single_dest_source["outputs"]);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
vector<uint64_t> mixin_timestamps;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
size_t output_i {0};
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for(const tx_source_entry::output_entry& oe: tx_source.outputs)
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_out_index toi;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get tx of the real output
|
|
|
|
toi = core_storage->get_db()
|
|
|
|
.get_output_tx_and_index(tx_source_amount, oe.first);
|
|
|
|
}
|
|
|
|
catch (OUTPUT_DNE& e)
|
|
|
|
{
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string out_msg = fmt::format(
|
|
|
|
"Output with amount {:d} and index {:d} does not exist!",
|
|
|
|
tx_source_amount, oe.first
|
|
|
|
);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << out_msg << endl;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return string(out_msg);
|
|
|
|
}
|
2017-02-16 23:20:55 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
transaction tx;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(toi.first, tx))
|
|
|
|
{
|
|
|
|
cerr << "Cant get tx in blockchain: " << toi.first
|
|
|
|
<< ". \n Check mempool now" << endl;
|
|
|
|
// tx is nowhere to be found :-(
|
|
|
|
return string("Cant get tx: " + pod_to_hex(toi.first));
|
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx);
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
public_key out_pub_key = txd.output_pub_keys[toi.second].first.key;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2016-09-22 05:06:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block cointaining this tx
|
|
|
|
block blk;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_block_by_height(txd.blk_height, blk))
|
|
|
|
{
|
|
|
|
cerr << "Cant get block: " << txd.blk_height << endl;
|
|
|
|
return string("Cant get block: " + to_string(txd.blk_height));
|
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
pair<string, string> age = get_age(server_timestamp, blk.timestamp);
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map single_output {
|
|
|
|
{"out_index" , oe.first},
|
|
|
|
{"tx_hash" , pod_to_hex(txd.hash)},
|
|
|
|
{"out_pub_key" , pod_to_hex(out_pub_key)},
|
|
|
|
{"ctkey" , pod_to_hex(oe.second)},
|
|
|
|
{"output_age" , age.first},
|
|
|
|
{"is_real" , (out_pub_key == real_out_pub_key)}
|
|
|
|
};
|
2016-05-09 04:07:10 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
single_dest_source.insert({"age_format" , age.second});
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
outputs.push_back(single_output);
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mixin_timestamps.push_back(blk.timestamp);
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++output_i;
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for(const tx_source_entry::output_entry& oe: tx_source.outputs)
|
2016-12-31 02:34:00 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
dest_sources.push_back(single_dest_source);
|
2016-12-31 02:34:00 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mixin_timestamp_groups.push_back(mixin_timestamps);
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (size_t i = 0; i < no_of_sources; ++i)
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_cd_data.insert({"sum_outputs_amounts" ,
|
|
|
|
xmreg::xmr_amount_to_str(sum_outputs_amounts)});
|
2017-01-27 03:44:52 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t min_mix_timestamp;
|
|
|
|
uint64_t max_mix_timestamp;
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
pair<mstch::array, double> mixins_timescales
|
|
|
|
= construct_mstch_mixin_timescales(
|
|
|
|
mixin_timestamp_groups,
|
|
|
|
min_mix_timestamp,
|
|
|
|
max_mix_timestamp
|
|
|
|
);
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_cd_data.emplace("timescales", mixins_timescales.first);
|
|
|
|
tx_cd_data["min_mix_time"] = xmreg::timestamp_to_str_gm(min_mix_timestamp);
|
|
|
|
tx_cd_data["max_mix_time"] = xmreg::timestamp_to_str_gm(max_mix_timestamp);
|
|
|
|
tx_cd_data["timescales_scale"] = fmt::format("{:0.2f}",
|
|
|
|
mixins_timescales.second
|
|
|
|
/ 3600.0 / 24.0); // in days
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// mark real mixing in the mixins timescale graph
|
|
|
|
mark_real_mixins_on_timescales(real_output_indices, tx_cd_data);
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txs.push_back(tx_cd_data);
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (const ::tools::wallet2::tx_construction_data& tx_cd: exported_txs.txes)
|
|
|
|
}
|
|
|
|
else
|
2017-01-27 03:44:52 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "deserialization of unsigned tx data NOT successful" << endl;
|
|
|
|
return string("deserialization of unsigned tx data NOT successful. "
|
|
|
|
"Maybe its not base64 encoded?");
|
|
|
|
}
|
|
|
|
} // if (unsigned_tx_given)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if raw data is not unsigined tx, then assume it is signed tx
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const size_t magiclen = strlen(SIGNED_TX_PREFIX);
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string data_prefix = xmreg::make_printable(decoded_raw_tx_data.substr(0, magiclen));
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (strncmp(decoded_raw_tx_data.c_str(), SIGNED_TX_PREFIX, magiclen) != 0)
|
|
|
|
{
|
2017-01-27 03:44:52 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// ok, so its not signed tx data. but maybe it is raw tx data
|
|
|
|
// used in rpc call "/sendrawtransaction". This is for example
|
|
|
|
// used in mymonero and openmonero projects.
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// to check this, first we need to encode data back to base64.
|
|
|
|
// the reason is that txs submited to "/sendrawtransaction"
|
|
|
|
// are not base64, and we earlier always asume it is base64.
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// string reencoded_raw_tx_data = epee::string_encoding::base64_decode(raw_tx_data);
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "raw_tx_data: " << raw_tx_data << endl;
|
2017-01-28 06:04:25 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cryptonote::blobdata tx_data_blob;
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!epee::string_tools::parse_hexstr_to_binbuff(raw_tx_data, tx_data_blob))
|
|
|
|
{
|
|
|
|
string msg = fmt::format("The data is neither unsigned, signed tx or raw tx! "
|
|
|
|
"Its prefix is: {:s}",
|
|
|
|
data_prefix);
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cout << msg << endl;
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return string(msg);
|
|
|
|
}
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash tx_hash_from_blob;
|
|
|
|
crypto::hash tx_prefix_hash_from_blob;
|
|
|
|
cryptonote::transaction tx_from_blob;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!cryptonote::parse_and_validate_tx_from_blob(tx_data_blob,
|
|
|
|
tx_from_blob,
|
|
|
|
tx_hash_from_blob,
|
|
|
|
tx_prefix_hash_from_blob))
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("failed to validate transaction");
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2017-01-27 04:22:13 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-10-13 04:02:17 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "tx_from_blob.vout.size(): " << tx_from_blob.vout.size() << endl;
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// tx has been correctly deserialized. So
|
|
|
|
// we just dispaly it. We dont have any information about real mixins, etc,
|
|
|
|
// so there is not much more we can do with tx data.
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map tx_context = construct_tx_context(tx_from_blob);
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (boost::get<bool>(tx_context["has_error"]))
|
|
|
|
{
|
|
|
|
return boost::get<string>(tx_context["error_msg"]);
|
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// this will be stored in html for for checking outputs
|
|
|
|
// we need this data if we want to use "Decode outputs"
|
|
|
|
// to see which outputs are ours, and decode amounts in ringct txs
|
|
|
|
tx_context["raw_tx_data"] = raw_tx_data;
|
|
|
|
tx_context["show_more_details_link"] = false;
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["data_prefix"] = string("none as this is pure raw tx data");
|
|
|
|
context["tx_json"] = obj_to_json_str(tx_from_blob);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("txs" , mstch::array{});
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
boost::get<mstch::array>(context["txs"]).push_back(tx_context);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
map<string, string> partials {
|
|
|
|
{"tx_details", template_file["tx_details"]},
|
|
|
|
};
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["checkrawtx"], context, partials);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // if (strncmp(decoded_raw_tx_data.c_str(), SIGNED_TX_PREFIX, magiclen) != 0)
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["data_prefix"] = data_prefix;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool r {false};
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string s = decoded_raw_tx_data.substr(magiclen);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
::tools::wallet2::signed_tx_set signed_txs;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
2016-09-07 06:50:37 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
std::istringstream iss(s);
|
|
|
|
boost::archive::portable_binary_iarchive ar(iss);
|
|
|
|
ar >> signed_txs;
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cerr << "Failed to parse signed tx data " << endl;
|
|
|
|
}
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
cerr << "deserialization of signed tx data NOT successful" << endl;
|
|
|
|
return string("deserialization of signed tx data NOT successful. "
|
|
|
|
"Maybe its not base64 encoded?");
|
|
|
|
}
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
std::vector<tools::wallet2::pending_tx> ptxs = signed_txs.ptx;
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.insert({"txs", mstch::array{}});
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (tools::wallet2::pending_tx& ptx: ptxs)
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map tx_context = construct_tx_context(ptx.tx, 1);
|
2016-09-07 06:50:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (boost::get<bool>(tx_context["has_error"]))
|
|
|
|
{
|
|
|
|
return boost::get<string>(tx_context["error_msg"]);
|
|
|
|
}
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["tx_prv_key"] = fmt::format("{:s}", ptx.tx_key);
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array destination_addresses;
|
|
|
|
vector<uint64_t> real_ammounts;
|
|
|
|
uint64_t outputs_xmr_sum {0};
|
2016-10-11 06:52:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// destiantion address for this tx
|
|
|
|
for (tx_destination_entry& a_dest: ptx.construction_data.splitted_dsts)
|
2016-10-13 05:54:16 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
//stealth_address_amount.insert({dest.addr, dest.amount});
|
|
|
|
//cout << get_account_address_as_str(testnet, a_dest.addr) << endl;
|
|
|
|
//address_amounts.push_back(a_dest.amount);
|
|
|
|
|
|
|
|
destination_addresses.push_back(
|
|
|
|
mstch::map {
|
|
|
|
{"dest_address" , get_account_address_as_str(testnet, a_dest.addr)},
|
|
|
|
{"dest_amount" , xmreg::xmr_amount_to_str(a_dest.amount)},
|
|
|
|
{"is_this_change" , false}
|
|
|
|
}
|
|
|
|
);
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
outputs_xmr_sum += a_dest.amount;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
real_ammounts.push_back(a_dest.amount);
|
|
|
|
}
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get change address and amount info
|
|
|
|
if (ptx.construction_data.change_dts.amount > 0)
|
|
|
|
{
|
|
|
|
destination_addresses.push_back(
|
|
|
|
mstch::map {
|
|
|
|
{"dest_address" , get_account_address_as_str(testnet, ptx.construction_data.change_dts.addr)},
|
|
|
|
{"dest_amount" , xmreg::xmr_amount_to_str(ptx.construction_data.change_dts.amount)},
|
|
|
|
{"is_this_change" , true}
|
|
|
|
}
|
|
|
|
);
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
real_ammounts.push_back(ptx.construction_data.change_dts.amount);
|
|
|
|
};
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context["outputs_xmr_sum"] = xmreg::xmr_amount_to_str(outputs_xmr_sum);
|
2016-10-21 06:25:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_context.insert({"dest_infos", destination_addresses});
|
2016-10-11 06:52:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get reference to inputs array created of the tx
|
|
|
|
mstch::array& outputs = boost::get<mstch::array>(tx_context["outputs"]);
|
2016-10-11 06:52:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// show real output amount for ringct outputs.
|
|
|
|
// otherwise its only 0.000000000
|
|
|
|
for (size_t i = 0; i < outputs.size(); ++i)
|
2016-10-24 01:51:53 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map& output_map = boost::get<mstch::map>(outputs.at(i));
|
2016-10-26 10:53:35 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string& out_amount_str = boost::get<string>(output_map["amount"]);
|
2016-10-11 06:52:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << boost::get<string>(output_map["out_pub_key"])
|
|
|
|
// <<", " << out_amount_str << endl;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t output_amount;
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (parse_amount(output_amount, out_amount_str))
|
|
|
|
{
|
|
|
|
if (output_amount == 0)
|
|
|
|
{
|
|
|
|
out_amount_str = xmreg::xmr_amount_to_str(real_ammounts.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get public keys of real outputs
|
|
|
|
vector<string> real_output_pub_keys;
|
|
|
|
vector<uint64_t> real_output_indices;
|
|
|
|
vector<uint64_t> real_amounts;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t inputs_xmr_sum {0};
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const tx_source_entry& tx_source: ptx.construction_data.sources)
|
|
|
|
{
|
|
|
|
transaction real_source_tx;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t index_of_real_output = tx_source.outputs[tx_source.real_output].first;
|
2016-10-11 06:52:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_source_amount = (tx_source.rct ? 0 : tx_source.amount);
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_out_index real_toi;
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// get tx of the real output
|
|
|
|
real_toi = core_storage->get_db()
|
|
|
|
.get_output_tx_and_index(tx_source_amount, index_of_real_output);
|
|
|
|
}
|
|
|
|
catch (const OUTPUT_DNE& e)
|
|
|
|
{
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string out_msg = fmt::format(
|
|
|
|
"Output with amount {:d} and index {:d} does not exist!",
|
|
|
|
tx_source_amount, index_of_real_output
|
|
|
|
);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << out_msg << endl;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return string(out_msg);
|
|
|
|
}
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(real_toi.first, real_source_tx))
|
2016-10-13 05:54:16 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "Cant get tx in blockchain: " << real_toi.first << endl;
|
|
|
|
return string("Cant get tx: " + pod_to_hex(real_toi.first));
|
2016-10-13 05:54:16 +00:00
|
|
|
}
|
2016-05-09 04:07:10 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details real_txd = get_tx_details(real_source_tx);
|
2016-10-11 06:52:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
public_key real_out_pub_key
|
|
|
|
= real_txd.output_pub_keys[tx_source.real_output_in_tx_index].first.key;
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
real_output_pub_keys.push_back(
|
|
|
|
REMOVE_HASH_BRAKETS(fmt::format("{:s}",real_out_pub_key))
|
|
|
|
);
|
2016-10-06 04:53:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
real_output_indices.push_back(tx_source.real_output);
|
|
|
|
real_amounts.push_back(tx_source.amount);
|
2016-10-06 04:53:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
inputs_xmr_sum += tx_source.amount;
|
|
|
|
}
|
2016-10-07 05:36:34 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// mark that we have signed tx data for use in mstch
|
|
|
|
tx_context["have_raw_tx"] = true;
|
2016-10-07 05:36:34 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// provide total mount of inputs xmr
|
|
|
|
tx_context["inputs_xmr_sum"] = xmreg::xmr_amount_to_str(inputs_xmr_sum);
|
2016-10-07 05:36:34 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get reference to inputs array created of the tx
|
|
|
|
mstch::array& inputs = boost::get<mstch::array>(tx_context["inputs"]);
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t input_idx {0};
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// mark which mixin is real in each input's mstch context
|
|
|
|
for (mstch::node& input_node: inputs)
|
|
|
|
{
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map& input_map = boost::get<mstch::map>(input_node);
|
2016-12-31 02:34:00 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// show input amount
|
|
|
|
string& amount = boost::get<string>(
|
|
|
|
boost::get<mstch::map>(input_node)["amount"]
|
|
|
|
);
|
2016-10-07 05:36:34 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
amount = xmreg::xmr_amount_to_str(real_amounts.at(input_idx));
|
2016-10-07 05:36:34 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if key images are spend or not
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string& in_key_img_str = boost::get<string>(
|
|
|
|
boost::get<mstch::map>(input_node)["in_key_img"]
|
|
|
|
);
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
key_image key_imgage;
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (epee::string_tools::hex_to_pod(in_key_img_str, key_imgage))
|
|
|
|
{
|
|
|
|
input_map["already_spent"] = core_storage->get_db().has_key_image(key_imgage);
|
|
|
|
}
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// mark real mixings
|
2016-10-06 04:53:33 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array& mixins = boost::get<mstch::array>(
|
|
|
|
boost::get<mstch::map>(input_node)["mixins"]
|
|
|
|
);
|
2016-10-06 00:41:43 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (mstch::node& mixin_node: mixins)
|
|
|
|
{
|
|
|
|
mstch::map& mixin = boost::get<mstch::map>(mixin_node);
|
2016-10-05 07:29:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string mix_pub_key_str = boost::get<string>(mixin["mix_pub_key"]);
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << mix_pub_key_str << endl;
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (std::find(
|
|
|
|
real_output_pub_keys.begin(),
|
|
|
|
real_output_pub_keys.end(),
|
|
|
|
mix_pub_key_str) != real_output_pub_keys.end())
|
|
|
|
{
|
|
|
|
mixin["mix_is_it_real"] = true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++input_idx;
|
|
|
|
}
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// mark real mixing in the mixins timescale graph
|
|
|
|
mark_real_mixins_on_timescales(real_output_indices, tx_context);
|
2016-12-28 02:34:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
boost::get<mstch::array>(context["txs"]).push_back(tx_context);
|
|
|
|
}
|
2016-05-09 04:07:10 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
map<string, string> partials {
|
|
|
|
{"tx_details", template_file["tx_details"]},
|
|
|
|
};
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(full_page, context, partials);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-05-09 03:44:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_pushrawtx(string raw_tx_data, string action)
|
2016-10-11 04:01:46 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
clean_post_data(raw_tx_data);
|
|
|
|
|
|
|
|
string decoded_raw_tx_data = epee::string_encoding::base64_decode(raw_tx_data);
|
2016-10-11 04:01:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const size_t magiclen = strlen(SIGNED_TX_PREFIX);
|
2016-10-11 04:01:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string data_prefix = xmreg::make_printable(decoded_raw_tx_data.substr(0, magiclen));
|
2016-10-11 04:01:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalize page template context map
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"have_raw_tx" , true},
|
|
|
|
{"has_error" , false},
|
|
|
|
{"error_msg" , string {}},
|
|
|
|
{"data_prefix" , data_prefix},
|
2016-10-14 04:31:48 +00:00
|
|
|
};
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("txs", mstch::array{});
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add header and footer
|
|
|
|
string full_page = template_file["pushrawtx"];
|
|
|
|
|
|
|
|
add_css_style(context);
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (strncmp(decoded_raw_tx_data.c_str(), SIGNED_TX_PREFIX, magiclen) != 0)
|
2016-10-11 04:01:46 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
string error_msg = fmt::format("The data does not appear to be signed raw tx! Data prefix: {:s}",
|
|
|
|
data_prefix);
|
2016-10-14 04:31:48 +00:00
|
|
|
|
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
2016-10-11 04:01:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (this->enable_pusher == false)
|
2016-10-25 23:35:46 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
string error_msg = fmt::format(
|
|
|
|
"Pushing disabled!\n "
|
|
|
|
"Run explorer with --enable-pusher flag to enable it.");
|
2016-10-25 23:35:46 +00:00
|
|
|
|
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
2016-10-25 23:35:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool r {false};
|
2016-10-11 04:01:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string s = decoded_raw_tx_data.substr(magiclen);
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
::tools::wallet2::signed_tx_set signed_txs;
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
std::istringstream iss(s);
|
|
|
|
boost::archive::portable_binary_iarchive ar(iss);
|
|
|
|
ar >> signed_txs;
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
r = true;
|
2016-10-11 04:01:46 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
catch (...)
|
2016-11-24 01:59:58 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << "Failed to parse signed tx data " << endl;
|
2016-11-24 01:59:58 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
if (!r)
|
2016-10-11 04:01:46 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
string error_msg = fmt::format("Deserialization of signed tx data NOT successful! "
|
|
|
|
"Maybe its not base64 encoded?");
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2016-11-23 22:11:23 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array& txs = boost::get<mstch::array>(context["txs"]);
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
std::vector<tools::wallet2::pending_tx> ptx_vector = signed_txs.ptx;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// actually commit the transactions
|
|
|
|
while (!ptx_vector.empty())
|
|
|
|
{
|
|
|
|
tools::wallet2::pending_tx& ptx = ptx_vector.back();
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(ptx.tx);
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string tx_hash_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", txd.hash));
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map tx_cd_data {
|
|
|
|
{"tx_hash" , tx_hash_str}
|
|
|
|
};
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check in mempool already contains tx to be submited
|
2017-06-02 02:14:42 +00:00
|
|
|
vector<MempoolStatus::mempool_tx> found_mempool_txs;
|
2017-05-04 00:52:52 +00:00
|
|
|
|
|
|
|
search_mempool(txd.hash, found_mempool_txs);
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!found_mempool_txs.empty())
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Tx already exist in the mempool: {:s}\n",
|
|
|
|
tx_hash_str);
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if tx to be submited already exists in the blockchain
|
|
|
|
if (core_storage->have_tx(txd.hash))
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Tx already exist in the blockchain: {:s}\n",
|
|
|
|
tx_hash_str);
|
2017-02-28 07:10:50 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if any key images of the tx to be submited are already spend
|
|
|
|
vector<key_image> key_images_spent;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const txin_to_key& tx_in: txd.input_key_imgs)
|
|
|
|
{
|
|
|
|
if (core_storage->have_tx_keyimg_as_spent(tx_in.k_image))
|
|
|
|
key_images_spent.push_back(tx_in.k_image);
|
|
|
|
}
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!key_images_spent.empty())
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Tx with hash {:s} has already spent inputs\n",
|
|
|
|
tx_hash_str);
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (key_image& k_img: key_images_spent)
|
|
|
|
{
|
|
|
|
error_msg += REMOVE_HASH_BRAKETS(fmt::format("{:s}", k_img));
|
|
|
|
error_msg += "</br>";
|
|
|
|
}
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string rpc_error_msg;
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (this->enable_pusher == false)
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format(
|
|
|
|
"Pushing signed transactions is disabled. "
|
|
|
|
"Run explorer with --enable-pusher flag to enable it.\n");
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!rpc.commit_tx(ptx, rpc_error_msg))
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format(
|
|
|
|
"Submitting signed tx {:s} to daemon failed: {:s}\n",
|
|
|
|
tx_hash_str, rpc_error_msg);
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2017-01-01 01:51:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-01 01:51:03 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txs.push_back(tx_cd_data);
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if no exception, remove element from vector
|
|
|
|
ptx_vector.pop_back();
|
|
|
|
}
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
2016-11-28 03:03:04 +00:00
|
|
|
return mstch::render(full_page, context);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_rawkeyimgs()
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalize page template context map
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet},
|
|
|
|
};
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["rawkeyimgs"], context);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_rawoutputkeys()
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalize page template context map
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet}
|
|
|
|
};
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-11-28 03:03:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["rawoutputkeys"], context);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-10-11 04:01:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_checkrawkeyimgs(string raw_data, string viewkey_str)
|
|
|
|
{
|
2016-10-14 04:31:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
clean_post_data(raw_data);
|
2016-10-11 04:01:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove white characters
|
|
|
|
boost::trim(viewkey_str);
|
2016-09-18 02:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string decoded_raw_data = epee::string_encoding::base64_decode(raw_data);
|
|
|
|
secret_key prv_view_key;
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalize page template context map
|
|
|
|
mstch::map context{
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"has_error" , false},
|
|
|
|
{"error_msg" , string{}},
|
|
|
|
};
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add header and footer
|
|
|
|
string full_page = template_file["checkrawkeyimgs"];
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (viewkey_str.empty())
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("View key not given. Cant decode "
|
|
|
|
"the key image data without it!");
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-11-17 06:11:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_secret_key(viewkey_str, prv_view_key))
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Cant parse the private key: " + viewkey_str);
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC);
|
2016-11-17 08:01:41 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string data_prefix = xmreg::make_printable(decoded_raw_data.substr(0, magiclen));
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["data_prefix"] = data_prefix;
|
2016-11-17 08:01:41 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!strncmp(decoded_raw_data.c_str(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen) == 0)
|
2016-10-24 04:12:40 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
string error_msg = fmt::format("This does not seem to be key image export data.");
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-10-24 06:22:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-10-24 06:22:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// decrypt key images data using private view key
|
|
|
|
decoded_raw_data = xmreg::decrypt(
|
|
|
|
std::string(decoded_raw_data, magiclen),
|
|
|
|
prv_view_key, true);
|
2016-10-24 06:22:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (decoded_raw_data.empty())
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Failed to authenticate key images data. "
|
|
|
|
"Maybe wrong viewkey was porvided?");
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// header is public spend and keys
|
|
|
|
const size_t header_lenght = 2 * sizeof(crypto::public_key);
|
|
|
|
const size_t key_img_size = sizeof(crypto::key_image);
|
|
|
|
const size_t record_lenght = key_img_size + sizeof(crypto::signature);
|
|
|
|
const size_t chacha_length = sizeof(crypto::chacha8_key);
|
2016-10-26 01:58:51 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (decoded_raw_data.size() < header_lenght)
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Bad data size from submitted key images raw data.");
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-11-28 03:35:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get xmr address stored in this key image file
|
|
|
|
const account_public_address* xmr_address =
|
|
|
|
reinterpret_cast<const account_public_address*>(
|
|
|
|
decoded_raw_data.data());
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.insert({"address" , REMOVE_HASH_BRAKETS(xmreg::print_address(*xmr_address, testnet))});
|
|
|
|
context.insert({"viewkey" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", prv_view_key))});
|
|
|
|
context.insert({"has_total_xmr" , false});
|
|
|
|
context.insert({"total_xmr" , string{}});
|
|
|
|
context.insert({"key_imgs" , mstch::array{}});
|
2016-11-29 01:21:32 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
size_t no_key_images = (decoded_raw_data.size() - header_lenght) / record_lenght;
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//vector<pair<crypto::key_image, crypto::signature>> signed_key_images;
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array& key_imgs_ctx = boost::get<mstch::array>(context["key_imgs"]);
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (size_t n = 0; n < no_key_images; ++n)
|
|
|
|
{
|
|
|
|
const char* record_ptr = decoded_raw_data.data() + header_lenght + n * record_lenght;
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::key_image key_image
|
|
|
|
= *reinterpret_cast<const crypto::key_image*>(record_ptr);
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::signature signature
|
|
|
|
= *reinterpret_cast<const crypto::signature*>(record_ptr + key_img_size);
|
2016-11-29 01:21:32 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map key_img_info {
|
|
|
|
{"key_no" , fmt::format("{:03d}", n)},
|
2017-05-09 04:00:32 +00:00
|
|
|
{"key_image" , pod_to_hex(key_image)},
|
2017-04-28 07:24:19 +00:00
|
|
|
{"signature" , fmt::format("{:s}", signature)},
|
|
|
|
{"address" , xmreg::print_address(*xmr_address, testnet)},
|
|
|
|
{"is_spent" , core_storage->have_tx_keyimg_as_spent(key_image)},
|
|
|
|
{"tx_hash" , string{}}
|
|
|
|
};
|
2016-11-29 01:21:32 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
key_imgs_ctx.push_back(key_img_info);
|
2016-12-05 02:46:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (size_t n = 0; n < no_key_images; ++n)
|
2016-12-05 02:46:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_checkcheckrawoutput(string raw_data, string viewkey_str)
|
|
|
|
{
|
|
|
|
clean_post_data(raw_data);
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove white characters
|
|
|
|
boost::trim(viewkey_str);
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string decoded_raw_data = epee::string_encoding::base64_decode(raw_data);
|
|
|
|
secret_key prv_view_key;
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalize page template context map
|
|
|
|
mstch::map context{
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"has_error" , false},
|
|
|
|
{"error_msg" , string{}}
|
|
|
|
};
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add header and footer
|
|
|
|
string full_page = template_file["checkoutputkeys"];
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (viewkey_str.empty())
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("View key not given. Cant decode "
|
|
|
|
"the outputs data without it!");
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_secret_key(viewkey_str, prv_view_key))
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Cant parse the private key: " + viewkey_str);
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-12-05 23:48:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const size_t magiclen = strlen(OUTPUT_EXPORT_FILE_MAGIC);
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string data_prefix = xmreg::make_printable(decoded_raw_data.substr(0, magiclen));
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["data_prefix"] = data_prefix;
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!strncmp(decoded_raw_data.c_str(), OUTPUT_EXPORT_FILE_MAGIC, magiclen) == 0)
|
2016-12-01 02:28:54 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
string error_msg = fmt::format("This does not seem to be output keys export data.");
|
2016-12-01 02:28:54 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-12-01 02:28:54 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-12-01 02:28:54 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// decrypt key images data using private view key
|
|
|
|
decoded_raw_data = xmreg::decrypt(
|
|
|
|
std::string(decoded_raw_data, magiclen),
|
|
|
|
prv_view_key, true);
|
2016-12-01 02:28:54 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (decoded_raw_data.empty())
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Failed to authenticate outputs data. "
|
|
|
|
"Maybe wrong viewkey was porvided?");
|
2016-12-01 02:28:54 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-12-01 02:28:54 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
2016-12-01 02:28:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// header is public spend and keys
|
|
|
|
const size_t header_lenght = 2 * sizeof(crypto::public_key);
|
|
|
|
|
|
|
|
// get xmr address stored in this key image file
|
|
|
|
const account_public_address* xmr_address =
|
|
|
|
reinterpret_cast<const account_public_address*>(
|
|
|
|
decoded_raw_data.data());
|
|
|
|
|
|
|
|
context.insert({"address" , REMOVE_HASH_BRAKETS(xmreg::print_address(*xmr_address, testnet))});
|
|
|
|
context.insert({"viewkey" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", prv_view_key))});
|
|
|
|
context.insert({"has_total_xmr" , false});
|
|
|
|
context.insert({"total_xmr" , string{}});
|
|
|
|
context.insert({"output_keys" , mstch::array{}});
|
|
|
|
|
|
|
|
mstch::array& output_keys_ctx = boost::get<mstch::array>(context["output_keys"]);
|
2016-12-05 23:48:36 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
std::vector<tools::wallet2::transfer_details> outputs;
|
|
|
|
|
|
|
|
try
|
2016-12-05 23:48:36 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
std::string body(decoded_raw_data, header_lenght);
|
|
|
|
std::stringstream iss;
|
|
|
|
iss << body;
|
|
|
|
boost::archive::portable_binary_iarchive ar(iss);
|
|
|
|
|
|
|
|
ar >> outputs;
|
2016-12-01 01:11:31 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//size_t n_outputs = m_wallet->import_outputs(outputs);
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Failed to import outputs: {:s}", e.what());
|
2016-12-05 23:48:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-12-05 23:48:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
2016-12-05 23:48:36 +00:00
|
|
|
}
|
2016-12-01 01:11:31 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t total_xmr {0};
|
|
|
|
uint64_t output_no {0};
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["are_key_images_known"] = false;
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const tools::wallet2::transfer_details& td: outputs)
|
2016-12-01 01:11:31 +00:00
|
|
|
{
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const transaction_prefix& txp = td.m_tx;
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txout_to_key txout_key = boost::get<txout_to_key>(
|
|
|
|
txp.vout[td.m_internal_output_index].target);
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t xmr_amount = td.amount();
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if the output is RingCT, i.e., tx version is 2
|
|
|
|
// need to decode its amount
|
2017-05-09 04:19:23 +00:00
|
|
|
if (td.is_rct())
|
2017-04-28 07:24:19 +00:00
|
|
|
{
|
|
|
|
// get tx associated with the given output
|
|
|
|
transaction tx;
|
2016-10-24 06:22:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(td.m_txid, tx))
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format("Cant get tx of hash: {:s}", td.m_txid);
|
2016-10-24 06:22:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
2016-10-24 06:22:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
2016-10-24 06:22:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
public_key tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(tx);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-09 04:19:23 +00:00
|
|
|
// cointbase txs have amounts in plain sight.
|
|
|
|
// so use amount from ringct, only for non-coinbase txs
|
|
|
|
if (!is_coinbase(tx))
|
2017-04-28 07:24:19 +00:00
|
|
|
{
|
2016-10-24 06:22:26 +00:00
|
|
|
|
2017-05-09 04:19:23 +00:00
|
|
|
bool r = decode_ringct(tx.rct_signatures,
|
|
|
|
tx_pub_key,
|
|
|
|
prv_view_key,
|
|
|
|
td.m_internal_output_index,
|
|
|
|
tx.rct_signatures.ecdhInfo[td.m_internal_output_index].mask,
|
|
|
|
xmr_amount);
|
2016-10-26 01:54:07 +00:00
|
|
|
|
2017-05-09 04:19:23 +00:00
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
string error_msg = fmt::format(
|
|
|
|
"Cant decode RingCT for output: {:s}",
|
|
|
|
txout_key.key);
|
|
|
|
|
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = error_msg;
|
|
|
|
|
|
|
|
return mstch::render(full_page, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // if (!is_coinbase(tx))
|
|
|
|
|
|
|
|
} // if (td.is_rct())
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
uint64_t blk_timestamp = core_storage
|
|
|
|
->get_db().get_block_timestamp(td.m_block_height);
|
|
|
|
|
|
|
|
const key_image* output_key_img;
|
|
|
|
|
|
|
|
bool is_output_spent {false};
|
|
|
|
|
|
|
|
if (td.m_key_image_known)
|
|
|
|
{
|
|
|
|
//are_key_images_known
|
|
|
|
|
|
|
|
output_key_img = &td.m_key_image;
|
|
|
|
|
|
|
|
is_output_spent = core_storage->have_tx_keyimg_as_spent(*output_key_img);
|
|
|
|
|
|
|
|
context["are_key_images_known"] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mstch::map output_info {
|
|
|
|
{"output_no" , fmt::format("{:03d}", output_no)},
|
|
|
|
{"output_pub_key" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", txout_key.key))},
|
|
|
|
{"amount" , xmreg::xmr_amount_to_str(xmr_amount)},
|
|
|
|
{"tx_hash" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", td.m_txid))},
|
|
|
|
{"timestamp" , xmreg::timestamp_to_str_gm(blk_timestamp)},
|
|
|
|
{"is_spent" , is_output_spent},
|
|
|
|
{"is_ringct" , td.m_rct}
|
|
|
|
};
|
2016-10-26 01:54:07 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++output_no;
|
2016-10-26 01:54:07 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!is_output_spent)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
total_xmr += xmr_amount;
|
2016-10-24 06:22:26 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
output_keys_ctx.push_back(output_info);
|
2016-10-24 04:12:40 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
if (total_xmr > 0)
|
2016-10-26 01:58:51 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_total_xmr"] = true;
|
|
|
|
context["total_xmr"] = xmreg::xmr_amount_to_str(total_xmr);
|
2016-10-26 01:58:51 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
return mstch::render(full_page, context);;
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-10-26 01:58:51 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
search(string search_text)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove white characters
|
|
|
|
boost::trim(search_text);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string default_txt {"No such thing found: " + search_text};
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string result_html {default_txt};
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t search_str_length = search_text.length();
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// first let try searching for tx
|
|
|
|
result_html = show_tx(search_text);
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// nasty check if output is "Cant get" as a sign of
|
|
|
|
// a not found tx. Later need to think of something better.
|
|
|
|
if (result_html.find("Cant get") == string::npos)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
return result_html;
|
2016-10-24 04:12:40 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 00:41:44 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// first check if searching for block of given height
|
|
|
|
if (search_text.size() < 12)
|
|
|
|
{
|
|
|
|
uint64_t blk_height;
|
2016-09-18 02:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
blk_height = boost::lexical_cast<uint64_t>(search_text);
|
2016-09-27 00:41:44 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
result_html = show_block(blk_height);
|
2016-09-27 00:41:44 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// nasty check if output is "Cant get" as a sign of
|
|
|
|
// a not found tx. Later need to think of something better.
|
|
|
|
if (result_html.find("Cant get") == string::npos)
|
|
|
|
{
|
|
|
|
return result_html;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
cerr << fmt::format("Parsing {:s} into uint64_t failed", search_text)
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
}
|
2016-09-18 02:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if tx search not successful, check if we are looking
|
|
|
|
// for a block with given hash
|
|
|
|
result_html = show_block(search_text);
|
2016-09-27 23:44:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (result_html.find("Cant get") == string::npos)
|
2016-10-26 01:58:51 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
return result_html;
|
2016-10-26 01:58:51 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
result_html = default_txt;
|
2016-10-24 04:12:40 +00:00
|
|
|
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if monero address is given based on its length
|
|
|
|
// if yes, then we can only show its public components
|
|
|
|
if (search_str_length == 95)
|
|
|
|
{
|
|
|
|
// parse string representing given monero address
|
|
|
|
cryptonote::account_public_address address;
|
2016-11-23 22:11:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool testnet_addr {false};
|
2016-10-03 04:53:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (search_text[0] == '9' || search_text[0] == 'A')
|
|
|
|
testnet_addr = true;
|
2016-10-03 04:53:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_address(search_text, address, testnet_addr))
|
|
|
|
{
|
|
|
|
cerr << "Cant parse string address: " << search_text << endl;
|
|
|
|
return string("Cant parse address (probably incorrect format): ")
|
|
|
|
+ search_text;
|
|
|
|
}
|
2016-10-03 04:53:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return show_address_details(address, testnet_addr);
|
|
|
|
}
|
2016-10-03 04:53:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if integrated monero address is given based on its length
|
|
|
|
// if yes, then show its public components search tx based on encrypted id
|
|
|
|
if (search_str_length == 106)
|
|
|
|
{
|
2016-10-03 04:53:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cryptonote::account_public_address address;
|
2016-10-03 04:53:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool has_payment_id;
|
2016-09-28 02:21:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash8 encrypted_payment_id;
|
2016-09-27 23:44:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool testnet;
|
2016-09-18 02:12:40 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!get_account_integrated_address_from_str(address,
|
|
|
|
has_payment_id,
|
|
|
|
encrypted_payment_id,
|
|
|
|
testnet,
|
|
|
|
search_text))
|
|
|
|
{
|
|
|
|
cerr << "Cant parse string integerated address: " << search_text << endl;
|
|
|
|
return string("Cant parse address (probably incorrect format): ")
|
|
|
|
+ search_text;
|
|
|
|
}
|
2016-05-10 10:21:20 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return show_integrated_address_details(address, encrypted_payment_id, testnet);
|
|
|
|
}
|
2016-04-24 03:49:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// all_possible_tx_hashes was field using custom lmdb database
|
|
|
|
// it was dropped, so all_possible_tx_hashes will be alwasy empty
|
|
|
|
// for now
|
|
|
|
vector<pair<string, vector<string>>> all_possible_tx_hashes;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
result_html = show_search_results(search_text, all_possible_tx_hashes);
|
2016-04-28 05:17:55 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return result_html;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
show_address_details(const account_public_address& address, bool testnet = false)
|
|
|
|
{
|
2016-04-24 03:49:42 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string address_str = xmreg::print_address(address, testnet);
|
|
|
|
string pub_viewkey_str = fmt::format("{:s}", address.m_view_public_key);
|
|
|
|
string pub_spendkey_str = fmt::format("{:s}", address.m_spend_public_key);
|
2016-05-09 23:44:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map context {
|
|
|
|
{"xmr_address" , REMOVE_HASH_BRAKETS(address_str)},
|
|
|
|
{"public_viewkey" , REMOVE_HASH_BRAKETS(pub_viewkey_str)},
|
|
|
|
{"public_spendkey" , REMOVE_HASH_BRAKETS(pub_spendkey_str)},
|
|
|
|
{"is_integrated_addr" , false},
|
|
|
|
{"testnet" , testnet}
|
|
|
|
};
|
|
|
|
|
|
|
|
add_css_style(context);
|
|
|
|
|
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["address"], context);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ;
|
|
|
|
string
|
|
|
|
show_integrated_address_details(const account_public_address& address,
|
|
|
|
const crypto::hash8& encrypted_payment_id,
|
|
|
|
bool testnet = false)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string address_str = xmreg::print_address(address, testnet);
|
|
|
|
string pub_viewkey_str = fmt::format("{:s}", address.m_view_public_key);
|
|
|
|
string pub_spendkey_str = fmt::format("{:s}", address.m_spend_public_key);
|
|
|
|
string enc_payment_id_str = fmt::format("{:s}", encrypted_payment_id);
|
|
|
|
|
|
|
|
mstch::map context {
|
|
|
|
{"xmr_address" , REMOVE_HASH_BRAKETS(address_str)},
|
|
|
|
{"public_viewkey" , REMOVE_HASH_BRAKETS(pub_viewkey_str)},
|
|
|
|
{"public_spendkey" , REMOVE_HASH_BRAKETS(pub_spendkey_str)},
|
|
|
|
{"encrypted_payment_id" , REMOVE_HASH_BRAKETS(enc_payment_id_str)},
|
|
|
|
{"is_integrated_addr" , true},
|
|
|
|
{"testnet" , testnet}
|
|
|
|
};
|
|
|
|
|
|
|
|
add_css_style(context);
|
2016-04-24 03:42:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(template_file["address"], context);
|
|
|
|
}
|
2016-04-24 04:15:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
map<string, vector<string>>
|
|
|
|
search_txs(vector<transaction> txs, const string& search_text)
|
|
|
|
{
|
|
|
|
map<string, vector<string>> tx_hashes;
|
2016-04-24 04:15:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initlizte the map with empty results
|
|
|
|
tx_hashes["key_images"] = {};
|
|
|
|
tx_hashes["tx_public_keys"] = {};
|
|
|
|
tx_hashes["payments_id"] = {};
|
|
|
|
tx_hashes["encrypted_payments_id"] = {};
|
|
|
|
tx_hashes["output_public_keys"] = {};
|
2016-04-24 04:15:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const transaction& tx: txs)
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx);
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string tx_hash_str = pod_to_hex(txd.hash);
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if any key_image matches the search_text
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
vector<txin_to_key>::iterator it1 =
|
|
|
|
find_if(begin(txd.input_key_imgs), end(txd.input_key_imgs),
|
|
|
|
[&](const txin_to_key& key_img)
|
|
|
|
{
|
|
|
|
return pod_to_hex(key_img.k_image) == search_text;
|
|
|
|
});
|
2016-04-24 04:15:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (it1 != txd.input_key_imgs.end())
|
|
|
|
{
|
|
|
|
tx_hashes["key_images"].push_back(tx_hash_str);
|
|
|
|
}
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if tx_public_key matches the search_text
|
2016-04-24 03:42:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (pod_to_hex(txd.pk) == search_text)
|
|
|
|
{
|
|
|
|
tx_hashes["tx_public_keys"].push_back(tx_hash_str);
|
|
|
|
}
|
2016-07-22 09:36:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if payments_id matches the search_text
|
2016-07-22 09:36:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (pod_to_hex(txd.payment_id) == search_text)
|
|
|
|
{
|
|
|
|
tx_hashes["payment_id"].push_back(tx_hash_str);
|
|
|
|
}
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if encrypted_payments_id matches the search_text
|
2016-07-22 09:36:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (pod_to_hex(txd.payment_id8) == search_text)
|
|
|
|
{
|
|
|
|
tx_hashes["encrypted_payments_id"].push_back(tx_hash_str);
|
|
|
|
}
|
2016-07-22 09:36:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if output_public_keys matche the search_text
|
2016-07-22 09:36:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
vector<pair<txout_to_key, uint64_t>>::iterator it2 =
|
|
|
|
find_if(begin(txd.output_pub_keys), end(txd.output_pub_keys),
|
|
|
|
[&](const pair<txout_to_key, uint64_t>& tx_out_pk)
|
|
|
|
{
|
|
|
|
return pod_to_hex(tx_out_pk.first.key) == search_text;
|
|
|
|
});
|
2016-04-28 07:03:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (it2 != txd.output_pub_keys.end())
|
|
|
|
{
|
|
|
|
tx_hashes["output_public_keys"].push_back(tx_hash_str);
|
|
|
|
}
|
2016-04-28 07:03:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2016-05-22 04:25:39 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return tx_hashes;
|
|
|
|
|
|
|
|
}
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
show_search_results(const string& search_text,
|
|
|
|
const vector<pair<string, vector<string>>>& all_possible_tx_hashes)
|
|
|
|
{
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"search_text" , search_text},
|
|
|
|
{"no_results" , true},
|
|
|
|
{"to_many_results" , false}
|
|
|
|
};
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const pair<string, vector<string>>& found_txs: all_possible_tx_hashes)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// define flag, e.g., has_key_images denoting that
|
|
|
|
// tx hashes for key_image searched were found
|
|
|
|
context.insert({"has_" + found_txs.first, !found_txs.second.empty()});
|
|
|
|
|
|
|
|
// cout << "found_txs.first: " << found_txs.first << endl;
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// insert new array based on what we found to context if not exist
|
|
|
|
pair< mstch::map::iterator, bool> res
|
|
|
|
= context.insert({found_txs.first, mstch::array{}});
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!found_txs.second.empty())
|
2016-10-04 05:05:45 +00:00
|
|
|
{
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_i {0};
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for each found tx_hash, get the corresponding tx
|
|
|
|
// and its details, and put into mstch for rendering
|
|
|
|
for (const string& tx_hash: found_txs.second)
|
|
|
|
{
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash tx_hash_pod;
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
epee::string_tools::hex_to_pod(tx_hash, tx_hash_pod);
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
transaction tx;
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t blk_height {0};
|
2016-04-28 04:18:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
int64_t blk_timestamp;
|
2016-04-28 04:18:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// first check in the blockchain
|
|
|
|
if (mcore->get_tx(tx_hash, tx))
|
|
|
|
{
|
2016-04-28 22:49:10 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get timestamp of the tx's block
|
|
|
|
blk_height = core_storage
|
|
|
|
->get_db().get_tx_block_height(tx_hash_pod);
|
|
|
|
|
|
|
|
blk_timestamp = core_storage
|
|
|
|
->get_db().get_block_timestamp(blk_height);
|
2016-04-28 22:49:10 +00:00
|
|
|
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// check in mempool if tx_hash not found in the
|
|
|
|
// blockchain
|
2017-06-02 02:14:42 +00:00
|
|
|
vector<MempoolStatus::mempool_tx> found_txs;
|
2017-05-04 00:52:52 +00:00
|
|
|
|
|
|
|
search_mempool(tx_hash_pod, found_txs);
|
2016-04-30 09:23:37 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!found_txs.empty())
|
|
|
|
{
|
|
|
|
// there should be only one tx found
|
2017-06-02 02:14:42 +00:00
|
|
|
tx = found_txs.at(0).tx;
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return string("Cant get tx of hash (show_search_results): " + tx_hash);
|
|
|
|
}
|
2016-04-28 22:49:10 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// tx in mempool have no blk_timestamp
|
|
|
|
// but can use their recive time
|
2017-06-02 02:14:42 +00:00
|
|
|
blk_timestamp = found_txs.at(0).info.receive_time;
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx);
|
2016-05-28 05:05:51 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map txd_map = txd.get_mstch_map();
|
2016-05-28 05:05:51 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add the timestamp to tx mstch map
|
|
|
|
txd_map.insert({"timestamp", xmreg::timestamp_to_str_gm(blk_timestamp)});
|
2016-05-28 05:05:51 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
boost::get<mstch::array>((res.first)->second).push_back(txd_map);
|
|
|
|
|
|
|
|
// dont show more than 500 results
|
|
|
|
if (tx_i > 500)
|
|
|
|
{
|
|
|
|
context["to_many_results"] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++tx_i;
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if found something, set this flag to indicate this fact
|
|
|
|
context["no_results"] = false;
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add header and footer
|
|
|
|
string full_page = template_file["search_results"];
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// read partial for showing details of tx(s) found
|
|
|
|
map<string, string> partials {
|
|
|
|
{"tx_table_head", template_file["tx_table_header"]},
|
|
|
|
{"tx_table_row" , template_file["tx_table_row"]}
|
|
|
|
};
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
add_css_style(context);
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// render the page
|
|
|
|
return mstch::render(full_page, context, partials);
|
|
|
|
}
|
2016-05-10 03:04:08 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
/*
|
2017-05-11 03:38:29 +00:00
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
2017-04-28 07:24:19 +00:00
|
|
|
json
|
|
|
|
json_transaction(string tx_hash_str)
|
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data" , json {}}
|
|
|
|
};
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json& j_data = j_response["data"];
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// parse tx hash string to hash object
|
|
|
|
crypto::hash tx_hash;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant parse tx hash: {:s}", tx_hash_str);
|
|
|
|
return j_response;
|
|
|
|
}
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get transaction
|
|
|
|
transaction tx;
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// flag to indicate if tx is in mempool
|
|
|
|
bool found_in_mempool {false};
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for tx in blocks we get block timestamp
|
|
|
|
// for tx in mempool we get recievive time
|
|
|
|
uint64_t tx_timestamp {0};
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!find_tx(tx_hash, tx, found_in_mempool, tx_timestamp))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant find tx hash: {:s}", tx_hash_str);
|
|
|
|
return j_response;
|
|
|
|
}
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t block_height {0};
|
|
|
|
uint64_t is_coinbase_tx = is_coinbase(tx);
|
|
|
|
uint64_t no_confirmations {0};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (found_in_mempool == false)
|
|
|
|
{
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
block blk;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// get block cointaining this tx
|
|
|
|
block_height = core_storage->get_db().get_tx_block_height(tx_hash);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_block_by_height(block_height, blk))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant get block: {:d}", block_height);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_timestamp = blk.timestamp;
|
|
|
|
}
|
|
|
|
catch (const exception& e)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = fmt::format("Tx does not exist in blockchain, "
|
|
|
|
"but was there before: {:s}", tx_hash_str);
|
2017-04-28 05:45:30 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string blk_timestamp_utc = xmreg::timestamp_to_str_gm(tx_timestamp);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get the current blockchain height. Just to check
|
|
|
|
uint64_t bc_height = core_storage->get_current_blockchain_height();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx, is_coinbase_tx, block_height, bc_height);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json outputs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (const auto& output: txd.output_pub_keys)
|
|
|
|
{
|
|
|
|
outputs.push_back(json {
|
|
|
|
{"public_key", pod_to_hex(output.first.key)},
|
|
|
|
{"amount" , output.second}
|
|
|
|
});
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json inputs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-04 23:32:02 +00:00
|
|
|
for (const txin_to_key &in_key: txd.input_key_imgs)
|
2017-04-28 07:24:19 +00:00
|
|
|
{
|
2017-05-04 23:32:02 +00:00
|
|
|
|
|
|
|
// get absolute offsets of mixins
|
|
|
|
std::vector<uint64_t> absolute_offsets
|
|
|
|
= cryptonote::relative_output_offsets_to_absolute(
|
|
|
|
in_key.key_offsets);
|
|
|
|
|
|
|
|
// get public keys of outputs used in the mixins that match to the offests
|
|
|
|
std::vector<output_data_t> outputs;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
core_storage->get_db().get_output_key(in_key.amount,
|
|
|
|
absolute_offsets,
|
|
|
|
outputs);
|
|
|
|
}
|
|
|
|
catch (const OUTPUT_DNE &e)
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Failed to retrive outputs (mixins) used in key images";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
inputs.push_back(json {
|
2017-05-04 23:32:02 +00:00
|
|
|
{"key_image" , pod_to_hex(in_key.k_image)},
|
|
|
|
{"amount" , in_key.amount},
|
|
|
|
{"mixins" , json {}}
|
2017-04-28 07:24:19 +00:00
|
|
|
});
|
2017-05-04 23:32:02 +00:00
|
|
|
|
|
|
|
json& mixins = inputs.back()["mixins"];
|
|
|
|
|
|
|
|
for (const output_data_t& output_data: outputs)
|
|
|
|
{
|
|
|
|
mixins.push_back(json {
|
|
|
|
{"public_key" , pod_to_hex(output_data.pubkey)},
|
|
|
|
{"block_no" , output_data.height},
|
|
|
|
});
|
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (found_in_mempool == false)
|
|
|
|
{
|
|
|
|
no_confirmations = txd.no_confirmations;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get tx from tx fetched. can be use to double check
|
|
|
|
// if what we return in the json response agrees with
|
|
|
|
// what tx_hash was requested
|
|
|
|
string tx_hash_str_again = pod_to_hex(get_transaction_hash(tx));
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get basic tx info
|
|
|
|
j_data = get_tx_json(tx, txd);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// append additional info from block, as we don't
|
|
|
|
// return block data in this function
|
|
|
|
j_data["timestamp"] = tx_timestamp;
|
|
|
|
j_data["timestamp_utc"] = blk_timestamp_utc;
|
|
|
|
j_data["block_height"] = block_height;
|
|
|
|
j_data["confirmations"] = no_confirmations;
|
|
|
|
j_data["outputs"] = outputs;
|
|
|
|
j_data["inputs"] = inputs;
|
|
|
|
j_data["current_height"] = bc_height;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_response["status"] = "success";
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-11 03:38:29 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
/*
|
2017-05-11 03:38:29 +00:00
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
|
|
|
json
|
|
|
|
json_rawtransaction(string tx_hash_str)
|
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data" , json {}}
|
|
|
|
};
|
|
|
|
|
|
|
|
json& j_data = j_response["data"];
|
|
|
|
|
|
|
|
// parse tx hash string to hash object
|
|
|
|
crypto::hash tx_hash;
|
|
|
|
|
|
|
|
if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant parse tx hash: {:s}", tx_hash_str);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get transaction
|
|
|
|
transaction tx;
|
|
|
|
|
|
|
|
// flag to indicate if tx is in mempool
|
|
|
|
bool found_in_mempool {false};
|
|
|
|
|
|
|
|
// for tx in blocks we get block timestamp
|
|
|
|
// for tx in mempool we get recievive time
|
|
|
|
uint64_t tx_timestamp {0};
|
|
|
|
|
|
|
|
if (!find_tx(tx_hash, tx, found_in_mempool, tx_timestamp))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant find tx hash: {:s}", tx_hash_str);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_in_mempool == false)
|
|
|
|
{
|
|
|
|
|
|
|
|
block blk;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// get block cointaining this tx
|
|
|
|
uint64_t block_height = core_storage->get_db().get_tx_block_height(tx_hash);
|
|
|
|
|
|
|
|
if (!mcore->get_block_by_height(block_height, blk))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant get block: {:d}", block_height);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const exception& e)
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = fmt::format("Tx does not exist in blockchain, "
|
|
|
|
"but was there before: {:s}",
|
|
|
|
tx_hash_str);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get raw tx json as in monero
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
j_data = json::parse(obj_to_json_str(tx));
|
|
|
|
}
|
|
|
|
catch (std::invalid_argument& e)
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Faild parsing raw tx data into json";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
j_response["status"] = "success";
|
|
|
|
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
2017-04-28 07:24:19 +00:00
|
|
|
json
|
|
|
|
json_block(string block_no_or_hash)
|
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data" , json {}}
|
|
|
|
};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json& j_data = j_response["data"];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t current_blockchain_height
|
|
|
|
= core_storage->get_current_blockchain_height();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t block_height {0};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash blk_hash;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
block blk;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (block_no_or_hash.length() <= 8)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// we have something that seems to be a block number
|
|
|
|
try
|
|
|
|
{
|
|
|
|
block_height = boost::lexical_cast<uint64_t>(block_no_or_hash);
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast& e)
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format(
|
|
|
|
"Cant parse block number: {:s}", block_no_or_hash);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (block_height > current_blockchain_height)
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format(
|
|
|
|
"Requested block is higher than blockchain:"
|
|
|
|
" {:d}, {:d}", block_height,current_blockchain_height);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_block_by_height(block_height, blk))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant get block: {:d}", block_height);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
blk_hash = core_storage->get_block_id_by_height(block_height);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
else if (block_no_or_hash.length() == 64)
|
|
|
|
{
|
|
|
|
// this seems to be block hash
|
|
|
|
if (!xmreg::parse_str_secret_key(block_no_or_hash, blk_hash))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant parse blk hash: {:s}", block_no_or_hash);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!core_storage->get_block_by_hash(blk_hash, blk))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant get block: {:s}", blk_hash);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
block_height = core_storage->get_db().get_block_height(blk_hash);
|
|
|
|
}
|
|
|
|
else
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
j_data["title"] = fmt::format("Cant find blk using search string: {:s}", block_no_or_hash);
|
2017-04-28 05:45:30 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block size in bytes
|
|
|
|
uint64_t blk_size = core_storage->get_db().get_block_size(block_height);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// miner reward tx
|
|
|
|
transaction coinbase_tx = blk.miner_tx;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// transcation in the block
|
|
|
|
vector<crypto::hash> tx_hashes = blk.tx_hashes;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// sum of all transactions in the block
|
|
|
|
uint64_t sum_fees = 0;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get tx details for the coinbase tx, i.e., miners reward
|
|
|
|
tx_details txd_coinbase = get_tx_details(blk.miner_tx, true,
|
|
|
|
block_height,
|
|
|
|
current_blockchain_height);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json j_txs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_txs.push_back(get_tx_json(coinbase_tx, txd_coinbase));
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for each transaction in the block
|
|
|
|
for (size_t i = 0; i < blk.tx_hashes.size(); ++i)
|
|
|
|
{
|
|
|
|
const crypto::hash &tx_hash = blk.tx_hashes.at(i);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get transaction
|
|
|
|
transaction tx;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(tx_hash, tx))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"]
|
|
|
|
= fmt::format("Cant get transactions in block: {:d}", block_height);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx, false,
|
|
|
|
block_height,
|
|
|
|
current_blockchain_height);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_txs.push_back(get_tx_json(tx, txd));
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// add fee to the rest
|
|
|
|
sum_fees += txd.fee;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_data = json {
|
|
|
|
{"block_height" , block_height},
|
|
|
|
{"hash" , pod_to_hex(blk_hash)},
|
|
|
|
{"timestamp" , blk.timestamp},
|
|
|
|
{"timestamp_utc" , xmreg::timestamp_to_str_gm(blk.timestamp)},
|
|
|
|
{"block_height" , block_height},
|
|
|
|
{"size" , blk_size},
|
|
|
|
{"txs" , j_txs},
|
|
|
|
{"current_height", current_blockchain_height}
|
|
|
|
};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_response["status"] = "success";
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
/*
|
2017-05-11 03:38:29 +00:00
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
|
|
|
json
|
|
|
|
json_rawblock(string block_no_or_hash)
|
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data" , json {}}
|
|
|
|
};
|
|
|
|
|
|
|
|
json& j_data = j_response["data"];
|
|
|
|
|
|
|
|
uint64_t current_blockchain_height
|
|
|
|
= core_storage->get_current_blockchain_height();
|
|
|
|
|
|
|
|
uint64_t block_height {0};
|
|
|
|
|
|
|
|
crypto::hash blk_hash;
|
|
|
|
|
|
|
|
block blk;
|
|
|
|
|
|
|
|
if (block_no_or_hash.length() <= 8)
|
|
|
|
{
|
|
|
|
// we have something that seems to be a block number
|
|
|
|
try
|
|
|
|
{
|
|
|
|
block_height = boost::lexical_cast<uint64_t>(block_no_or_hash);
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast& e)
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format(
|
|
|
|
"Cant parse block number: {:s}", block_no_or_hash);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block_height > current_blockchain_height)
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format(
|
|
|
|
"Requested block is higher than blockchain:"
|
|
|
|
" {:d}, {:d}", block_height,current_blockchain_height);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mcore->get_block_by_height(block_height, blk))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant get block: {:d}", block_height);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
blk_hash = core_storage->get_block_id_by_height(block_height);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (block_no_or_hash.length() == 64)
|
|
|
|
{
|
|
|
|
// this seems to be block hash
|
|
|
|
if (!xmreg::parse_str_secret_key(block_no_or_hash, blk_hash))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant parse blk hash: {:s}", block_no_or_hash);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!core_storage->get_block_by_hash(blk_hash, blk))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant get block: {:s}", blk_hash);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
block_height = core_storage->get_db().get_block_height(blk_hash);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant find blk using search string: {:s}", block_no_or_hash);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get raw tx json as in monero
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
j_data = json::parse(obj_to_json_str(blk));
|
|
|
|
}
|
|
|
|
catch (std::invalid_argument& e)
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Faild parsing raw blk data into json";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
j_response["status"] = "success";
|
|
|
|
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
2017-04-28 07:24:19 +00:00
|
|
|
json
|
|
|
|
json_transactions(string _page, string _limit)
|
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data", json {}}
|
|
|
|
};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json& j_data = j_response["data"];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// parse page and limit into numbers
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t page {0};
|
|
|
|
uint64_t limit {0};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
page = boost::lexical_cast<uint64_t>(_page);
|
|
|
|
limit = boost::lexical_cast<uint64_t>(_limit);
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast& e)
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format(
|
|
|
|
"Cant parse page and/or limit numbers: {:s}, {:s}", _page, _limit);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// enforce maximum number of blocks per page to 100
|
|
|
|
limit = limit > 100 ? 100 : limit;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//get current server timestamp
|
|
|
|
server_timestamp = std::time(nullptr);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t local_copy_server_timestamp = server_timestamp;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t height = core_storage->get_current_blockchain_height();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// calculate starting and ending block numbers to show
|
|
|
|
int64_t start_height = height - limit * (page + 1);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if start height is not below range
|
|
|
|
start_height = start_height < 0 ? 0 : start_height;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
int64_t end_height = start_height + limit - 1;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// loop index
|
|
|
|
int64_t i = end_height;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_data["blocks"] = json::array();
|
|
|
|
json& j_blocks = j_data["blocks"];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// iterate over last no_of_last_blocks of blocks
|
|
|
|
while (i >= start_height)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block at the given height i
|
|
|
|
block blk;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_block_by_height(i, blk))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = fmt::format("Cant get block: {:d}", i);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block size in bytes
|
|
|
|
double blk_size = core_storage->get_db().get_block_size(i);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
crypto::hash blk_hash = core_storage->get_block_id_by_height(i);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block age
|
|
|
|
pair<string, string> age = get_age(local_copy_server_timestamp, blk.timestamp);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_blocks.push_back(json {
|
|
|
|
{"height" , i},
|
|
|
|
{"hash" , pod_to_hex(blk_hash)},
|
|
|
|
{"age" , age.first},
|
|
|
|
{"size" , blk_size},
|
|
|
|
{"timestamp" , blk.timestamp},
|
|
|
|
{"timestamp_utc", xmreg::timestamp_to_str_gm(blk.timestamp)},
|
|
|
|
{"txs" , json::array()}
|
|
|
|
});
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json& j_txs = j_blocks.back()["txs"];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
list<cryptonote::transaction> blk_txs {blk.miner_tx};
|
|
|
|
list<crypto::hash> missed_txs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!core_storage->get_transactions(blk.tx_hashes, blk_txs, missed_txs))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = fmt::format("Cant get transactions in block: {:d}", i);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
(void) missed_txs;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for(auto it = blk_txs.begin(); it != blk_txs.end(); ++it)
|
|
|
|
{
|
|
|
|
const cryptonote::transaction &tx = *it;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const tx_details& txd = get_tx_details(tx, false, i, height);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_txs.push_back(get_tx_json(tx, txd));
|
|
|
|
}
|
|
|
|
|
|
|
|
--i;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_data["page"] = page;
|
|
|
|
j_data["limit"] = limit;
|
|
|
|
j_data["current_height"] = height;
|
2017-05-07 06:19:32 +00:00
|
|
|
|
2017-05-12 05:38:23 +00:00
|
|
|
j_data["total_page_no"] = limit > 0 ? (height / limit) : 0;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_response["status"] = "success";
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
/*
|
2017-04-28 05:45:30 +00:00
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
2017-04-28 07:24:19 +00:00
|
|
|
json
|
2017-05-10 00:42:06 +00:00
|
|
|
json_mempool(string _page, string _limit)
|
2017-04-28 07:24:19 +00:00
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data", json {}}
|
|
|
|
};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json& j_data = j_response["data"];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-10 00:42:06 +00:00
|
|
|
// parse page and limit into numbers
|
|
|
|
|
|
|
|
uint64_t page {0};
|
|
|
|
uint64_t limit {0};
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
page = boost::lexical_cast<uint64_t>(_page);
|
|
|
|
limit = boost::lexical_cast<uint64_t>(_limit);
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast& e)
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format(
|
|
|
|
"Cant parse page and/or limit numbers: {:s}, {:s}", _page, _limit);
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//get current server timestamp
|
|
|
|
server_timestamp = std::time(nullptr);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t local_copy_server_timestamp = server_timestamp;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t height = core_storage->get_current_blockchain_height();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-06-02 01:26:55 +00:00
|
|
|
// get mempool tx from mempoolstatus thread
|
|
|
|
vector<MempoolStatus::mempool_tx> mempool_data
|
|
|
|
= MempoolStatus::get_mempool_txs();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-10 00:42:06 +00:00
|
|
|
uint64_t no_mempool_txs = mempool_data.size();
|
|
|
|
|
|
|
|
// calculate starting and ending block numbers to show
|
2017-05-10 09:04:31 +00:00
|
|
|
int64_t start_height = limit * page;
|
2017-05-10 00:42:06 +00:00
|
|
|
|
|
|
|
int64_t end_height = start_height + limit;
|
|
|
|
|
|
|
|
end_height = end_height > no_mempool_txs ? no_mempool_txs : end_height;
|
|
|
|
|
2017-05-10 09:04:31 +00:00
|
|
|
// check if start height is not below range
|
|
|
|
start_height = start_height > end_height ? end_height - limit : start_height;
|
|
|
|
|
|
|
|
start_height = start_height < 0 ? 0 : start_height;
|
|
|
|
|
2017-05-10 00:42:06 +00:00
|
|
|
// loop index
|
2017-05-10 09:04:31 +00:00
|
|
|
int64_t i = start_height;
|
2017-05-10 00:42:06 +00:00
|
|
|
|
|
|
|
json j_txs = json::array();
|
|
|
|
|
|
|
|
// for each transaction in the memory pool in current page
|
2017-05-10 09:04:31 +00:00
|
|
|
while (i < end_height)
|
2017-04-28 07:24:19 +00:00
|
|
|
{
|
2017-06-02 02:14:42 +00:00
|
|
|
const MempoolStatus::mempool_tx* mempool_tx {nullptr};
|
2017-05-10 00:42:06 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-06-02 02:14:42 +00:00
|
|
|
mempool_tx = &(mempool_data.at(i));
|
2017-05-10 00:42:06 +00:00
|
|
|
}
|
|
|
|
catch (const std::out_of_range& e)
|
|
|
|
{
|
2017-05-10 00:49:59 +00:00
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = fmt::format("Getting mempool txs failed due to std::out_of_range");
|
|
|
|
|
|
|
|
return j_response;
|
2017-05-10 00:42:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
const tx_details& txd = get_tx_details(mempool_tx->tx, false, 1, height); // 1 is dummy here
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get basic tx info
|
2017-06-02 02:14:42 +00:00
|
|
|
json j_tx = get_tx_json(mempool_tx->tx, txd);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// we add some extra data, for mempool txs, such as recieve timestamp
|
2017-06-02 02:14:42 +00:00
|
|
|
j_tx["timestamp"] = mempool_tx->info.receive_time;
|
|
|
|
j_tx["timestamp_utc"] = xmreg::timestamp_to_str_gm(mempool_tx->info.receive_time);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-10 00:42:06 +00:00
|
|
|
j_txs.push_back(j_tx);
|
|
|
|
|
2017-05-10 09:04:31 +00:00
|
|
|
++i;
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-10 00:42:06 +00:00
|
|
|
j_data["txs"] = j_txs;
|
|
|
|
j_data["page"] = page;
|
|
|
|
j_data["limit"] = limit;
|
|
|
|
j_data["txs_no"] = no_mempool_txs;
|
|
|
|
j_data["total_page_no"] = limit > 0 ? (no_mempool_txs / limit) : 0;
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_response["status"] = "success";
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
/*
|
2017-05-10 01:06:06 +00:00
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
2017-04-28 07:24:19 +00:00
|
|
|
json
|
|
|
|
json_search(const string& search_text)
|
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data", json {}}
|
|
|
|
};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json& j_data = j_response["data"];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//get current server timestamp
|
|
|
|
server_timestamp = std::time(nullptr);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t local_copy_server_timestamp = server_timestamp;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t height = core_storage->get_current_blockchain_height();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t search_str_length = search_text.length();
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// first let check if the search_text matches any tx or block hash
|
|
|
|
if (search_str_length == 64)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// first check for tx
|
|
|
|
json j_tx = json_transaction(search_text);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (j_tx["status"] == "success")
|
|
|
|
{
|
|
|
|
j_response["data"] = j_tx["data"];
|
|
|
|
j_response["data"]["title"] = "transaction";
|
|
|
|
j_response["status"] = "success";
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// now check for block
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json j_block = json_block(search_text);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (j_block["status"] == "success")
|
|
|
|
{
|
|
|
|
j_response["data"] = j_block["data"];
|
|
|
|
j_response["data"]["title"] = "block";
|
|
|
|
j_response["status"] = "success";
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// now lets see if this is a block number
|
|
|
|
if (search_str_length <= 8)
|
|
|
|
{
|
|
|
|
json j_block = json_block(search_text);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (j_block["status"] == "success")
|
|
|
|
{
|
|
|
|
j_response["data"] = j_block["data"];
|
|
|
|
j_response["data"]["title"] = "block";
|
|
|
|
j_response["status"] = "success";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_data["title"] = "Nothing was found that matches search string: " + search_text;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json
|
|
|
|
json_outputs(string tx_hash_str,
|
|
|
|
string address_str,
|
|
|
|
string viewkey_str,
|
|
|
|
bool tx_prove = false)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
boost::trim(tx_hash_str);
|
|
|
|
boost::trim(address_str);
|
|
|
|
boost::trim(viewkey_str);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data", json {}}
|
|
|
|
};
|
|
|
|
|
|
|
|
json& j_data = j_response["data"];
|
|
|
|
|
|
|
|
|
|
|
|
if (tx_hash_str.empty())
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
2017-04-28 07:24:19 +00:00
|
|
|
j_response["message"] = "Tx hash not provided";
|
2017-04-28 05:45:30 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
if (address_str.empty())
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
2017-04-28 07:24:19 +00:00
|
|
|
j_response["message"] = "Monero address not provided";
|
2017-04-28 05:45:30 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (viewkey_str.empty())
|
|
|
|
{
|
|
|
|
if (!tx_prove)
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Viewkey not provided";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Tx private key not provided";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// parse tx hash string to hash object
|
|
|
|
crypto::hash tx_hash;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Cant parse tx hash: " + tx_hash_str;
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// parse string representing given monero address
|
|
|
|
cryptonote::account_public_address address;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_address(address_str, address, testnet))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Cant parse monero address: " + address_str;
|
|
|
|
return j_response;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// parse string representing given private key
|
|
|
|
crypto::secret_key prv_view_key;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!xmreg::parse_str_secret_key(viewkey_str, prv_view_key))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Cant parse view key or tx private key: "
|
|
|
|
+ viewkey_str;
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get transaction
|
|
|
|
transaction tx;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// flag to indicate if tx is in mempool
|
|
|
|
bool found_in_mempool {false};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for tx in blocks we get block timestamp
|
|
|
|
// for tx in mempool we get recievive time
|
|
|
|
uint64_t tx_timestamp {0};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!find_tx(tx_hash, tx, found_in_mempool, tx_timestamp))
|
|
|
|
{
|
|
|
|
j_data["title"] = fmt::format("Cant find tx hash: {:s}", tx_hash_str);
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
(void) tx_timestamp;
|
|
|
|
(void) found_in_mempool;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// public transaction key is combined with our viewkey
|
|
|
|
// to create, so called, derived key.
|
|
|
|
key_derivation derivation;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
public_key pub_key = tx_prove ? address.m_view_public_key : txd.pk;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
//cout << "txd.pk: " << pod_to_hex(txd.pk) << endl;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!generate_key_derivation(pub_key, prv_view_key, derivation))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Cant calculate key_derivation";
|
|
|
|
return j_response;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t output_idx {0};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
std::vector<uint64_t> money_transfered(tx.vout.size(), 0);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_data["outputs"] = json::array();
|
|
|
|
json& j_outptus = j_data["outputs"];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (pair<txout_to_key, uint64_t>& outp: txd.output_pub_keys)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get the tx output public key
|
|
|
|
// that normally would be generated for us,
|
|
|
|
// if someone had sent us some xmr.
|
|
|
|
public_key tx_pubkey;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
derive_public_key(derivation,
|
|
|
|
output_idx,
|
|
|
|
address.m_spend_public_key,
|
|
|
|
tx_pubkey);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// check if generated public key matches the current output's key
|
|
|
|
bool mine_output = (outp.first.key == tx_pubkey);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if mine output has RingCT, i.e., tx version is 2
|
|
|
|
if (mine_output && tx.version == 2)
|
|
|
|
{
|
|
|
|
// cointbase txs have amounts in plain sight.
|
|
|
|
// so use amount from ringct, only for non-coinbase txs
|
|
|
|
if (!is_coinbase(tx))
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initialize with regular amount
|
|
|
|
uint64_t rct_amount = money_transfered[output_idx];
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool r;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
r = decode_ringct(tx.rct_signatures,
|
|
|
|
pub_key,
|
|
|
|
prv_view_key,
|
|
|
|
output_idx,
|
|
|
|
tx.rct_signatures.ecdhInfo[output_idx].mask,
|
|
|
|
rct_amount);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
cerr << "\nshow_my_outputs: Cant decode ringCT! " << endl;
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
outp.second = rct_amount;
|
|
|
|
money_transfered[output_idx] = rct_amount;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // if (!is_coinbase(tx))
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // if (mine_output && tx.version == 2)
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_outptus.push_back(json {
|
|
|
|
{"output_pubkey", pod_to_hex(outp.first.key)},
|
|
|
|
{"amount" , outp.second},
|
|
|
|
{"match" , mine_output},
|
|
|
|
{"output_idx" , output_idx},
|
|
|
|
});
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++output_idx;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (pair<txout_to_key, uint64_t>& outp: txd.output_pub_keys)
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// return parsed values. can be use to double
|
|
|
|
// check if submited data in the request
|
|
|
|
// matches to what was used to produce response.
|
|
|
|
j_data["tx_hash"] = pod_to_hex(txd.hash);
|
|
|
|
j_data["address"] = pod_to_hex(address);
|
|
|
|
j_data["viewkey"] = pod_to_hex(prv_view_key);
|
|
|
|
j_data["tx_prove"] = tx_prove;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
j_response["status"] = "success";
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return j_response;
|
|
|
|
}
|
2017-05-11 04:17:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
|
|
|
json
|
|
|
|
json_networkinfo()
|
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data", json {}}
|
|
|
|
};
|
|
|
|
|
|
|
|
json& j_data = j_response["data"];
|
|
|
|
|
|
|
|
json j_info;
|
|
|
|
|
2017-05-15 06:19:57 +00:00
|
|
|
// get basic network info
|
2017-05-11 04:17:10 +00:00
|
|
|
if (!get_monero_network_info(j_info))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Cant get monero network info";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
2017-05-15 06:19:57 +00:00
|
|
|
uint64_t fee_estimated {0};
|
|
|
|
|
|
|
|
// get dynamic fee estimate from last 10 blocks
|
|
|
|
if (!get_dynamic_per_kb_fee_estimate(fee_estimated))
|
|
|
|
{
|
|
|
|
j_response["status"] = "error";
|
|
|
|
j_response["message"] = "Cant get dynamic fee esimate";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
j_info["fee_per_kb"] = fee_estimated;
|
|
|
|
|
2017-06-02 02:34:27 +00:00
|
|
|
j_info["tx_pool_size"] = MempoolStatus::mempool_no.load();
|
|
|
|
j_info["tx_pool_size_kbytes"] = MempoolStatus::mempool_size.load();
|
2017-05-25 06:20:58 +00:00
|
|
|
|
2017-05-11 04:17:10 +00:00
|
|
|
j_data = j_info;
|
|
|
|
|
|
|
|
j_response["status"] = "success";
|
|
|
|
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-19 09:50:12 +00:00
|
|
|
/*
|
|
|
|
* Lets use this json api convention for success and error
|
|
|
|
* https://labs.omniti.com/labs/jsend
|
|
|
|
*/
|
|
|
|
json
|
|
|
|
json_emission()
|
|
|
|
{
|
|
|
|
json j_response {
|
|
|
|
{"status", "fail"},
|
|
|
|
{"data", json {}}
|
|
|
|
};
|
|
|
|
|
|
|
|
json& j_data = j_response["data"];
|
|
|
|
|
|
|
|
json j_info;
|
|
|
|
|
|
|
|
// get basic network info
|
|
|
|
if (!CurrentBlockchainStatus::is_thread_running())
|
|
|
|
{
|
|
|
|
j_data["title"] = "Emission monitoring thread not enabled.";
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentBlockchainStatus::Emission current_values
|
|
|
|
= CurrentBlockchainStatus::get_emission();
|
|
|
|
|
|
|
|
string emission_blk_no = std::to_string(current_values.blk_no - 1);
|
|
|
|
string emission_coinbase = xmr_amount_to_str(current_values.coinbase, "{:0.3f}");
|
|
|
|
string emission_fee = xmr_amount_to_str(current_values.fee, "{:0.3f}");
|
|
|
|
|
|
|
|
j_data = json {
|
|
|
|
{"blk_no" , current_values.blk_no - 1},
|
|
|
|
{"coinbase", current_values.coinbase},
|
|
|
|
{"fee" , current_values.fee},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
j_response["status"] = "success";
|
|
|
|
|
|
|
|
return j_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
private:
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json
|
|
|
|
get_tx_json(const transaction& tx, const tx_details& txd)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
json j_tx {
|
|
|
|
{"tx_hash" , pod_to_hex(txd.hash)},
|
|
|
|
{"tx_fee" , txd.fee},
|
|
|
|
{"mixin" , txd.mixin_no},
|
|
|
|
{"tx_size" , txd.size},
|
|
|
|
{"xmr_outputs" , txd.xmr_outputs},
|
|
|
|
{"xmr_inputs" , txd.xmr_inputs},
|
|
|
|
{"tx_version" , txd.version},
|
|
|
|
{"rct_type" , tx.rct_signatures.type},
|
|
|
|
{"coinbase" , is_coinbase(tx)},
|
|
|
|
{"mixin" , txd.mixin_no},
|
|
|
|
{"extra" , txd.get_extra_str()},
|
|
|
|
{"payment_id" , (txd.payment_id != null_hash ? pod_to_hex(txd.payment_id) : "")},
|
|
|
|
{"payment_id8" , (txd.payment_id8 != null_hash8 ? pod_to_hex(txd.payment_id8) : "")},
|
|
|
|
};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return j_tx;
|
2017-04-28 05:45:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-15 06:19:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool
|
|
|
|
find_tx(const crypto::hash& tx_hash,
|
|
|
|
transaction& tx,
|
|
|
|
bool& found_in_mempool,
|
|
|
|
uint64_t& tx_timestamp)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
found_in_mempool = false;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(tx_hash, tx))
|
|
|
|
{
|
|
|
|
cerr << "Cant get tx in blockchain: " << tx_hash
|
|
|
|
<< ". \n Check mempool now" << endl;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
vector<MempoolStatus::mempool_tx> found_txs;
|
2017-05-04 00:52:52 +00:00
|
|
|
|
|
|
|
search_mempool(tx_hash, found_txs);
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!found_txs.empty())
|
|
|
|
{
|
|
|
|
// there should be only one tx found
|
2017-06-02 02:14:42 +00:00
|
|
|
tx = found_txs.at(0).tx;
|
2017-04-28 07:24:19 +00:00
|
|
|
found_in_mempool = true;
|
2017-06-02 02:14:42 +00:00
|
|
|
tx_timestamp = found_txs.at(0).info.receive_time;
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// tx is nowhere to be found :-(
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return true;
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
void
|
|
|
|
mark_real_mixins_on_timescales(
|
|
|
|
const vector<uint64_t>& real_output_indices,
|
|
|
|
mstch::map& tx_context)
|
|
|
|
{
|
|
|
|
// mark real mixing in the mixins timescale graph
|
|
|
|
mstch::array& mixins_timescales
|
|
|
|
= boost::get<mstch::array>(tx_context["timescales"]);
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t idx {0};
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (mstch::node& timescale_node: mixins_timescales)
|
|
|
|
{
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string& timescale = boost::get<string>(
|
|
|
|
boost::get<mstch::map>(timescale_node)["timescale"]
|
|
|
|
);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// claculated number of timescale points
|
|
|
|
// due to resolution, no of points might be lower than no of mixins
|
|
|
|
size_t no_points = std::count(timescale.begin(), timescale.end(), '*');
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
size_t point_to_find = real_output_indices.at(idx);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// adjust point to find based on total number of points
|
|
|
|
if (point_to_find >= no_points)
|
|
|
|
point_to_find = no_points - 1;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
boost::iterator_range<string::iterator> r
|
|
|
|
= boost::find_nth(timescale, "*", point_to_find);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
*(r.begin()) = 'R';
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
}
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::map
|
|
|
|
construct_tx_context(transaction tx, uint16_t with_ring_signatures = 0)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details txd = get_tx_details(tx);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
const crypto::hash& tx_hash = txd.hash;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string tx_hash_str = pod_to_hex(tx_hash);
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_blk_height {0};
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool tx_blk_found {false};
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
bool detailed_view {enable_mixins_details || static_cast<bool>(with_ring_signatures)};
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (core_storage->have_tx(tx_hash))
|
|
|
|
{
|
|
|
|
// currently get_tx_block_height seems to return a block hight
|
|
|
|
// +1. Before it was not like this.
|
|
|
|
tx_blk_height = core_storage->get_db().get_tx_block_height(tx_hash);
|
|
|
|
tx_blk_found = true;
|
|
|
|
}
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get block cointaining this tx
|
|
|
|
block blk;
|
2016-05-10 05:28:11 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (tx_blk_found && !mcore->get_block_by_height(tx_blk_height, blk))
|
|
|
|
{
|
|
|
|
cerr << "Cant get block: " << tx_blk_height << endl;
|
|
|
|
}
|
2017-02-22 07:03:19 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string tx_blk_height_str {"N/A"};
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// tx age
|
|
|
|
pair<string, string> age;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string blk_timestamp {"N/A"};
|
2016-10-04 05:05:45 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (tx_blk_found)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// calculate difference between tx and server timestamps
|
|
|
|
age = get_age(server_timestamp, blk.timestamp, FULL_AGE_FORMAT);
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
blk_timestamp = xmreg::timestamp_to_str_gm(blk.timestamp);
|
2016-05-10 03:04:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_blk_height_str = std::to_string(tx_blk_height);
|
2016-10-04 05:05:45 +00:00
|
|
|
}
|
2016-04-28 07:03:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// payments id. both normal and encrypted (payment_id8)
|
|
|
|
string pid_str = pod_to_hex(txd.payment_id);
|
|
|
|
string pid8_str = pod_to_hex(txd.payment_id8);
|
|
|
|
|
|
|
|
|
|
|
|
string tx_json = obj_to_json_str(tx);
|
|
|
|
|
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
mstch::map context {
|
|
|
|
{"testnet" , testnet},
|
|
|
|
{"tx_hash" , tx_hash_str},
|
|
|
|
{"tx_prefix_hash" , string{}},
|
|
|
|
{"tx_pub_key" , pod_to_hex(txd.pk)},
|
|
|
|
{"blk_height" , tx_blk_height_str},
|
|
|
|
{"tx_blk_height" , tx_blk_height},
|
|
|
|
{"tx_size" , fmt::format("{:0.4f}",
|
|
|
|
static_cast<double>(txd.size) / 1024.0)},
|
|
|
|
{"tx_fee" , xmreg::xmr_amount_to_str(txd.fee)},
|
|
|
|
{"tx_version" , txd.version},
|
|
|
|
{"blk_timestamp" , blk_timestamp},
|
|
|
|
{"blk_timestamp_uint" , blk.timestamp},
|
|
|
|
{"delta_time" , age.first},
|
|
|
|
{"inputs_no" , static_cast<uint64_t>(txd.input_key_imgs.size())},
|
|
|
|
{"has_inputs" , !txd.input_key_imgs.empty()},
|
|
|
|
{"outputs_no" , static_cast<uint64_t>(txd.output_pub_keys.size())},
|
|
|
|
{"has_payment_id" , txd.payment_id != null_hash},
|
|
|
|
{"has_payment_id8" , txd.payment_id8 != null_hash8},
|
|
|
|
{"confirmations" , txd.no_confirmations},
|
|
|
|
{"payment_id" , pid_str},
|
|
|
|
{"payment_id8" , pid8_str},
|
|
|
|
{"extra" , txd.get_extra_str()},
|
|
|
|
{"with_ring_signatures" , static_cast<bool>(
|
|
|
|
with_ring_signatures)},
|
|
|
|
{"tx_json" , tx_json},
|
|
|
|
{"is_ringct" , (tx.version > 1)},
|
|
|
|
{"rct_type" , tx.rct_signatures.type},
|
|
|
|
{"has_error" , false},
|
|
|
|
{"error_msg" , string("")},
|
|
|
|
{"have_raw_tx" , false},
|
|
|
|
{"show_more_details_link", true},
|
|
|
|
{"from_cache" , false},
|
|
|
|
{"construction_time" , string {}},
|
|
|
|
};
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string server_time_str = xmreg::timestamp_to_str_gm(server_timestamp, "%F");
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array inputs = mstch::array{};
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t input_idx {0};
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t inputs_xmr_sum {0};
|
|
|
|
|
|
|
|
// ringct inputs can be mixture of known amounts (when old outputs)
|
|
|
|
// are spent, and unknown umounts (makrked in explorer by '?') when
|
|
|
|
// ringct outputs are spent. thus we totalling input amounts
|
|
|
|
// in such case, we need to show sum of known umounts, and
|
|
|
|
// indicate that this is minium sum, as we dont know the unknown
|
|
|
|
// umounts.
|
|
|
|
bool have_any_unknown_amount {false};
|
2016-07-21 11:04:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t max_no_of_inputs_to_show {10};
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if a tx has more inputs than max_no_of_inputs_to_show,
|
|
|
|
// we only show 10 first.
|
|
|
|
bool show_part_of_inputs = (txd.input_key_imgs.size() > max_no_of_inputs_to_show);
|
|
|
|
|
|
|
|
// but if we show all details, i.e.,
|
|
|
|
// the show all inputs, regardless of their number
|
2017-04-28 05:45:30 +00:00
|
|
|
if (detailed_view)
|
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
show_part_of_inputs = false;
|
2017-04-28 05:45:30 +00:00
|
|
|
}
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
vector<vector<uint64_t>> mixin_timestamp_groups;
|
2017-02-22 07:03:19 +00:00
|
|
|
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// make timescale maps for mixins in input
|
|
|
|
for (const txin_to_key &in_key: txd.input_key_imgs)
|
|
|
|
{
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (show_part_of_inputs && (input_idx > max_no_of_inputs_to_show))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get absolute offsets of mixins
|
|
|
|
std::vector<uint64_t> absolute_offsets
|
|
|
|
= cryptonote::relative_output_offsets_to_absolute(
|
|
|
|
in_key.key_offsets);
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get public keys of outputs used in the mixins that match to the offests
|
|
|
|
std::vector<cryptonote::output_data_t> outputs;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
core_storage->get_db().get_output_key(in_key.amount,
|
|
|
|
absolute_offsets,
|
|
|
|
outputs);
|
2016-10-13 05:54:16 +00:00
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
catch (const OUTPUT_DNE &e)
|
2016-10-13 05:54:16 +00:00
|
|
|
{
|
|
|
|
string out_msg = fmt::format(
|
2017-04-28 07:24:19 +00:00
|
|
|
"Outputs with amount {:d} do not exist and indexes ",
|
|
|
|
in_key.amount
|
2016-10-13 05:54:16 +00:00
|
|
|
);
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (auto offset: absolute_offsets)
|
|
|
|
out_msg += ", " + to_string(offset);
|
|
|
|
|
|
|
|
out_msg += " don't exist!";
|
|
|
|
|
2016-10-13 05:54:16 +00:00
|
|
|
cerr << out_msg << endl;
|
|
|
|
|
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = out_msg;
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
inputs.push_back(mstch::map {
|
|
|
|
{"in_key_img" , pod_to_hex(in_key.k_image)},
|
|
|
|
{"amount" , xmreg::xmr_amount_to_str(in_key.amount)},
|
|
|
|
{"input_idx" , fmt::format("{:02d}", input_idx)},
|
|
|
|
{"mixins" , mstch::array{}},
|
|
|
|
{"ring_sigs" , mstch::array{}},
|
|
|
|
{"already_spent", false} // placeholder for later
|
|
|
|
});
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
if (detailed_view)
|
2016-05-06 08:00:57 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
boost::get<mstch::map>(inputs.back())["ring_sigs"]
|
|
|
|
= txd.get_ring_sig_for_input(input_idx);
|
|
|
|
}
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
inputs_xmr_sum += in_key.amount;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (in_key.amount == 0)
|
|
|
|
{
|
|
|
|
// if any input has amount equal to zero,
|
|
|
|
// it is really an unkown amount
|
|
|
|
have_any_unknown_amount = true;
|
|
|
|
}
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
vector<uint64_t> mixin_timestamps;
|
2016-10-13 05:54:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get reference to mixins array created above
|
|
|
|
mstch::array& mixins = boost::get<mstch::array>(
|
|
|
|
boost::get<mstch::map>(inputs.back())["mixins"]);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// mixin counter
|
|
|
|
size_t count = 0;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// for each found output public key find its block to get timestamp
|
|
|
|
for (const uint64_t& i: absolute_offsets)
|
2017-04-28 05:45:30 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// get basic information about mixn's output
|
|
|
|
cryptonote::output_data_t output_data = outputs.at(count);
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_out_index tx_out_idx;
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// get pair pair<crypto::hash, uint64_t> where first is tx hash
|
|
|
|
// and second is local index of the output i in that tx
|
|
|
|
tx_out_idx = core_storage->get_db()
|
|
|
|
.get_output_tx_and_index(in_key.amount, i);
|
|
|
|
}
|
|
|
|
catch (const OUTPUT_DNE &e)
|
|
|
|
{
|
2016-05-06 08:00:57 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string out_msg = fmt::format(
|
|
|
|
"Output with amount {:d} and index {:d} does not exist!",
|
|
|
|
in_key.amount, i
|
|
|
|
);
|
2016-05-02 06:09:41 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
cerr << out_msg << endl;
|
2016-05-02 06:09:41 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = out_msg;
|
2016-05-02 06:09:41 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return context;
|
|
|
|
}
|
2016-05-02 06:09:41 +00:00
|
|
|
|
2016-04-28 07:03:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (detailed_view)
|
|
|
|
{
|
|
|
|
// get block of given height, as we want to get its timestamp
|
|
|
|
cryptonote::block blk;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_block_by_height(output_data.height, blk))
|
|
|
|
{
|
|
|
|
cerr << "- cant get block of height: " << output_data.height << endl;
|
2016-05-10 03:13:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = fmt::format("- cant get block of height: {}",
|
|
|
|
output_data.height);
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get age of mixin relative to server time
|
|
|
|
pair<string, string> mixin_age = get_age(server_timestamp,
|
|
|
|
blk.timestamp,
|
|
|
|
FULL_AGE_FORMAT);
|
|
|
|
// get mixin transaction
|
|
|
|
transaction mixin_tx;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!mcore->get_tx(tx_out_idx.first, mixin_tx))
|
|
|
|
{
|
|
|
|
cerr << "Cant get tx: " << tx_out_idx.first << endl;
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["has_error"] = true;
|
|
|
|
context["error_msg"] = fmt::format("Cant get tx: {:s}", tx_out_idx.first);
|
|
|
|
}
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// mixin tx details
|
|
|
|
tx_details mixin_txd = get_tx_details(mixin_tx, true);
|
|
|
|
|
|
|
|
mixins.push_back(mstch::map {
|
|
|
|
{"mix_blk", fmt::format("{:08d}", output_data.height)},
|
|
|
|
{"mix_pub_key", pod_to_hex(output_data.pubkey)},
|
|
|
|
{"mix_tx_hash", pod_to_hex(tx_out_idx.first)},
|
|
|
|
{"mix_out_indx", tx_out_idx.second},
|
|
|
|
{"mix_timestamp", xmreg::timestamp_to_str_gm(blk.timestamp)},
|
|
|
|
{"mix_age", mixin_age.first},
|
|
|
|
{"mix_mixin_no", mixin_txd.mixin_no},
|
|
|
|
{"mix_inputs_no", static_cast<uint64_t>(mixin_txd.input_key_imgs.size())},
|
|
|
|
{"mix_outputs_no", static_cast<uint64_t>(mixin_txd.output_pub_keys.size())},
|
|
|
|
{"mix_age_format", mixin_age.second},
|
|
|
|
{"mix_idx", fmt::format("{:02d}", count)},
|
|
|
|
{"mix_is_it_real", false}, // a placeholder for future
|
|
|
|
});
|
|
|
|
|
|
|
|
// get mixin timestamp from its orginal block
|
|
|
|
mixin_timestamps.push_back(blk.timestamp);
|
|
|
|
}
|
|
|
|
else // if (detailed_view)
|
|
|
|
{
|
|
|
|
mixins.push_back(mstch::map {
|
|
|
|
{"mix_blk", fmt::format("{:08d}", output_data.height)},
|
|
|
|
{"mix_pub_key", pod_to_hex(output_data.pubkey)},
|
|
|
|
{"mix_idx", fmt::format("{:02d}", count)},
|
|
|
|
{"mix_is_it_real", false}, // a placeholder for future
|
|
|
|
});
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // else if (enable_mixins_details)
|
2017-02-22 07:03:19 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
++count;
|
2017-02-22 07:03:19 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (const uint64_t &i: absolute_offsets)
|
2017-02-22 07:03:19 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mixin_timestamp_groups.push_back(mixin_timestamps);
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
input_idx++;
|
2016-04-29 09:38:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (const txin_to_key& in_key: txd.input_key_imgs)
|
2016-05-01 05:28:09 +00:00
|
|
|
|
2016-04-29 09:38:23 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (detailed_view)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t min_mix_timestamp {0};
|
|
|
|
uint64_t max_mix_timestamp {0};
|
|
|
|
|
|
|
|
pair<mstch::array, double> mixins_timescales
|
|
|
|
= construct_mstch_mixin_timescales(
|
|
|
|
mixin_timestamp_groups,
|
|
|
|
min_mix_timestamp,
|
|
|
|
max_mix_timestamp
|
|
|
|
);
|
2016-05-07 09:32:28 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["min_mix_time"] = xmreg::timestamp_to_str_gm(min_mix_timestamp);
|
|
|
|
context["max_mix_time"] = xmreg::timestamp_to_str_gm(max_mix_timestamp);
|
2016-05-07 09:32:28 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("timescales", mixins_timescales.first);
|
2016-05-07 09:32:28 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["timescales_scale"] = fmt::format("{:0.2f}",
|
|
|
|
mixins_timescales.second / 3600.0 / 24.0); // in days
|
2016-05-07 09:32:28 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["tx_prefix_hash"] = pod_to_hex(get_transaction_prefix_hash(tx));
|
2016-05-07 09:32:28 +00:00
|
|
|
|
2016-10-04 05:05:45 +00:00
|
|
|
}
|
2016-05-07 09:32:28 +00:00
|
|
|
|
2016-04-30 01:35:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["have_any_unknown_amount"] = have_any_unknown_amount;
|
|
|
|
context["inputs_xmr_sum_not_zero"] = (inputs_xmr_sum > 0);
|
|
|
|
context["inputs_xmr_sum"] = xmreg::xmr_amount_to_str(inputs_xmr_sum);
|
|
|
|
context["server_time"] = server_time_str;
|
|
|
|
context["enable_mixins_details"] = detailed_view;
|
|
|
|
context["show_part_of_inputs"] = show_part_of_inputs;
|
|
|
|
context["max_no_of_inputs_to_show"] = max_no_of_inputs_to_show;
|
|
|
|
|
|
|
|
|
|
|
|
context.emplace("inputs", inputs);
|
2016-04-29 09:38:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get indices of outputs in amounts tables
|
|
|
|
vector<uint64_t> out_amount_indices;
|
2016-05-01 08:07:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
try
|
|
|
|
{
|
2016-05-01 08:07:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t tx_index;
|
2016-05-01 08:07:49 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (core_storage->get_db().tx_exists(txd.hash, tx_index))
|
|
|
|
{
|
|
|
|
out_amount_indices = core_storage->get_db()
|
|
|
|
.get_tx_amount_output_indices(tx_index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "get_tx_outputs_gindexs failed to find transaction with id = " << txd.hash;
|
|
|
|
}
|
2016-05-01 05:28:09 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
|
|
|
catch(const exception& e)
|
|
|
|
{
|
|
|
|
cerr << e.what() << endl;
|
|
|
|
}
|
2016-05-01 05:28:09 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t output_idx {0};
|
2016-04-28 22:49:10 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
mstch::array outputs;
|
2016-04-28 22:49:10 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t outputs_xmr_sum {0};
|
2016-04-28 07:03:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (pair<txout_to_key, uint64_t>& outp: txd.output_pub_keys)
|
|
|
|
{
|
2016-04-28 07:03:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// total number of ouputs in the blockchain for this amount
|
|
|
|
uint64_t num_outputs_amount = core_storage->get_db()
|
|
|
|
.get_num_outputs(outp.second);
|
2016-04-30 01:35:48 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string out_amount_index_str {"N/A"};
|
|
|
|
|
|
|
|
// outputs in tx in them mempool dont have yet global indices
|
|
|
|
// thus for them, we print N/A
|
|
|
|
if (!out_amount_indices.empty())
|
|
|
|
{
|
|
|
|
out_amount_index_str = fmt::format("{:d}",
|
|
|
|
out_amount_indices.at(output_idx));
|
|
|
|
}
|
2016-04-28 07:03:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
outputs_xmr_sum += outp.second;
|
2016-10-13 04:02:17 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
outputs.push_back(mstch::map {
|
|
|
|
{"out_pub_key" , pod_to_hex(outp.first.key)},
|
|
|
|
{"amount" , xmreg::xmr_amount_to_str(outp.second)},
|
|
|
|
{"amount_idx" , out_amount_index_str},
|
|
|
|
{"num_outputs" , num_outputs_amount},
|
|
|
|
{"output_idx" , fmt::format("{:02d}", output_idx++)}
|
|
|
|
});
|
|
|
|
}
|
2016-10-13 04:02:17 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context["outputs_xmr_sum"] = xmreg::xmr_amount_to_str(outputs_xmr_sum);
|
2016-10-13 04:02:17 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
context.emplace("outputs", outputs);
|
2016-10-13 04:02:17 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return context;
|
|
|
|
}
|
2016-10-13 04:02:17 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
pair<mstch::array, double>
|
|
|
|
construct_mstch_mixin_timescales(
|
|
|
|
const vector<vector<uint64_t>>& mixin_timestamp_groups,
|
|
|
|
uint64_t& min_mix_timestamp,
|
|
|
|
uint64_t& max_mix_timestamp
|
|
|
|
)
|
|
|
|
{
|
|
|
|
mstch::array mixins_timescales;
|
2016-10-13 04:02:17 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
double timescale_scale {0.0}; // size of one '_' in days
|
2016-12-26 04:21:23 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// initialize with some large and some numbers
|
|
|
|
min_mix_timestamp = server_timestamp*2L;
|
|
|
|
max_mix_timestamp = 0;
|
2016-10-13 04:02:17 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// find min and maximum timestamps
|
|
|
|
for (const vector<uint64_t>& mixn_timestamps : mixin_timestamp_groups)
|
|
|
|
{
|
2016-04-28 07:03:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
uint64_t min_found = *min_element(mixn_timestamps.begin(), mixn_timestamps.end());
|
|
|
|
uint64_t max_found = *max_element(mixn_timestamps.begin(), mixn_timestamps.end());
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (min_found < min_mix_timestamp)
|
|
|
|
min_mix_timestamp = min_found;
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (max_found > max_mix_timestamp)
|
|
|
|
max_mix_timestamp = max_found;
|
|
|
|
}
|
2016-04-17 01:44:24 +00:00
|
|
|
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
min_mix_timestamp -= 3600;
|
|
|
|
max_mix_timestamp += 3600;
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// make timescale maps for mixins in input with adjusted range
|
|
|
|
for (auto& mixn_timestamps : mixin_timestamp_groups)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// get mixins in time scale for visual representation
|
|
|
|
pair<string, double> mixin_times_scale = xmreg::timestamps_time_scale(
|
|
|
|
mixn_timestamps,
|
|
|
|
max_mix_timestamp,
|
|
|
|
170,
|
|
|
|
min_mix_timestamp);
|
|
|
|
|
|
|
|
// save resolution of mixin timescales
|
|
|
|
timescale_scale = mixin_times_scale.second;
|
|
|
|
|
|
|
|
// save the string timescales for later to show
|
|
|
|
mixins_timescales.push_back(mstch::map {
|
|
|
|
{"timescale", mixin_times_scale.first}
|
|
|
|
});
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2017-04-28 07:24:19 +00:00
|
|
|
|
|
|
|
return make_pair(mixins_timescales, timescale_scale);
|
2016-11-23 22:11:23 +00:00
|
|
|
}
|
2016-05-15 10:30:12 +00:00
|
|
|
|
2016-09-07 02:00:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
tx_details
|
|
|
|
get_tx_details(const transaction& tx,
|
|
|
|
bool coinbase = false,
|
|
|
|
uint64_t blk_height = 0,
|
|
|
|
uint64_t bc_height = 0)
|
|
|
|
{
|
|
|
|
tx_details txd;
|
2016-11-28 00:50:01 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get tx hash
|
|
|
|
txd.hash = get_transaction_hash(tx);
|
2016-11-28 00:50:01 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get tx public key from extra
|
|
|
|
// this check if there are two public keys
|
|
|
|
// due to previous bug with sining txs:
|
|
|
|
// https://github.com/monero-project/monero/pull/1358/commits/7abfc5474c0f86e16c405f154570310468b635c2
|
|
|
|
txd.pk = xmreg::get_tx_pub_key_from_received_outs(tx);
|
2016-10-17 09:10:36 +00:00
|
|
|
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// sum xmr in inputs and ouputs in the given tx
|
|
|
|
const array<uint64_t, 4>& sum_data = summary_of_in_out_rct(
|
|
|
|
tx, txd.output_pub_keys, txd.input_key_imgs);
|
2016-04-25 03:54:26 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txd.xmr_outputs = sum_data[0];
|
|
|
|
txd.xmr_inputs = sum_data[1];
|
|
|
|
txd.mixin_no = sum_data[2];
|
|
|
|
txd.num_nonrct_inputs = sum_data[3];
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txd.fee = 0;
|
2016-04-19 07:13:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (!coinbase && tx.vin.size() > 0)
|
|
|
|
{
|
|
|
|
// check if not miner tx
|
|
|
|
// i.e., for blocks without any user transactions
|
|
|
|
if (tx.vin.at(0).type() != typeid(txin_gen))
|
|
|
|
{
|
|
|
|
// get tx fee
|
|
|
|
txd.fee = get_tx_fee(tx);
|
|
|
|
}
|
|
|
|
}
|
2016-04-30 12:16:44 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
get_payment_id(tx, txd.payment_id, txd.payment_id8);
|
2016-04-19 07:13:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get tx size in bytes
|
|
|
|
txd.size = get_object_blobsize(tx);
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txd.extra = tx.extra;
|
2016-04-17 01:44:24 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get tx signatures for each input
|
|
|
|
txd.signatures = tx.signatures;
|
2016-10-17 09:10:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get tx version
|
|
|
|
txd.version = tx.version;
|
2016-12-05 02:02:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// get unlock time
|
|
|
|
txd.unlock_time = tx.unlock_time;
|
2016-12-05 02:02:46 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txd.no_confirmations = 0;
|
2016-11-26 05:05:28 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
if (blk_height == 0 && core_storage->have_tx(txd.hash))
|
|
|
|
{
|
|
|
|
// if blk_height is zero then search for tx block in
|
|
|
|
// the blockchain. but since often block height is know a priory
|
|
|
|
// this is not needed
|
|
|
|
|
|
|
|
txd.blk_height = core_storage->get_db().get_tx_block_height(txd.hash);
|
|
|
|
|
|
|
|
// get the current blockchain height. Just to check
|
|
|
|
uint64_t bc_height = core_storage->get_current_blockchain_height();
|
|
|
|
|
|
|
|
txd.no_confirmations = bc_height - (txd.blk_height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if we know blk_height, and current blockchan height
|
|
|
|
// just use it to get no_confirmations.
|
2016-10-17 09:10:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
txd.no_confirmations = bc_height - (blk_height);
|
|
|
|
}
|
2016-10-17 09:10:36 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return txd;
|
|
|
|
}
|
2016-09-30 04:45:35 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
void
|
|
|
|
clean_post_data(string& raw_tx_data)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// remove white characters
|
|
|
|
boost::trim(raw_tx_data);
|
|
|
|
boost::erase_all(raw_tx_data, "\r\n");
|
|
|
|
boost::erase_all(raw_tx_data, "\n");
|
|
|
|
|
|
|
|
// remove header and footer from base64 data
|
|
|
|
// produced by certutil.exe in windows
|
|
|
|
boost::erase_all(raw_tx_data, "-----BEGIN CERTIFICATE-----");
|
|
|
|
boost::erase_all(raw_tx_data, "-----END CERTIFICATE-----");
|
2016-04-17 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
|
2017-05-04 00:52:52 +00:00
|
|
|
bool
|
|
|
|
search_mempool(crypto::hash tx_hash,
|
2017-06-02 02:14:42 +00:00
|
|
|
vector<MempoolStatus::mempool_tx>& found_txs)
|
2016-04-24 01:11:08 +00:00
|
|
|
{
|
2017-04-28 07:24:19 +00:00
|
|
|
// if tx_hash == null_hash then this method
|
|
|
|
// will just return the vector containing all
|
|
|
|
// txs in mempool
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
|
|
|
|
// get mempool tx from mempoolstatus thread
|
|
|
|
vector<MempoolStatus::mempool_tx> mempool_txs
|
|
|
|
= MempoolStatus::get_mempool_txs();
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if dont have tx_blob member, construct tx
|
|
|
|
// from json obtained from the rpc call
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
for (size_t i = 0; i < mempool_txs.size(); ++i)
|
|
|
|
{
|
|
|
|
// get transaction info of the tx in the mempool
|
2017-06-02 02:14:42 +00:00
|
|
|
const MempoolStatus::mempool_tx& mempool_tx = mempool_txs.at(i);
|
2016-04-24 01:11:08 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
if (tx_hash == mempool_tx.tx_hash || tx_hash == null_hash)
|
2016-11-23 22:11:23 +00:00
|
|
|
{
|
2017-06-02 02:14:42 +00:00
|
|
|
found_txs.push_back(mempool_tx);
|
2016-12-02 02:22:49 +00:00
|
|
|
|
2017-06-02 02:14:42 +00:00
|
|
|
if (tx_hash != null_hash)
|
|
|
|
break;
|
|
|
|
}
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
} // for (size_t i = 0; i < mempool_txs.size(); ++i)
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-05-04 00:52:52 +00:00
|
|
|
return true;
|
2017-04-28 07:24:19 +00:00
|
|
|
}
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
pair<string, string>
|
|
|
|
get_age(uint64_t timestamp1, uint64_t timestamp2, bool full_format = 0)
|
|
|
|
{
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
pair<string, string> age_pair;
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// calculate difference between server and block timestamps
|
|
|
|
array<size_t, 5> delta_time = timestamp_difference(
|
|
|
|
timestamp1, timestamp2);
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// default format for age
|
|
|
|
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
|
|
|
|
delta_time[2], delta_time[3],
|
|
|
|
delta_time[4]);
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string age_format {"[h:m:s]"};
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
// if have days or years, change age format
|
|
|
|
if (delta_time[0] > 0 || full_format == true)
|
|
|
|
{
|
|
|
|
age_str = fmt::format("{:02d}:{:03d}:{:02d}:{:02d}:{:02d}",
|
|
|
|
delta_time[0], delta_time[1], delta_time[2],
|
|
|
|
delta_time[3], delta_time[4]);
|
|
|
|
|
|
|
|
age_format = string("[y:d:h:m:s]");
|
|
|
|
}
|
|
|
|
else if (delta_time[1] > 0)
|
|
|
|
{
|
|
|
|
age_str = fmt::format("{:02d}:{:02d}:{:02d}:{:02d}",
|
|
|
|
delta_time[1], delta_time[2],
|
|
|
|
delta_time[3], delta_time[4]);
|
2016-04-16 03:44:58 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
age_format = string("[d:h:m:s]");
|
|
|
|
}
|
2016-04-12 22:20:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
age_pair.first = age_str;
|
|
|
|
age_pair.second = age_format;
|
2016-04-12 22:20:14 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return age_pair;
|
|
|
|
}
|
2016-11-23 01:59:22 +00:00
|
|
|
|
2016-11-29 06:07:16 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
get_full_page(const string& middle)
|
|
|
|
{
|
|
|
|
return template_file["header"]
|
|
|
|
+ middle
|
|
|
|
+ template_file["footer"];
|
|
|
|
}
|
|
|
|
|
2017-05-15 06:19:57 +00:00
|
|
|
bool
|
2017-05-11 04:17:10 +00:00
|
|
|
get_monero_network_info(json& j_info)
|
|
|
|
{
|
|
|
|
COMMAND_RPC_GET_INFO::response network_info;
|
|
|
|
|
|
|
|
if (!rpc.get_network_info(network_info))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
j_info = json {
|
|
|
|
{"status" , network_info.status},
|
|
|
|
{"height" , network_info.height},
|
|
|
|
{"target_height" , network_info.target_height},
|
|
|
|
{"difficulty" , network_info.difficulty},
|
|
|
|
{"target" , network_info.target},
|
|
|
|
{"hash_rate" , (network_info.difficulty/network_info.target)},
|
|
|
|
{"tx_count" , network_info.tx_count},
|
|
|
|
{"tx_pool_size" , network_info.tx_pool_size},
|
|
|
|
{"alt_blocks_count" , network_info.alt_blocks_count},
|
|
|
|
{"outgoing_connections_count", network_info.outgoing_connections_count},
|
|
|
|
{"incoming_connections_count", network_info.incoming_connections_count},
|
|
|
|
{"white_peerlist_size" , network_info.white_peerlist_size},
|
|
|
|
{"grey_peerlist_size" , network_info.grey_peerlist_size},
|
|
|
|
{"testnet" , network_info.testnet},
|
|
|
|
{"top_block_hash" , network_info.top_block_hash},
|
|
|
|
{"cumulative_difficulty" , network_info.cumulative_difficulty},
|
|
|
|
{"block_size_limit" , network_info.block_size_limit},
|
|
|
|
{"start_time" , network_info.start_time}
|
|
|
|
};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-15 06:19:57 +00:00
|
|
|
bool
|
|
|
|
get_dynamic_per_kb_fee_estimate(uint64_t& fee_estimated)
|
|
|
|
{
|
|
|
|
|
|
|
|
string error_msg;
|
|
|
|
|
|
|
|
if (!rpc.get_dynamic_per_kb_fee_estimate(
|
|
|
|
FEE_ESTIMATE_GRACE_BLOCKS,
|
|
|
|
fee_estimated, error_msg))
|
|
|
|
{
|
|
|
|
cerr << "rpc.get_dynamic_per_kb_fee_estimate failed" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) error_msg;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string
|
|
|
|
get_footer()
|
|
|
|
{
|
|
|
|
// set last git commit date based on
|
|
|
|
// autogenrated version.h during compilation
|
|
|
|
static const mstch::map footer_context {
|
|
|
|
{"last_git_commit_hash", string {GIT_COMMIT_HASH}},
|
|
|
|
{"last_git_commit_date", string {GIT_COMMIT_DATETIME}},
|
2017-05-24 05:40:25 +00:00
|
|
|
{"git_branch_name" , string {GIT_BRANCH_NAME}},
|
|
|
|
{"monero_version_full" , string {MONERO_VERSION_FULL}}
|
2017-04-28 07:24:19 +00:00
|
|
|
};
|
2016-11-23 01:59:22 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
string footer_html = mstch::render(xmreg::read(TMPL_FOOTER), footer_context);
|
2016-04-08 06:54:04 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
return footer_html;
|
|
|
|
}
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
void
|
|
|
|
add_css_style(mstch::map& context)
|
|
|
|
{
|
|
|
|
context["css_styles"] = mstch::lambda{[&](const std::string& text) -> mstch::node {
|
|
|
|
return template_file["css_styles"];
|
|
|
|
}};
|
|
|
|
}
|
2016-10-13 07:13:59 +00:00
|
|
|
|
2017-04-28 07:24:19 +00:00
|
|
|
};
|
2016-04-08 06:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif //CROWXMR_PAGE_H
|
2017-05-19 09:50:12 +00:00
|
|
|
|