fix merging problems

master
moneroexamples 8 years ago
parent b540bf5f72
commit c3c25fcb03

@ -16,11 +16,13 @@
#include "MicroCore.h"
#include "tools.h"
#include "rpccalls.h"
#include "../ext/crow/http_request.h"
#include "../ext/vpetrigocaches/cache.hpp"
#include "../ext/vpetrigocaches/lru_cache_policy.hpp"
#include "../ext/vpetrigocaches/fifo_cache_policy.hpp"
#include <algorithm>
#include <limits>
#include <ctime>
@ -74,7 +76,6 @@ struct tx_info_cache
};
};
// indect overload of hash for tx_info_cache::key
namespace std
{
@ -95,12 +96,12 @@ namespace xmreg
{
using namespace cryptonote;
using namespace crypto;
using namespace std;
using namespace cryptonote;
using namespace crypto;
using namespace std;
using epee::string_tools::pod_to_hex;
using epee::string_tools::hex_to_pod;
using epee::string_tools::pod_to_hex;
using epee::string_tools::hex_to_pod;
/**
* @brief The tx_details struct
@ -108,8 +109,8 @@ using epee::string_tools::hex_to_pod;
* Basic information about tx
*
*/
struct tx_details
{
struct tx_details
{
crypto::hash hash;
crypto::hash prefix_hash;
crypto::public_key pk;
@ -139,23 +140,13 @@ struct tx_details
mstch::map
get_mstch_map() const
{
// remove "<" and ">" from the hash string
string tx_hash_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", hash));
string tx_prefix_hash_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", prefix_hash));
string tx_pk_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", pk));
//cout << "payment_id: " << payment_id << endl;
string pid_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", payment_id));
string pid8_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", payment_id8));
string mixin_str {"N/A"};
string fee_str {"N/A"};
string fee_short_str {"N/A"};
const double& xmr_amount = XMR_AMOUNT(fee);
if (!input_key_imgs.empty())
{
mixin_str = std::to_string(mixin_no - 1);
@ -163,7 +154,6 @@ struct tx_details
fee_short_str = fmt::format("{:0.3f}", xmr_amount);
}
const double& tx_size = static_cast<double>(size)/1024.0;
mstch::map txd_map {
@ -201,7 +191,6 @@ struct tx_details
string
get_extra_str() const
{
return epee::string_tools::buff_to_hex_nodelimer(
string{reinterpret_cast<const char*>(extra.data()), extra.size()});
}
@ -237,11 +226,11 @@ struct tx_details
return ss.str();
}
};
};
class page
{
class page
{
static const bool FULL_AGE_FORMAT {true};
@ -251,6 +240,7 @@ class page
atomic<time_t> server_timestamp;
bool testnet;
bool enable_pusher;
@ -263,8 +253,8 @@ class page
bool enable_block_cache;
bool show_cache_times;
bool enable_autorefresh_option;
bool enable_autorefresh_option;
uint64_t no_of_mempool_tx_of_frontpage;
@ -272,6 +262,7 @@ class page
string testnet_url;
string mainnet_url;
// 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
@ -324,7 +315,9 @@ class page
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:
public:
page(MicroCore* _mcore,
Blockchain* _core_storage,
@ -366,8 +359,6 @@ public:
no_of_mempool_tx_of_frontpage = 25;
// read template files for all the pages
// into template_file map
@ -389,7 +380,6 @@ public:
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");
@ -408,6 +398,7 @@ public:
server_timestamp = std::time(nullptr);
uint64_t local_copy_server_timestamp = server_timestamp;
// number of last blocks to show
uint64_t no_of_last_blocks {no_blocks_on_index + 1};
@ -435,6 +426,7 @@ public:
{"enable_autorefresh_option", enable_autorefresh_option},
{"show_cache_times" , show_cache_times}
};
context.emplace("txs", mstch::array()); // will keep tx to show
// get reference to txs mstch map to be field below
@ -458,6 +450,7 @@ public:
// loop index
int64_t i = end_height;
// iterate over last no_of_last_blocks of blocks
while (i >= start_height)
{
@ -686,6 +679,7 @@ public:
context["blk_size_median"] = fmt::format("{:0.2f}", blk_size_median);
// save computational times for disply in the frontend
context["construction_time_cached"] = fmt::format(
@ -710,10 +704,8 @@ public:
// render the page
return mstch::render(template_file["index2"], context);
}
/**
* Render mempool data
*/
@ -813,6 +805,7 @@ public:
try
{
// get the above incormation from json of that tx
json j_tx;
if (enable_mempool_cache && mempool_tx_json_cache.Contains(_tx_info.id_hash))
@ -903,6 +896,7 @@ public:
});
}
} // else if (mempool_tx_json_cache.Contains(_tx_info.id_hash))
}
catch (std::invalid_argument& e)
{
@ -921,11 +915,8 @@ public:
{"no_inputs" , no_inputs},
{"no_outputs" , no_outputs},
{"no_nonrct_inputs", num_nonrct_inputs},
{"is_ringct" , is_ringct_str},
{"rct_type" , rct_type_str},
{"mixin" , fmt::format("{:d}", mixin_no)},
{"txsize" , fmt::format("{:0.2f}",
static_cast<double>(_tx_info.blob_size)/1024.0)}
{"mixin" , mixin_no},
{"txsize" , txsize}
});
}
@ -1402,10 +1393,8 @@ public:
{"tx_details", template_file["tx_details"]},
};
add_css_style(context);
// render the page
return mstch::render(template_file["tx"], context, partials);
}
@ -2139,11 +2128,13 @@ public:
{"error_msg" , string {}},
{"data_prefix" , data_prefix},
};
context.emplace("txs", mstch::array{});
string full_page = template_file["checkrawtx"];
add_css_style(context);
if (unsigned_tx_given)
{
@ -2481,7 +2472,6 @@ public:
{"tx_details", template_file["tx_details"]},
};
add_css_style(context);
// render the page
@ -2731,7 +2721,6 @@ public:
{"tx_details", template_file["tx_details"]},
};
// render the page
return mstch::render(full_page, context, partials);
}
@ -3057,7 +3046,6 @@ public:
context.insert({"key_imgs" , mstch::array{}});
size_t no_key_images = (decoded_raw_data.size() - header_lenght) / record_lenght;
//vector<pair<crypto::key_image, crypto::signature>> signed_key_images;
@ -3082,7 +3070,6 @@ public:
// so this will be empty always for now.
vector<string> found_tx_hashes;
mstch::map key_img_info {
{"key_no" , fmt::format("{:03d}", n)},
{"key_image" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", key_image))},
@ -3541,6 +3528,7 @@ public:
return result_html;
}
// first check if searching for block of given height
if (search_text.size() < 12)
{
@ -3577,6 +3565,7 @@ public:
result_html = default_txt;
// 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)
@ -3629,11 +3618,8 @@ public:
// 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;
result_html = show_search_results(search_text, all_possible_tx_hashes);
return result_html;
@ -3762,7 +3748,6 @@ public:
}
string
show_search_results(const string& search_text,
const vector<pair<string, vector<string>>>& all_possible_tx_hashes)
@ -4582,7 +4567,7 @@ public:
return j_response;
}
private:
private:
json
get_tx_json(const transaction& tx, const tx_details& txd)
@ -4641,6 +4626,7 @@ private:
return true;
}
void
mark_real_mixins_on_timescales(
const vector<uint64_t>& real_output_indices,
@ -4681,7 +4667,6 @@ private:
mstch::map
construct_tx_context(transaction tx, uint16_t with_ring_signatures = 0)
{
tx_details txd = get_tx_details(tx);
const crypto::hash& tx_hash = txd.hash;
@ -4693,6 +4678,7 @@ private:
bool tx_blk_found {false};
bool detailed_view {enable_mixins_details || static_cast<bool>(with_ring_signatures)};
if (core_storage->have_tx(tx_hash))
{
// currently get_tx_block_height seems to return a block hight
@ -4798,15 +4784,19 @@ private:
{
show_part_of_inputs = false;
}
vector<vector<uint64_t>> mixin_timestamp_groups;
// make timescale maps for mixins in input
for (const txin_to_key &in_key: txd.input_key_imgs)
{
if (show_part_of_inputs && (input_idx > max_no_of_inputs_to_show))
{
break;
}
// get absolute offsets of mixins
std::vector<uint64_t> absolute_offsets
= cryptonote::relative_output_offsets_to_absolute(
@ -4855,6 +4845,8 @@ private:
boost::get<mstch::map>(inputs.back())["ring_sigs"]
= txd.get_ring_sig_for_input(input_idx);
}
inputs_xmr_sum += in_key.amount;
if (in_key.amount == 0)
@ -4973,6 +4965,7 @@ private:
mixin_timestamp_groups.push_back(mixin_timestamps);
input_idx++;
} // for (const txin_to_key& in_key: txd.input_key_imgs)
@ -5148,13 +5141,13 @@ private:
// get tx hash
txd.hash = get_transaction_hash(tx);
// 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);
// 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);
@ -5166,11 +5159,6 @@ private:
txd.fee = 0;
transaction tx_copy = tx;
txd.json_representation = obj_to_json_str(tx_copy);
if (!coinbase && tx.vin.size() > 0)
{
// check if not miner tx
@ -5184,8 +5172,6 @@ private:
get_payment_id(tx, txd.payment_id, txd.payment_id8);
// get tx size in bytes
txd.size = get_object_blobsize(tx);
@ -5207,6 +5193,7 @@ private:
// 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
@ -5376,7 +5363,7 @@ private:
}};
}
};
};
}

@ -14,10 +14,10 @@ namespace xmreg
* into crypto::secret_key or crypto::public_key
* depending on the template argument.
*/
template <typename T>
bool
parse_str_secret_key(const string& key_str, T& secret_key)
{
template <typename T>
bool
parse_str_secret_key(const string& key_str, T& secret_key)
{
// hash and keys have same structure, so to parse string of
// a key, e.g., a view key, we can first parse it into the hash
@ -38,21 +38,21 @@ parse_str_secret_key(const string& key_str, T& secret_key)
copy(begin(hash_.data), end(hash_.data), secret_key.data);
return true;
}
}
// explicit instantiations of get template function
template bool parse_str_secret_key<crypto::secret_key>(const string& key_str, crypto::secret_key& secret_key);
template bool parse_str_secret_key<crypto::public_key>(const string& key_str, crypto::public_key& secret_key);
template bool parse_str_secret_key<crypto::hash>(const string& key_str, crypto::hash& secret_key);
template bool parse_str_secret_key<crypto::secret_key>(const string& key_str, crypto::secret_key& secret_key);
template bool parse_str_secret_key<crypto::public_key>(const string& key_str, crypto::public_key& secret_key);
template bool parse_str_secret_key<crypto::hash>(const string& key_str, crypto::hash& secret_key);
/**
* Get transaction tx using given tx hash. Hash is represent as string here,
* so before we can tap into the blockchain, we need to pare it into
* crypto::hash object.
*/
bool
get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, transaction& tx)
{
bool
get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, transaction& tx)
{
crypto::hash tx_hash;
parse_hash256(hash_str, tx_hash);
@ -68,17 +68,17 @@ get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, t
}
return true;
}
}
/**
* Parse monero address in a string form into
* cryptonote::account_public_address object
*/
bool
parse_str_address(const string& address_str,
bool
parse_str_address(const string& address_str,
account_public_address& address,
bool testnet)
{
{
if (!get_account_address_from_str(address, testnet, address_str))
{
@ -87,58 +87,58 @@ parse_str_address(const string& address_str,
}
return true;
}
}
/**
* Return string representation of monero address
*/
string
print_address(const account_public_address& address, bool testnet)
{
string
print_address(const account_public_address& address, bool testnet)
{
return "<" + get_account_address_as_str(testnet, address) + ">";
}
}
string
print_sig (const signature& sig)
{
string
print_sig (const signature& sig)
{
stringstream ss;
ss << "c: <" << epee::string_tools::pod_to_hex(sig.c) << "> "
<< "r: <" << epee::string_tools::pod_to_hex(sig.r) << ">";
return ss.str();
}
}
/**
* Check if a character is a path seprator
*/
inline bool
is_separator(char c)
{
inline bool
is_separator(char c)
{
// default linux path separator
const char separator = PATH_SEPARARTOR;
return c == separator;
}
}
/**
* Remove trailinig path separator.
*/
string
remove_trailing_path_separator(const string& in_path)
{
string
remove_trailing_path_separator(const string& in_path)
{
string new_string = in_path;
if (!new_string.empty() && is_separator(new_string[new_string.size() - 1]))
new_string.erase(new_string.size() - 1);
return new_string;
}
}
bf::path
remove_trailing_path_separator(const bf::path& in_path)
{
bf::path
remove_trailing_path_separator(const bf::path& in_path)
{
#ifdef WIN32
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
string path_str = converter.to_bytes(in_path.native());
@ -146,7 +146,7 @@ remove_trailing_path_separator(const bf::path& in_path)
string path_str = in_path.native();
#endif
return bf::path(remove_trailing_path_separator(path_str));
}
}
//string
//timestamp_to_str(time_t timestamp, const char* format)
@ -155,9 +155,9 @@ remove_trailing_path_separator(const bf::path& in_path)
//}
string
timestamp_to_str_gm(time_t timestamp, const char* format)
{
string
timestamp_to_str_gm(time_t timestamp, const char* format)
{
const time_t* t = &timestamp;
const int TIME_LENGTH = 60;
@ -172,26 +172,26 @@ timestamp_to_str_gm(time_t timestamp, const char* format)
len = std::strftime(str_buff, TIME_LENGTH, format, &tmp);
return string(str_buff, len);
}
}
ostream&
operator<< (ostream& os, const account_public_address& addr)
{
ostream&
operator<< (ostream& os, const account_public_address& addr)
{
os << get_account_address_as_str(false, addr);
return os;
}
}
/*
* Generate key_image of foran ith output
*/
bool
generate_key_image(const crypto::key_derivation& derivation,
bool
generate_key_image(const crypto::key_derivation& derivation,
const std::size_t i,
const crypto::secret_key& sec_key,
const crypto::public_key& pub_key,
crypto::key_image& key_img)
{
{
cryptonote::keypair in_ephemeral;
@ -230,12 +230,12 @@ generate_key_image(const crypto::key_derivation& derivation,
}
return true;
}
}
string
get_default_lmdb_folder(bool testnet)
{
string
get_default_lmdb_folder(bool testnet)
{
// default path to monero folder
// on linux this is /home/<username>/.bitmonero
string default_monero_dir = tools::get_default_data_dir();
@ -247,7 +247,7 @@ get_default_lmdb_folder(bool testnet)
// the default folder of the lmdb blockchain database
// is therefore as follows
return default_monero_dir + string("/lmdb");
}
}
/*
@ -255,11 +255,11 @@ get_default_lmdb_folder(bool testnet)
*
* If not given, provide default path
*/
bool
get_blockchain_path(const boost::optional<string>& bc_path,
bool
get_blockchain_path(const boost::optional<string>& bc_path,
bf::path& blockchain_path,
bool testnet)
{
{
// the default folder of the lmdb blockchain database
string default_lmdb_dir = xmreg::get_default_lmdb_folder(testnet);
@ -279,12 +279,12 @@ get_blockchain_path(const boost::optional<string>& bc_path,
blockchain_path = xmreg::remove_trailing_path_separator(blockchain_path);
return true;
}
}
uint64_t
sum_money_in_outputs(const transaction& tx)
{
uint64_t
sum_money_in_outputs(const transaction& tx)
{
uint64_t sum_xmr {0};
for (const tx_out& txout: tx.vout)
@ -293,11 +293,11 @@ sum_money_in_outputs(const transaction& tx)
}
return sum_xmr;
}
}
pair<uint64_t, uint64_t>
sum_money_in_outputs(const string& json_str)
{
pair<uint64_t, uint64_t>
sum_money_in_outputs(const string& json_str)
{
pair<uint64_t, uint64_t> sum_xmr {0, 0};
json j;
@ -320,11 +320,11 @@ sum_money_in_outputs(const string& json_str)
return sum_xmr;
};
};
pair<uint64_t, uint64_t>
sum_money_in_outputs(const json& _json)
{
pair<uint64_t, uint64_t>
sum_money_in_outputs(const json& _json)
{
pair<uint64_t, uint64_t> sum_xmr {0ULL, 0ULL};
for (const json& vout: _json["vout"])
@ -334,15 +334,15 @@ sum_money_in_outputs(const json& _json)
}
return sum_xmr;
};
};
array<uint64_t, 4>
summary_of_in_out_rct(
array<uint64_t, 4>
summary_of_in_out_rct(
const transaction& tx,
vector<pair<txout_to_key, uint64_t>>& output_pub_keys,
vector<txin_to_key>& input_key_imgs)
{
{
uint64_t xmr_outputs {0};
uint64_t xmr_inputs {0};
@ -400,13 +400,13 @@ summary_of_in_out_rct(
return {xmr_outputs, xmr_inputs, mixin_no, num_nonrct_inputs};
};
};
// this version for mempool txs from json
array<uint64_t, 6>
summary_of_in_out_rct(const json& _json)
{
array<uint64_t, 6>
summary_of_in_out_rct(const json& _json)
{
uint64_t xmr_outputs {0};
uint64_t xmr_inputs {0};
uint64_t no_outputs {0};
@ -436,12 +436,12 @@ summary_of_in_out_rct(const json& _json)
mixin_no = _json["vin"].at(0)["key"]["key_offsets"].size() - 1;
return {xmr_outputs, xmr_inputs, no_outputs, no_inputs, mixin_no, num_nonrct_inputs};
};
};
uint64_t
sum_money_in_inputs(const transaction& tx)
{
uint64_t
sum_money_in_inputs(const transaction& tx)
{
uint64_t sum_xmr {0};
size_t input_no = tx.vin.size();
@ -462,11 +462,11 @@ sum_money_in_inputs(const transaction& tx)
}
return sum_xmr;
}
}
pair<uint64_t, uint64_t>
sum_money_in_inputs(const string& json_str)
{
pair<uint64_t, uint64_t>
sum_money_in_inputs(const string& json_str)
{
pair<uint64_t, uint64_t> sum_xmr {0, 0};
json j;
@ -487,12 +487,12 @@ sum_money_in_inputs(const string& json_str)
}
return sum_xmr;
};
};
pair<uint64_t, uint64_t>
sum_money_in_inputs(const json& _json)
{
pair<uint64_t, uint64_t>
sum_money_in_inputs(const json& _json)
{
pair<uint64_t, uint64_t> sum_xmr {0, 0};
for (const json& vin: _json["vin"])
@ -502,11 +502,11 @@ sum_money_in_inputs(const json& _json)
}
return sum_xmr;
};
};
uint64_t
count_nonrct_inputs(const transaction& tx)
{
uint64_t
count_nonrct_inputs(const transaction& tx)
{
uint64_t num {0};
size_t input_no = tx.vin.size();
@ -528,11 +528,11 @@ count_nonrct_inputs(const transaction& tx)
}
return num;
}
}
uint64_t
count_nonrct_inputs(const string& json_str)
{
uint64_t
count_nonrct_inputs(const string& json_str)
{
uint64_t num {0};
json j;
@ -554,12 +554,12 @@ count_nonrct_inputs(const string& json_str)
}
return num;
};
};
uint64_t
count_nonrct_inputs(const json& _json)
{
uint64_t
count_nonrct_inputs(const json& _json)
{
uint64_t num {0};
for (const json& vin: _json["vin"])
@ -570,23 +570,23 @@ count_nonrct_inputs(const json& _json)
}
return num;
};
};
array<uint64_t, 2>
sum_money_in_tx(const transaction& tx)
{
array<uint64_t, 2>
sum_money_in_tx(const transaction& tx)
{
array<uint64_t, 2> sum_xmr;
sum_xmr[0] = sum_money_in_inputs(tx);
sum_xmr[1] = sum_money_in_outputs(tx);
return sum_xmr;
};
};
array<uint64_t, 2>
sum_money_in_txs(const vector<transaction>& txs)
{
array<uint64_t, 2>
sum_money_in_txs(const vector<transaction>& txs)
{
array<uint64_t, 2> sum_xmr {0,0};
for (const transaction& tx: txs)
@ -596,12 +596,12 @@ sum_money_in_txs(const vector<transaction>& txs)
}
return sum_xmr;
};
};
uint64_t
sum_fees_in_txs(const vector<transaction>& txs)
{
uint64_t
sum_fees_in_txs(const vector<transaction>& txs)
{
uint64_t fees_sum {0};
for (const transaction& tx: txs)
@ -610,13 +610,13 @@ sum_fees_in_txs(const vector<transaction>& txs)
}
return fees_sum;
}
}
vector<pair<txout_to_key, uint64_t>>
get_ouputs(const transaction& tx)
{
vector<pair<txout_to_key, uint64_t>>
get_ouputs(const transaction& tx)
{
vector<pair<txout_to_key, uint64_t>> outputs;
for (const tx_out& txout: tx.vout)
@ -637,11 +637,11 @@ get_ouputs(const transaction& tx)
return outputs;
};
};
vector<tuple<txout_to_key, uint64_t, uint64_t>>
get_ouputs_tuple(const transaction& tx)
{
vector<tuple<txout_to_key, uint64_t, uint64_t>>
get_ouputs_tuple(const transaction& tx)
{
vector<tuple<txout_to_key, uint64_t, uint64_t>> outputs;
for (uint64_t n = 0; n < tx.vout.size(); ++n)
@ -660,11 +660,11 @@ get_ouputs_tuple(const transaction& tx)
}
return outputs;
};
};
uint64_t
get_mixin_no(const transaction& tx)
{
uint64_t
get_mixin_no(const transaction& tx)
{
uint64_t mixin_no {0};
size_t input_no = tx.vin.size();
@ -692,10 +692,10 @@ get_mixin_no(const transaction& tx)
}
return mixin_no;
}
vector<uint64_t>
get_mixin_no(const string& json_str)
{
}
vector<uint64_t>
get_mixin_no(const string& json_str)
{
vector<uint64_t> mixin_no;
json j;
@ -713,23 +713,23 @@ get_mixin_no(const string& json_str)
}
return mixin_no;
}
}
vector<uint64_t>
get_mixin_no(const json& _json)
{
vector<uint64_t>
get_mixin_no(const json& _json)
{
vector<uint64_t> mixin_no;
mixin_no.push_back(_json["vin"].at(0)["key"]["key_offsets"].size());
return mixin_no;
}
}
vector<uint64_t>
get_mixin_no_in_txs(const vector<transaction>& txs)
{
vector<uint64_t>
get_mixin_no_in_txs(const vector<transaction>& txs)
{
vector<uint64_t> mixin_no;
for (const transaction& tx: txs)
@ -738,12 +738,12 @@ get_mixin_no_in_txs(const vector<transaction>& txs)
}
return mixin_no;
}
}
vector<txin_to_key>
get_key_images(const transaction& tx)
{
vector<txin_to_key>
get_key_images(const transaction& tx)
{
vector<txin_to_key> key_images;
size_t input_no = tx.vin.size();
@ -764,14 +764,14 @@ get_key_images(const transaction& tx)
}
return key_images;
}
}
bool
get_payment_id(const vector<uint8_t>& extra,
bool
get_payment_id(const vector<uint8_t>& extra,
crypto::hash& payment_id,
crypto::hash8& payment_id8)
{
{
payment_id = null_hash;
payment_id8 = null_hash8;
@ -798,21 +798,21 @@ get_payment_id(const vector<uint8_t>& extra,
}
return false;
}
}
bool
get_payment_id(const transaction& tx,
bool
get_payment_id(const transaction& tx,
crypto::hash& payment_id,
crypto::hash8& payment_id8)
{
{
return get_payment_id(tx.extra, payment_id, payment_id8);
}
}
array<size_t, 5>
timestamp_difference(uint64_t t1, uint64_t t2)
{
array<size_t, 5>
timestamp_difference(uint64_t t1, uint64_t t2)
{
uint64_t timestamp_diff = t1 - t2;
@ -844,12 +844,12 @@ timestamp_difference(uint64_t t1, uint64_t t2)
time_diff_hours, time_diff_minutes,
time_diff_seconds};
};
};
string
read(string filename)
{
string
read(string filename)
{
if (!bf::exists(bf::path(filename)))
{
cerr << "File does not exist: " << filename << endl;
@ -859,14 +859,14 @@ read(string filename)
std::ifstream t(filename);
return string(std::istreambuf_iterator<char>(t),
std::istreambuf_iterator<char>());
}
}
pair<string, double>
timestamps_time_scale(const vector<uint64_t>& timestamps,
pair<string, double>
timestamps_time_scale(const vector<uint64_t>& timestamps,
uint64_t timeN,
uint64_t resolution,
uint64_t time0)
{
{
string empty_time = string(resolution, '_');
size_t time_axis_length = empty_time.size();
@ -891,26 +891,26 @@ timestamps_time_scale(const vector<uint64_t>& timestamps,
}
return make_pair(empty_time, scale);
}
}
// useful reference to get epoch time in correct timezon
// http://www.boost.org/doc/libs/1_41_0/doc/html/date_time/examples.html#date_time.examples.seconds_since_epoch
time_t
ptime_to_time_t(const pt::ptime& in_ptime)
{
time_t
ptime_to_time_t(const pt::ptime& in_ptime)
{
static pt::ptime epoch(gt::date(1970, 1, 1));
pt::time_duration::sec_type no_seconds = (in_ptime - epoch).total_seconds();
return time_t(no_seconds);
}
}
bool
decode_ringct(const rct::rctSig& rv,
bool
decode_ringct(const rct::rctSig& rv,
const crypto::public_key pub,
const crypto::secret_key &sec,
unsigned int i,
rct::key & mask,
uint64_t & amount)
{
{
try
{
crypto::key_derivation derivation;
@ -953,11 +953,11 @@ decode_ringct(const rct::rctSig& rv,
}
return true;
}
}
bool
url_decode(const std::string& in, std::string& out)
{
bool
url_decode(const std::string& in, std::string& out)
{
out.clear();
out.reserve(in.size());
for (std::size_t i = 0; i < in.size(); ++i)
@ -993,11 +993,11 @@ url_decode(const std::string& in, std::string& out)
}
}
return true;
}
}
map<std::string, std::string>
parse_crow_post_data(const string& req_body)
{
map<std::string, std::string>
parse_crow_post_data(const string& req_body)
{
map<std::string, std::string> body;
vector<string> vec;
@ -1020,15 +1020,15 @@ parse_crow_post_data(const string& req_body)
}
}
return body;
}
}
// from wallet2::decrypt
string
decrypt(const std::string &ciphertext,
string
decrypt(const std::string &ciphertext,
const crypto::secret_key &skey,
bool authenticated)
{
{
const size_t prefix_size = sizeof(chacha8_iv)
+ (authenticated ? sizeof(crypto::signature) : 0);
@ -1071,13 +1071,13 @@ decrypt(const std::string &ciphertext,
key, iv, &plaintext[0]);
return plaintext;
}
}
// based on
// crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const
public_key
get_tx_pub_key_from_received_outs(const transaction &tx)
{
public_key
get_tx_pub_key_from_received_outs(const transaction &tx)
{
std::vector<tx_extra_field> tx_extra_fields;
if(!parse_tx_extra(tx.extra, tx_extra_fields))
@ -1115,20 +1115,20 @@ get_tx_pub_key_from_received_outs(const transaction &tx)
}
return null_pkey;
}
}
/**
* Check if given output (specified by output_index)
* belongs is ours based
* on our private view key and public spend key
*/
bool
is_output_ours(const size_t& output_index,
bool
is_output_ours(const size_t& output_index,
const transaction& tx,
const public_key& pub_tx_key,
const secret_key& private_view_key,
const public_key& public_spend_key)
{
{
// public transaction key is combined with our viewkey
// to create, so called, derived key.
key_derivation derivation;
@ -1166,27 +1166,27 @@ is_output_ours(const size_t& output_index,
}
return false;
}
}
bool
get_real_output_for_key_image(const key_image& ki,
bool
get_real_output_for_key_image(const key_image& ki,
const transaction& tx,
const secret_key& private_view_key,
const public_key& public_spend_key,
uint64_t output_idx,
public_key output_pub_key)
{
{
return false;
}
}
bool
make_tx_from_json(const string& json_str, transaction& tx)
{
bool
make_tx_from_json(const string& json_str, transaction& tx)
{
json j;
try
@ -1448,12 +1448,12 @@ make_tx_from_json(const string& json_str, transaction& tx)
//cout << "From reconstructed tx: " << obj_to_json_str(tx) << endl;
return true;
}
}
string
make_printable(const string& in_s)
{
string
make_printable(const string& in_s)
{
string output;
for (char c: in_s)
@ -1486,13 +1486,13 @@ make_printable(const string& in_s)
}
return output;
}
}
string
get_human_readable_timestamp(uint64_t ts)
{
string
get_human_readable_timestamp(uint64_t ts)
{
char buffer[64];
if (ts < 1234567890)
return "<unknown>";
@ -1506,11 +1506,11 @@ get_human_readable_timestamp(uint64_t ts)
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M:%S", &tm);
return std::string(buffer);
}
}
void
pause_execution(uint64_t no_seconds, const string& text)
{
void
pause_execution(uint64_t no_seconds, const string& text)
{
cout << "\nPausing " << text
<< " for " << no_seconds << " seconds: "
@ -1523,7 +1523,6 @@ pause_execution(uint64_t no_seconds, const string& text)
}
cout << endl;
}
}
}

@ -19,7 +19,6 @@
#include "../ext/fmt/ostream.h"
#include "../ext/fmt/format.h"
#include "../ext/json.hpp"
#include "../ext/member_checker.h"
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
@ -41,19 +40,19 @@
namespace xmreg
{
using namespace cryptonote;
using namespace crypto;
using namespace std;
using namespace cryptonote;
using namespace crypto;
using namespace std;
namespace bf = boost::filesystem;
namespace pt = boost::posix_time;
namespace gt = boost::gregorian;
namespace lt = boost::local_time;
namespace bf = boost::filesystem;
namespace pt = boost::posix_time;
namespace gt = boost::gregorian;
namespace lt = boost::local_time;
using json = nlohmann::json;
using json = nlohmann::json;
struct outputs_visitor
{
struct outputs_visitor
{
std::vector<crypto::public_key >& m_output_keys;
const Blockchain& m_bch;
@ -68,159 +67,161 @@ struct outputs_visitor
m_output_keys.push_back(pubkey);
return true;
}
};
};
template <typename T>
bool
parse_str_secret_key(const string& key_str, T& secret_key);
template <typename T>
bool
parse_str_secret_key(const string& key_str, T& secret_key);
bool
get_tx_pub_key_from_str_hash(Blockchain& core_storage,
bool
get_tx_pub_key_from_str_hash(Blockchain& core_storage,
const string& hash_str,
transaction& tx);
bool
parse_str_address(const string& address_str,
bool
parse_str_address(const string& address_str,
account_public_address& address,
bool testnet = false);
inline bool
is_separator(char c);
inline bool
is_separator(char c);
string
print_address(const account_public_address& address,
string
print_address(const account_public_address& address,
bool testnet = false);
string
print_sig (const signature& sig);
string
print_sig (const signature& sig);
string
remove_trailing_path_separator(const string& in_path);
string
remove_trailing_path_separator(const string& in_path);
bf::path
remove_trailing_path_separator(const bf::path& in_path);
bf::path
remove_trailing_path_separator(const bf::path& in_path);
string
timestamp_to_str_gm(time_t timestamp, const char* format = "%F %T");
string
timestamp_to_str_gm(time_t timestamp, const char* format = "%F %T");
ostream&
operator<< (ostream& os, const account_public_address& addr);
ostream&
operator<< (ostream& os, const account_public_address& addr);
string
get_default_lmdb_folder(bool testnet = false);
string
get_default_lmdb_folder(bool testnet = false);
bool
generate_key_image(const crypto::key_derivation& derivation,
bool
generate_key_image(const crypto::key_derivation& derivation,
const std::size_t output_index,
const crypto::secret_key& sec_key,
const crypto::public_key& pub_key,
crypto::key_image& key_img);
bool
get_blockchain_path(const boost::optional<string>& bc_path,
bool
get_blockchain_path(const boost::optional<string>& bc_path,
bf::path& blockchain_path,
bool testnet = false);
uint64_t
sum_money_in_outputs(const transaction& tx);
uint64_t
sum_money_in_outputs(const transaction& tx);
pair<uint64_t, uint64_t>
sum_money_in_outputs(const string& json_str);
pair<uint64_t, uint64_t>
sum_money_in_outputs(const string& json_str);
pair<uint64_t, uint64_t>
sum_money_in_outputs(const json& _json);
pair<uint64_t, uint64_t>
sum_money_in_outputs(const json& _json);
array<uint64_t, 4>
summary_of_in_out_rct(
array<uint64_t, 4>
summary_of_in_out_rct(
const transaction& tx,
vector<pair<txout_to_key, uint64_t>>& output_pub_keys,
vector<txin_to_key>& input_key_imgs);
// this version for mempool txs from json
array<uint64_t, 6>
summary_of_in_out_rct(const json& _json);
array<uint64_t, 6>
summary_of_in_out_rct(const json& _json);
uint64_t
sum_money_in_inputs(const transaction& tx);
uint64_t
sum_money_in_inputs(const transaction& tx);
pair<uint64_t, uint64_t>
sum_money_in_inputs(const string& json_str);
pair<uint64_t, uint64_t>
sum_money_in_inputs(const string& json_str);
pair<uint64_t, uint64_t>
sum_money_in_inputs(const json& _json);
pair<uint64_t, uint64_t>
sum_money_in_inputs(const json& _json);
uint64_t
count_nonrct_inputs(const transaction& tx);
uint64_t
count_nonrct_inputs(const transaction& tx);
uint64_t
count_nonrct_inputs(const string& json_str);
uint64_t
count_nonrct_inputs(const string& json_str);
uint64_t
count_nonrct_inputs(const json& _json);
uint64_t
count_nonrct_inputs(const json& _json);
array<uint64_t, 2>
sum_money_in_tx(const transaction& tx);
array<uint64_t, 2>
sum_money_in_tx(const transaction& tx);
array<uint64_t, 2>
sum_money_in_txs(const vector<transaction>& txs);
array<uint64_t, 2>
sum_money_in_txs(const vector<transaction>& txs);
uint64_t
sum_fees_in_txs(const vector<transaction>& txs);
uint64_t
sum_fees_in_txs(const vector<transaction>& txs);
uint64_t
get_mixin_no(const transaction& tx);
uint64_t
get_mixin_no(const transaction& tx);
vector<uint64_t>
get_mixin_no(const string& json_str);
vector<uint64_t>
get_mixin_no(const string& json_str);
vector<uint64_t>
get_mixin_no(const json& _json);
vector<uint64_t>
get_mixin_no(const json& _json);
vector<uint64_t>
get_mixin_no_in_txs(const vector<transaction>& txs);
vector<uint64_t>
get_mixin_no_in_txs(const vector<transaction>& txs);
vector<pair<txout_to_key, uint64_t>>
get_ouputs(const transaction& tx);
vector<pair<txout_to_key, uint64_t>>
get_ouputs(const transaction& tx);
vector<tuple<txout_to_key, uint64_t, uint64_t>>
get_ouputs_tuple(const transaction& tx);
vector<tuple<txout_to_key, uint64_t, uint64_t>>
get_ouputs_tuple(const transaction& tx);
vector<txin_to_key>
get_key_images(const transaction& tx);
vector<txin_to_key>
get_key_images(const transaction& tx);
bool
get_payment_id(const vector<uint8_t>& extra,
bool
get_payment_id(const vector<uint8_t>& extra,
crypto::hash& payment_id,
crypto::hash8& payment_id8);
bool
get_payment_id(const transaction& tx,
bool
get_payment_id(const transaction& tx,
crypto::hash& payment_id,
crypto::hash8& payment_id8);
inline double
get_xmr(uint64_t core_amount)
{
inline double
get_xmr(uint64_t core_amount)
{
return static_cast<double>(core_amount) / 1e12;
}
}
array<size_t, 5>
timestamp_difference(uint64_t t1, uint64_t t2);
array<size_t, 5>
timestamp_difference(uint64_t t1, uint64_t t2);
string
read(string filename);
string
read(string filename);
/**
* prints an iterable such as vector
*/
template<typename T>
void print_iterable(const T & elems) {
template<typename T>
void print_iterable(const T & elems) {
infix_ostream_iterator<typename T::value_type>
oiter(std::cout, ",");
@ -228,51 +229,48 @@ void print_iterable(const T & elems) {
std::cout << "[";
std::copy(elems.begin(), elems.end(),oiter);
std::cout << "]" << std::endl;
}
}
pair<string, double>
timestamps_time_scale(const vector<uint64_t>& timestamps,
pair<string, double>
timestamps_time_scale(const vector<uint64_t>& timestamps,
uint64_t timeN, uint64_t resolution = 80,
uint64_t time0 = 1397818193 /* timestamp of the second block */);
time_t
ptime_to_time_t(const pt::ptime& in_ptime);
time_t
ptime_to_time_t(const pt::ptime& in_ptime);
bool
decode_ringct(const rct::rctSig & rv,
bool
decode_ringct(const rct::rctSig & rv,
const crypto::public_key pub,
const crypto::secret_key &sec,
unsigned int i,
rct::key & mask,
uint64_t & amount);
bool
url_decode(const std::string& in, std::string& out);
bool
url_decode(const std::string& in, std::string& out);
map<std::string, std::string>
parse_crow_post_data(const string& req_body);
map<std::string, std::string>
parse_crow_post_data(const string& req_body);
// from wallet2::decrypt
string
decrypt(const std::string &ciphertext,
string
decrypt(const std::string &ciphertext,
const crypto::secret_key &skey,
bool authenticated = true);
// based on
// crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const
public_key
get_tx_pub_key_from_received_outs(const transaction &tx);
date::sys_seconds
parse(const std::string& str, string format="%Y-%m-%d %H:%M:%S");
public_key
get_tx_pub_key_from_received_outs(const transaction &tx);
static
string
xmr_amount_to_str(const uint64_t& xmr_amount,
static
string
xmr_amount_to_str(const uint64_t& xmr_amount,
string _format="{:0.12f}",
bool zero_to_question_mark=true)
{
{
string amount_str = "?";
if (!zero_to_question_mark)
@ -288,17 +286,17 @@ xmr_amount_to_str(const uint64_t& xmr_amount,
}
return amount_str;
}
}
bool
is_output_ours(const size_t& output_index,
bool
is_output_ours(const size_t& output_index,
const transaction& tx,
const public_key& pub_tx_key,
const secret_key& private_view_key,
const public_key& public_spend_key);
bool
get_real_output_for_key_image(const key_image& ki,
bool
get_real_output_for_key_image(const key_image& ki,
const transaction& tx,
const secret_key& private_view_key,
const public_key& public_spend_key,
@ -306,12 +304,12 @@ get_real_output_for_key_image(const key_image& ki,
public_key output_pub_key);
// based on http://stackoverflow.com/a/9943098/248823
template<typename Iterator, typename Func>
void chunks(Iterator begin,
template<typename Iterator, typename Func>
void chunks(Iterator begin,
Iterator end,
iterator_traits<string::iterator>::difference_type k,
Func f)
{
{
Iterator chunk_begin;
Iterator chunk_end;
chunk_end = chunk_begin = begin;
@ -326,33 +324,33 @@ void chunks(Iterator begin,
chunk_begin = chunk_end;
}
while(std::distance(chunk_begin,end) > 0);
}
}
bool
make_tx_from_json(const string& json_str, transaction& tx);
bool
make_tx_from_json(const string& json_str, transaction& tx);
string
make_printable(const string& in_s);
string
make_printable(const string& in_s);
string
get_human_readable_timestamp(uint64_t ts);
string
get_human_readable_timestamp(uint64_t ts);
// Get the median of an unordered set of numbers of arbitrary
// type without modifying the underlying dataset.
// taken from http://stackoverflow.com/a/19695285
template <typename It>
typename std::iterator_traits<It>::value_type
calc_median(It it_begin, It it_end)
{
template <typename It>
typename std::iterator_traits<It>::value_type
calc_median(It it_begin, It it_end)
{
using T = typename std::iterator_traits<It>::value_type;
std::vector<T> data(it_begin, it_end);
std::nth_element(data.begin(), data.begin() + data.size() / 2, data.end());
return data[data.size() / 2];
}
}
void
pause_execution(uint64_t no_seconds, const string& text = "now");
void
pause_execution(uint64_t no_seconds, const string& text = "now");
}

Loading…
Cancel
Save