fix merging problems

master
moneroexamples 8 years ago
parent b540bf5f72
commit c3c25fcb03

@ -16,11 +16,13 @@
#include "MicroCore.h" #include "MicroCore.h"
#include "tools.h" #include "tools.h"
#include "rpccalls.h" #include "rpccalls.h"
#include "../ext/crow/http_request.h" #include "../ext/crow/http_request.h"
#include "../ext/vpetrigocaches/cache.hpp" #include "../ext/vpetrigocaches/cache.hpp"
#include "../ext/vpetrigocaches/lru_cache_policy.hpp" #include "../ext/vpetrigocaches/lru_cache_policy.hpp"
#include "../ext/vpetrigocaches/fifo_cache_policy.hpp" #include "../ext/vpetrigocaches/fifo_cache_policy.hpp"
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
#include <ctime> #include <ctime>
@ -74,7 +76,6 @@ struct tx_info_cache
}; };
}; };
// indect overload of hash for tx_info_cache::key // indect overload of hash for tx_info_cache::key
namespace std namespace std
{ {
@ -95,12 +96,12 @@ namespace xmreg
{ {
using namespace cryptonote; using namespace cryptonote;
using namespace crypto; using namespace crypto;
using namespace std; using namespace std;
using epee::string_tools::pod_to_hex; using epee::string_tools::pod_to_hex;
using epee::string_tools::hex_to_pod; using epee::string_tools::hex_to_pod;
/** /**
* @brief The tx_details struct * @brief The tx_details struct
@ -108,8 +109,8 @@ using epee::string_tools::hex_to_pod;
* Basic information about tx * Basic information about tx
* *
*/ */
struct tx_details struct tx_details
{ {
crypto::hash hash; crypto::hash hash;
crypto::hash prefix_hash; crypto::hash prefix_hash;
crypto::public_key pk; crypto::public_key pk;
@ -139,23 +140,13 @@ struct tx_details
mstch::map mstch::map
get_mstch_map() const 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 mixin_str {"N/A"};
string fee_str {"N/A"}; string fee_str {"N/A"};
string fee_short_str {"N/A"}; string fee_short_str {"N/A"};
const double& xmr_amount = XMR_AMOUNT(fee); const double& xmr_amount = XMR_AMOUNT(fee);
if (!input_key_imgs.empty()) if (!input_key_imgs.empty())
{ {
mixin_str = std::to_string(mixin_no - 1); mixin_str = std::to_string(mixin_no - 1);
@ -163,7 +154,6 @@ struct tx_details
fee_short_str = fmt::format("{:0.3f}", xmr_amount); fee_short_str = fmt::format("{:0.3f}", xmr_amount);
} }
const double& tx_size = static_cast<double>(size)/1024.0; const double& tx_size = static_cast<double>(size)/1024.0;
mstch::map txd_map { mstch::map txd_map {
@ -201,7 +191,6 @@ struct tx_details
string string
get_extra_str() const get_extra_str() const
{ {
return epee::string_tools::buff_to_hex_nodelimer( return epee::string_tools::buff_to_hex_nodelimer(
string{reinterpret_cast<const char*>(extra.data()), extra.size()}); string{reinterpret_cast<const char*>(extra.data()), extra.size()});
} }
@ -237,11 +226,11 @@ struct tx_details
return ss.str(); return ss.str();
} }
}; };
class page class page
{ {
static const bool FULL_AGE_FORMAT {true}; static const bool FULL_AGE_FORMAT {true};
@ -251,6 +240,7 @@ class page
atomic<time_t> server_timestamp; atomic<time_t> server_timestamp;
bool testnet; bool testnet;
bool enable_pusher; bool enable_pusher;
@ -263,8 +253,8 @@ class page
bool enable_block_cache; bool enable_block_cache;
bool show_cache_times; bool show_cache_times;
bool enable_autorefresh_option;
bool enable_autorefresh_option;
uint64_t no_of_mempool_tx_of_frontpage; uint64_t no_of_mempool_tx_of_frontpage;
@ -272,6 +262,7 @@ class page
string testnet_url; string testnet_url;
string mainnet_url; string mainnet_url;
// instead of constatnly reading template files // instead of constatnly reading template files
// from hard drive for each request, we can read // from hard drive for each request, we can read
// them only once, when the explorer starts into this map // 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; 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; lru_cache_t<tx_info_cache::key, tx_info_cache> tx_context_cache;
public:
public:
page(MicroCore* _mcore, page(MicroCore* _mcore,
Blockchain* _core_storage, Blockchain* _core_storage,
@ -366,8 +359,6 @@ public:
no_of_mempool_tx_of_frontpage = 25; no_of_mempool_tx_of_frontpage = 25;
// read template files for all the pages // read template files for all the pages
// into template_file map // into template_file map
@ -389,7 +380,6 @@ public:
template_file["checkoutputkeys"] = get_full_page(xmreg::read(TMPL_MY_CHECKRAWOUTPUTKEYS)); template_file["checkoutputkeys"] = get_full_page(xmreg::read(TMPL_MY_CHECKRAWOUTPUTKEYS));
template_file["address"] = get_full_page(xmreg::read(TMPL_ADDRESS)); template_file["address"] = get_full_page(xmreg::read(TMPL_ADDRESS));
template_file["search_results"] = get_full_page(xmreg::read(TMPL_SEARCH_RESULTS)); 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_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_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"); 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); server_timestamp = std::time(nullptr);
uint64_t local_copy_server_timestamp = server_timestamp; uint64_t local_copy_server_timestamp = server_timestamp;
// number of last blocks to show // number of last blocks to show
uint64_t no_of_last_blocks {no_blocks_on_index + 1}; uint64_t no_of_last_blocks {no_blocks_on_index + 1};
@ -435,6 +426,7 @@ public:
{"enable_autorefresh_option", enable_autorefresh_option}, {"enable_autorefresh_option", enable_autorefresh_option},
{"show_cache_times" , show_cache_times} {"show_cache_times" , show_cache_times}
}; };
context.emplace("txs", mstch::array()); // will keep tx to show context.emplace("txs", mstch::array()); // will keep tx to show
// get reference to txs mstch map to be field below // get reference to txs mstch map to be field below
@ -458,6 +450,7 @@ public:
// loop index // loop index
int64_t i = end_height; int64_t i = end_height;
// iterate over last no_of_last_blocks of blocks // iterate over last no_of_last_blocks of blocks
while (i >= start_height) while (i >= start_height)
{ {
@ -686,6 +679,7 @@ public:
context["blk_size_median"] = fmt::format("{:0.2f}", blk_size_median); context["blk_size_median"] = fmt::format("{:0.2f}", blk_size_median);
// save computational times for disply in the frontend // save computational times for disply in the frontend
context["construction_time_cached"] = fmt::format( context["construction_time_cached"] = fmt::format(
@ -710,10 +704,8 @@ public:
// render the page // render the page
return mstch::render(template_file["index2"], context); return mstch::render(template_file["index2"], context);
} }
/** /**
* Render mempool data * Render mempool data
*/ */
@ -813,6 +805,7 @@ public:
try try
{ {
// get the above incormation from json of that tx // get the above incormation from json of that tx
json j_tx; json j_tx;
if (enable_mempool_cache && mempool_tx_json_cache.Contains(_tx_info.id_hash)) 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)) } // else if (mempool_tx_json_cache.Contains(_tx_info.id_hash))
} }
catch (std::invalid_argument& e) catch (std::invalid_argument& e)
{ {
@ -921,11 +915,8 @@ public:
{"no_inputs" , no_inputs}, {"no_inputs" , no_inputs},
{"no_outputs" , no_outputs}, {"no_outputs" , no_outputs},
{"no_nonrct_inputs", num_nonrct_inputs}, {"no_nonrct_inputs", num_nonrct_inputs},
{"is_ringct" , is_ringct_str}, {"mixin" , mixin_no},
{"rct_type" , rct_type_str}, {"txsize" , txsize}
{"mixin" , fmt::format("{:d}", mixin_no)},
{"txsize" , fmt::format("{:0.2f}",
static_cast<double>(_tx_info.blob_size)/1024.0)}
}); });
} }
@ -1402,10 +1393,8 @@ public:
{"tx_details", template_file["tx_details"]}, {"tx_details", template_file["tx_details"]},
}; };
add_css_style(context); add_css_style(context);
// render the page // render the page
return mstch::render(template_file["tx"], context, partials); return mstch::render(template_file["tx"], context, partials);
} }
@ -2139,11 +2128,13 @@ public:
{"error_msg" , string {}}, {"error_msg" , string {}},
{"data_prefix" , data_prefix}, {"data_prefix" , data_prefix},
}; };
context.emplace("txs", mstch::array{}); context.emplace("txs", mstch::array{});
string full_page = template_file["checkrawtx"]; string full_page = template_file["checkrawtx"];
add_css_style(context); add_css_style(context);
if (unsigned_tx_given) if (unsigned_tx_given)
{ {
@ -2481,7 +2472,6 @@ public:
{"tx_details", template_file["tx_details"]}, {"tx_details", template_file["tx_details"]},
}; };
add_css_style(context); add_css_style(context);
// render the page // render the page
@ -2731,7 +2721,6 @@ public:
{"tx_details", template_file["tx_details"]}, {"tx_details", template_file["tx_details"]},
}; };
// render the page // render the page
return mstch::render(full_page, context, partials); return mstch::render(full_page, context, partials);
} }
@ -3057,7 +3046,6 @@ public:
context.insert({"key_imgs" , mstch::array{}}); context.insert({"key_imgs" , mstch::array{}});
size_t no_key_images = (decoded_raw_data.size() - header_lenght) / record_lenght; size_t no_key_images = (decoded_raw_data.size() - header_lenght) / record_lenght;
//vector<pair<crypto::key_image, crypto::signature>> signed_key_images; //vector<pair<crypto::key_image, crypto::signature>> signed_key_images;
@ -3082,7 +3070,6 @@ public:
// so this will be empty always for now. // so this will be empty always for now.
vector<string> found_tx_hashes; vector<string> found_tx_hashes;
mstch::map key_img_info { mstch::map key_img_info {
{"key_no" , fmt::format("{:03d}", n)}, {"key_no" , fmt::format("{:03d}", n)},
{"key_image" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", key_image))}, {"key_image" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", key_image))},
@ -3541,6 +3528,7 @@ public:
return result_html; return result_html;
} }
// first check if searching for block of given height // first check if searching for block of given height
if (search_text.size() < 12) if (search_text.size() < 12)
{ {
@ -3577,6 +3565,7 @@ public:
result_html = default_txt; result_html = default_txt;
// check if monero address is given based on its length // check if monero address is given based on its length
// if yes, then we can only show its public components // if yes, then we can only show its public components
if (search_str_length == 95) if (search_str_length == 95)
@ -3629,11 +3618,8 @@ public:
// all_possible_tx_hashes was field using custom lmdb database // all_possible_tx_hashes was field using custom lmdb database
// it was dropped, so all_possible_tx_hashes will be alwasy empty // it was dropped, so all_possible_tx_hashes will be alwasy empty
// for now // for now
vector<pair<string, vector<string>>> all_possible_tx_hashes; vector<pair<string, vector<string>>> all_possible_tx_hashes;
result_html = show_search_results(search_text, all_possible_tx_hashes); result_html = show_search_results(search_text, all_possible_tx_hashes);
return result_html; return result_html;
@ -3762,7 +3748,6 @@ public:
} }
string string
show_search_results(const string& search_text, show_search_results(const string& search_text,
const vector<pair<string, vector<string>>>& all_possible_tx_hashes) const vector<pair<string, vector<string>>>& all_possible_tx_hashes)
@ -4582,7 +4567,7 @@ public:
return j_response; return j_response;
} }
private: private:
json json
get_tx_json(const transaction& tx, const tx_details& txd) get_tx_json(const transaction& tx, const tx_details& txd)
@ -4641,6 +4626,7 @@ private:
return true; return true;
} }
void void
mark_real_mixins_on_timescales( mark_real_mixins_on_timescales(
const vector<uint64_t>& real_output_indices, const vector<uint64_t>& real_output_indices,
@ -4681,7 +4667,6 @@ private:
mstch::map mstch::map
construct_tx_context(transaction tx, uint16_t with_ring_signatures = 0) construct_tx_context(transaction tx, uint16_t with_ring_signatures = 0)
{ {
tx_details txd = get_tx_details(tx); tx_details txd = get_tx_details(tx);
const crypto::hash& tx_hash = txd.hash; const crypto::hash& tx_hash = txd.hash;
@ -4693,6 +4678,7 @@ private:
bool tx_blk_found {false}; bool tx_blk_found {false};
bool detailed_view {enable_mixins_details || static_cast<bool>(with_ring_signatures)}; bool detailed_view {enable_mixins_details || static_cast<bool>(with_ring_signatures)};
if (core_storage->have_tx(tx_hash)) if (core_storage->have_tx(tx_hash))
{ {
// currently get_tx_block_height seems to return a block hight // currently get_tx_block_height seems to return a block hight
@ -4798,15 +4784,19 @@ private:
{ {
show_part_of_inputs = false; show_part_of_inputs = false;
} }
vector<vector<uint64_t>> mixin_timestamp_groups; vector<vector<uint64_t>> mixin_timestamp_groups;
// make timescale maps for mixins in input // make timescale maps for mixins in input
for (const txin_to_key &in_key: txd.input_key_imgs) for (const txin_to_key &in_key: txd.input_key_imgs)
{ {
if (show_part_of_inputs && (input_idx > max_no_of_inputs_to_show)) if (show_part_of_inputs && (input_idx > max_no_of_inputs_to_show))
{ {
break; break;
} }
// get absolute offsets of mixins // get absolute offsets of mixins
std::vector<uint64_t> absolute_offsets std::vector<uint64_t> absolute_offsets
= cryptonote::relative_output_offsets_to_absolute( = cryptonote::relative_output_offsets_to_absolute(
@ -4855,6 +4845,8 @@ private:
boost::get<mstch::map>(inputs.back())["ring_sigs"] boost::get<mstch::map>(inputs.back())["ring_sigs"]
= txd.get_ring_sig_for_input(input_idx); = txd.get_ring_sig_for_input(input_idx);
} }
inputs_xmr_sum += in_key.amount; inputs_xmr_sum += in_key.amount;
if (in_key.amount == 0) if (in_key.amount == 0)
@ -4973,6 +4965,7 @@ private:
mixin_timestamp_groups.push_back(mixin_timestamps); mixin_timestamp_groups.push_back(mixin_timestamps);
input_idx++; input_idx++;
} // for (const txin_to_key& in_key: txd.input_key_imgs) } // for (const txin_to_key& in_key: txd.input_key_imgs)
@ -5148,13 +5141,13 @@ private:
// get tx hash // get tx hash
txd.hash = get_transaction_hash(tx); txd.hash = get_transaction_hash(tx);
// get tx public key from extra // get tx public key from extra
// this check if there are two public keys // this check if there are two public keys
// due to previous bug with sining txs: // due to previous bug with sining txs:
// https://github.com/monero-project/monero/pull/1358/commits/7abfc5474c0f86e16c405f154570310468b635c2 // https://github.com/monero-project/monero/pull/1358/commits/7abfc5474c0f86e16c405f154570310468b635c2
txd.pk = xmreg::get_tx_pub_key_from_received_outs(tx); txd.pk = xmreg::get_tx_pub_key_from_received_outs(tx);
// sum xmr in inputs and ouputs in the given tx // sum xmr in inputs and ouputs in the given tx
const array<uint64_t, 4>& sum_data = summary_of_in_out_rct( const array<uint64_t, 4>& sum_data = summary_of_in_out_rct(
tx, txd.output_pub_keys, txd.input_key_imgs); tx, txd.output_pub_keys, txd.input_key_imgs);
@ -5166,11 +5159,6 @@ private:
txd.fee = 0; txd.fee = 0;
transaction tx_copy = tx;
txd.json_representation = obj_to_json_str(tx_copy);
if (!coinbase && tx.vin.size() > 0) if (!coinbase && tx.vin.size() > 0)
{ {
// check if not miner tx // check if not miner tx
@ -5184,8 +5172,6 @@ private:
get_payment_id(tx, txd.payment_id, txd.payment_id8); get_payment_id(tx, txd.payment_id, txd.payment_id8);
// get tx size in bytes // get tx size in bytes
txd.size = get_object_blobsize(tx); txd.size = get_object_blobsize(tx);
@ -5207,6 +5193,7 @@ private:
// if blk_height is zero then search for tx block in // if blk_height is zero then search for tx block in
// the blockchain. but since often block height is know a priory // the blockchain. but since often block height is know a priory
// this is not needed // this is not needed
txd.blk_height = core_storage->get_db().get_tx_block_height(txd.hash); txd.blk_height = core_storage->get_db().get_tx_block_height(txd.hash);
// get the current blockchain height. Just to check // 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 * into crypto::secret_key or crypto::public_key
* depending on the template argument. * depending on the template argument.
*/ */
template <typename T> template <typename T>
bool bool
parse_str_secret_key(const string& key_str, T& secret_key) parse_str_secret_key(const string& key_str, T& secret_key)
{ {
// hash and keys have same structure, so to parse string of // 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 // 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); copy(begin(hash_.data), end(hash_.data), secret_key.data);
return true; return true;
} }
// explicit instantiations of get template function // 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::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::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::hash>(const string& key_str, crypto::hash& secret_key);
/** /**
* Get transaction tx using given tx hash. Hash is represent as string here, * 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 * so before we can tap into the blockchain, we need to pare it into
* crypto::hash object. * crypto::hash object.
*/ */
bool bool
get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, transaction& tx) get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, transaction& tx)
{ {
crypto::hash tx_hash; crypto::hash tx_hash;
parse_hash256(hash_str, 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; return true;
} }
/** /**
* Parse monero address in a string form into * Parse monero address in a string form into
* cryptonote::account_public_address object * cryptonote::account_public_address object
*/ */
bool bool
parse_str_address(const string& address_str, parse_str_address(const string& address_str,
account_public_address& address, account_public_address& address,
bool testnet) bool testnet)
{ {
if (!get_account_address_from_str(address, testnet, address_str)) if (!get_account_address_from_str(address, testnet, address_str))
{ {
@ -87,58 +87,58 @@ parse_str_address(const string& address_str,
} }
return true; return true;
} }
/** /**
* Return string representation of monero address * Return string representation of monero address
*/ */
string string
print_address(const account_public_address& address, bool testnet) print_address(const account_public_address& address, bool testnet)
{ {
return "<" + get_account_address_as_str(testnet, address) + ">"; return "<" + get_account_address_as_str(testnet, address) + ">";
} }
string string
print_sig (const signature& sig) print_sig (const signature& sig)
{ {
stringstream ss; stringstream ss;
ss << "c: <" << epee::string_tools::pod_to_hex(sig.c) << "> " ss << "c: <" << epee::string_tools::pod_to_hex(sig.c) << "> "
<< "r: <" << epee::string_tools::pod_to_hex(sig.r) << ">"; << "r: <" << epee::string_tools::pod_to_hex(sig.r) << ">";
return ss.str(); return ss.str();
} }
/** /**
* Check if a character is a path seprator * Check if a character is a path seprator
*/ */
inline bool inline bool
is_separator(char c) is_separator(char c)
{ {
// default linux path separator // default linux path separator
const char separator = PATH_SEPARARTOR; const char separator = PATH_SEPARARTOR;
return c == separator; return c == separator;
} }
/** /**
* Remove trailinig path separator. * Remove trailinig path separator.
*/ */
string string
remove_trailing_path_separator(const string& in_path) remove_trailing_path_separator(const string& in_path)
{ {
string new_string = in_path; string new_string = in_path;
if (!new_string.empty() && is_separator(new_string[new_string.size() - 1])) if (!new_string.empty() && is_separator(new_string[new_string.size() - 1]))
new_string.erase(new_string.size() - 1); new_string.erase(new_string.size() - 1);
return new_string; return new_string;
} }
bf::path bf::path
remove_trailing_path_separator(const bf::path& in_path) remove_trailing_path_separator(const bf::path& in_path)
{ {
#ifdef WIN32 #ifdef WIN32
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
string path_str = converter.to_bytes(in_path.native()); 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(); string path_str = in_path.native();
#endif #endif
return bf::path(remove_trailing_path_separator(path_str)); return bf::path(remove_trailing_path_separator(path_str));
} }
//string //string
//timestamp_to_str(time_t timestamp, const char* format) //timestamp_to_str(time_t timestamp, const char* format)
@ -155,9 +155,9 @@ remove_trailing_path_separator(const bf::path& in_path)
//} //}
string string
timestamp_to_str_gm(time_t timestamp, const char* format) timestamp_to_str_gm(time_t timestamp, const char* format)
{ {
const time_t* t = &timestamp; const time_t* t = &timestamp;
const int TIME_LENGTH = 60; 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); len = std::strftime(str_buff, TIME_LENGTH, format, &tmp);
return string(str_buff, len); return string(str_buff, len);
} }
ostream& ostream&
operator<< (ostream& os, const account_public_address& addr) operator<< (ostream& os, const account_public_address& addr)
{ {
os << get_account_address_as_str(false, addr); os << get_account_address_as_str(false, addr);
return os; return os;
} }
/* /*
* Generate key_image of foran ith output * Generate key_image of foran ith output
*/ */
bool bool
generate_key_image(const crypto::key_derivation& derivation, generate_key_image(const crypto::key_derivation& derivation,
const std::size_t i, const std::size_t i,
const crypto::secret_key& sec_key, const crypto::secret_key& sec_key,
const crypto::public_key& pub_key, const crypto::public_key& pub_key,
crypto::key_image& key_img) crypto::key_image& key_img)
{ {
cryptonote::keypair in_ephemeral; cryptonote::keypair in_ephemeral;
@ -230,12 +230,12 @@ generate_key_image(const crypto::key_derivation& derivation,
} }
return true; return true;
} }
string string
get_default_lmdb_folder(bool testnet) get_default_lmdb_folder(bool testnet)
{ {
// default path to monero folder // default path to monero folder
// on linux this is /home/<username>/.bitmonero // on linux this is /home/<username>/.bitmonero
string default_monero_dir = tools::get_default_data_dir(); 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 // the default folder of the lmdb blockchain database
// is therefore as follows // is therefore as follows
return default_monero_dir + string("/lmdb"); return default_monero_dir + string("/lmdb");
} }
/* /*
@ -255,11 +255,11 @@ get_default_lmdb_folder(bool testnet)
* *
* If not given, provide default path * If not given, provide default path
*/ */
bool bool
get_blockchain_path(const boost::optional<string>& bc_path, get_blockchain_path(const boost::optional<string>& bc_path,
bf::path& blockchain_path, bf::path& blockchain_path,
bool testnet) bool testnet)
{ {
// the default folder of the lmdb blockchain database // the default folder of the lmdb blockchain database
string default_lmdb_dir = xmreg::get_default_lmdb_folder(testnet); 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); blockchain_path = xmreg::remove_trailing_path_separator(blockchain_path);
return true; return true;
} }
uint64_t uint64_t
sum_money_in_outputs(const transaction& tx) sum_money_in_outputs(const transaction& tx)
{ {
uint64_t sum_xmr {0}; uint64_t sum_xmr {0};
for (const tx_out& txout: tx.vout) for (const tx_out& txout: tx.vout)
@ -293,11 +293,11 @@ sum_money_in_outputs(const transaction& tx)
} }
return sum_xmr; return sum_xmr;
} }
pair<uint64_t, uint64_t> pair<uint64_t, uint64_t>
sum_money_in_outputs(const string& json_str) sum_money_in_outputs(const string& json_str)
{ {
pair<uint64_t, uint64_t> sum_xmr {0, 0}; pair<uint64_t, uint64_t> sum_xmr {0, 0};
json j; json j;
@ -320,11 +320,11 @@ sum_money_in_outputs(const string& json_str)
return sum_xmr; return sum_xmr;
}; };
pair<uint64_t, uint64_t> pair<uint64_t, uint64_t>
sum_money_in_outputs(const json& _json) sum_money_in_outputs(const json& _json)
{ {
pair<uint64_t, uint64_t> sum_xmr {0ULL, 0ULL}; pair<uint64_t, uint64_t> sum_xmr {0ULL, 0ULL};
for (const json& vout: _json["vout"]) for (const json& vout: _json["vout"])
@ -334,15 +334,15 @@ sum_money_in_outputs(const json& _json)
} }
return sum_xmr; return sum_xmr;
}; };
array<uint64_t, 4> array<uint64_t, 4>
summary_of_in_out_rct( summary_of_in_out_rct(
const transaction& tx, const transaction& tx,
vector<pair<txout_to_key, uint64_t>>& output_pub_keys, vector<pair<txout_to_key, uint64_t>>& output_pub_keys,
vector<txin_to_key>& input_key_imgs) vector<txin_to_key>& input_key_imgs)
{ {
uint64_t xmr_outputs {0}; uint64_t xmr_outputs {0};
uint64_t xmr_inputs {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}; return {xmr_outputs, xmr_inputs, mixin_no, num_nonrct_inputs};
}; };
// this version for mempool txs from json // this version for mempool txs from json
array<uint64_t, 6> array<uint64_t, 6>
summary_of_in_out_rct(const json& _json) summary_of_in_out_rct(const json& _json)
{ {
uint64_t xmr_outputs {0}; uint64_t xmr_outputs {0};
uint64_t xmr_inputs {0}; uint64_t xmr_inputs {0};
uint64_t no_outputs {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; 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}; return {xmr_outputs, xmr_inputs, no_outputs, no_inputs, mixin_no, num_nonrct_inputs};
}; };
uint64_t uint64_t
sum_money_in_inputs(const transaction& tx) sum_money_in_inputs(const transaction& tx)
{ {
uint64_t sum_xmr {0}; uint64_t sum_xmr {0};
size_t input_no = tx.vin.size(); size_t input_no = tx.vin.size();
@ -462,11 +462,11 @@ sum_money_in_inputs(const transaction& tx)
} }
return sum_xmr; return sum_xmr;
} }
pair<uint64_t, uint64_t> pair<uint64_t, uint64_t>
sum_money_in_inputs(const string& json_str) sum_money_in_inputs(const string& json_str)
{ {
pair<uint64_t, uint64_t> sum_xmr {0, 0}; pair<uint64_t, uint64_t> sum_xmr {0, 0};
json j; json j;
@ -487,12 +487,12 @@ sum_money_in_inputs(const string& json_str)
} }
return sum_xmr; return sum_xmr;
}; };
pair<uint64_t, uint64_t> pair<uint64_t, uint64_t>
sum_money_in_inputs(const json& _json) sum_money_in_inputs(const json& _json)
{ {
pair<uint64_t, uint64_t> sum_xmr {0, 0}; pair<uint64_t, uint64_t> sum_xmr {0, 0};
for (const json& vin: _json["vin"]) for (const json& vin: _json["vin"])
@ -502,11 +502,11 @@ sum_money_in_inputs(const json& _json)
} }
return sum_xmr; return sum_xmr;
}; };
uint64_t uint64_t
count_nonrct_inputs(const transaction& tx) count_nonrct_inputs(const transaction& tx)
{ {
uint64_t num {0}; uint64_t num {0};
size_t input_no = tx.vin.size(); size_t input_no = tx.vin.size();
@ -528,11 +528,11 @@ count_nonrct_inputs(const transaction& tx)
} }
return num; return num;
} }
uint64_t uint64_t
count_nonrct_inputs(const string& json_str) count_nonrct_inputs(const string& json_str)
{ {
uint64_t num {0}; uint64_t num {0};
json j; json j;
@ -554,12 +554,12 @@ count_nonrct_inputs(const string& json_str)
} }
return num; return num;
}; };
uint64_t uint64_t
count_nonrct_inputs(const json& _json) count_nonrct_inputs(const json& _json)
{ {
uint64_t num {0}; uint64_t num {0};
for (const json& vin: _json["vin"]) for (const json& vin: _json["vin"])
@ -570,23 +570,23 @@ count_nonrct_inputs(const json& _json)
} }
return num; return num;
}; };
array<uint64_t, 2> array<uint64_t, 2>
sum_money_in_tx(const transaction& tx) sum_money_in_tx(const transaction& tx)
{ {
array<uint64_t, 2> sum_xmr; array<uint64_t, 2> sum_xmr;
sum_xmr[0] = sum_money_in_inputs(tx); sum_xmr[0] = sum_money_in_inputs(tx);
sum_xmr[1] = sum_money_in_outputs(tx); sum_xmr[1] = sum_money_in_outputs(tx);
return sum_xmr; return sum_xmr;
}; };
array<uint64_t, 2> array<uint64_t, 2>
sum_money_in_txs(const vector<transaction>& txs) sum_money_in_txs(const vector<transaction>& txs)
{ {
array<uint64_t, 2> sum_xmr {0,0}; array<uint64_t, 2> sum_xmr {0,0};
for (const transaction& tx: txs) for (const transaction& tx: txs)
@ -596,12 +596,12 @@ sum_money_in_txs(const vector<transaction>& txs)
} }
return sum_xmr; return sum_xmr;
}; };
uint64_t uint64_t
sum_fees_in_txs(const vector<transaction>& txs) sum_fees_in_txs(const vector<transaction>& txs)
{ {
uint64_t fees_sum {0}; uint64_t fees_sum {0};
for (const transaction& tx: txs) for (const transaction& tx: txs)
@ -610,13 +610,13 @@ sum_fees_in_txs(const vector<transaction>& txs)
} }
return fees_sum; return fees_sum;
} }
vector<pair<txout_to_key, uint64_t>> vector<pair<txout_to_key, uint64_t>>
get_ouputs(const transaction& tx) get_ouputs(const transaction& tx)
{ {
vector<pair<txout_to_key, uint64_t>> outputs; vector<pair<txout_to_key, uint64_t>> outputs;
for (const tx_out& txout: tx.vout) for (const tx_out& txout: tx.vout)
@ -637,11 +637,11 @@ get_ouputs(const transaction& tx)
return outputs; return outputs;
}; };
vector<tuple<txout_to_key, uint64_t, uint64_t>> vector<tuple<txout_to_key, uint64_t, uint64_t>>
get_ouputs_tuple(const transaction& tx) get_ouputs_tuple(const transaction& tx)
{ {
vector<tuple<txout_to_key, uint64_t, uint64_t>> outputs; vector<tuple<txout_to_key, uint64_t, uint64_t>> outputs;
for (uint64_t n = 0; n < tx.vout.size(); ++n) for (uint64_t n = 0; n < tx.vout.size(); ++n)
@ -660,11 +660,11 @@ get_ouputs_tuple(const transaction& tx)
} }
return outputs; return outputs;
}; };
uint64_t uint64_t
get_mixin_no(const transaction& tx) get_mixin_no(const transaction& tx)
{ {
uint64_t mixin_no {0}; uint64_t mixin_no {0};
size_t input_no = tx.vin.size(); size_t input_no = tx.vin.size();
@ -692,10 +692,10 @@ get_mixin_no(const transaction& tx)
} }
return mixin_no; return mixin_no;
} }
vector<uint64_t> vector<uint64_t>
get_mixin_no(const string& json_str) get_mixin_no(const string& json_str)
{ {
vector<uint64_t> mixin_no; vector<uint64_t> mixin_no;
json j; json j;
@ -713,23 +713,23 @@ get_mixin_no(const string& json_str)
} }
return mixin_no; return mixin_no;
} }
vector<uint64_t> vector<uint64_t>
get_mixin_no(const json& _json) get_mixin_no(const json& _json)
{ {
vector<uint64_t> mixin_no; vector<uint64_t> mixin_no;
mixin_no.push_back(_json["vin"].at(0)["key"]["key_offsets"].size()); mixin_no.push_back(_json["vin"].at(0)["key"]["key_offsets"].size());
return mixin_no; return mixin_no;
} }
vector<uint64_t> vector<uint64_t>
get_mixin_no_in_txs(const vector<transaction>& txs) get_mixin_no_in_txs(const vector<transaction>& txs)
{ {
vector<uint64_t> mixin_no; vector<uint64_t> mixin_no;
for (const transaction& tx: txs) for (const transaction& tx: txs)
@ -738,12 +738,12 @@ get_mixin_no_in_txs(const vector<transaction>& txs)
} }
return mixin_no; return mixin_no;
} }
vector<txin_to_key> vector<txin_to_key>
get_key_images(const transaction& tx) get_key_images(const transaction& tx)
{ {
vector<txin_to_key> key_images; vector<txin_to_key> key_images;
size_t input_no = tx.vin.size(); size_t input_no = tx.vin.size();
@ -764,14 +764,14 @@ get_key_images(const transaction& tx)
} }
return key_images; return key_images;
} }
bool bool
get_payment_id(const vector<uint8_t>& extra, get_payment_id(const vector<uint8_t>& extra,
crypto::hash& payment_id, crypto::hash& payment_id,
crypto::hash8& payment_id8) crypto::hash8& payment_id8)
{ {
payment_id = null_hash; payment_id = null_hash;
payment_id8 = null_hash8; payment_id8 = null_hash8;
@ -798,21 +798,21 @@ get_payment_id(const vector<uint8_t>& extra,
} }
return false; return false;
} }
bool bool
get_payment_id(const transaction& tx, get_payment_id(const transaction& tx,
crypto::hash& payment_id, crypto::hash& payment_id,
crypto::hash8& payment_id8) crypto::hash8& payment_id8)
{ {
return get_payment_id(tx.extra, payment_id, payment_id8); return get_payment_id(tx.extra, payment_id, payment_id8);
} }
array<size_t, 5> array<size_t, 5>
timestamp_difference(uint64_t t1, uint64_t t2) timestamp_difference(uint64_t t1, uint64_t t2)
{ {
uint64_t timestamp_diff = t1 - 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_hours, time_diff_minutes,
time_diff_seconds}; time_diff_seconds};
}; };
string string
read(string filename) read(string filename)
{ {
if (!bf::exists(bf::path(filename))) if (!bf::exists(bf::path(filename)))
{ {
cerr << "File does not exist: " << filename << endl; cerr << "File does not exist: " << filename << endl;
@ -859,14 +859,14 @@ read(string filename)
std::ifstream t(filename); std::ifstream t(filename);
return string(std::istreambuf_iterator<char>(t), return string(std::istreambuf_iterator<char>(t),
std::istreambuf_iterator<char>()); std::istreambuf_iterator<char>());
} }
pair<string, double> pair<string, double>
timestamps_time_scale(const vector<uint64_t>& timestamps, timestamps_time_scale(const vector<uint64_t>& timestamps,
uint64_t timeN, uint64_t timeN,
uint64_t resolution, uint64_t resolution,
uint64_t time0) uint64_t time0)
{ {
string empty_time = string(resolution, '_'); string empty_time = string(resolution, '_');
size_t time_axis_length = empty_time.size(); 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); return make_pair(empty_time, scale);
} }
// useful reference to get epoch time in correct timezon // 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 // http://www.boost.org/doc/libs/1_41_0/doc/html/date_time/examples.html#date_time.examples.seconds_since_epoch
time_t time_t
ptime_to_time_t(const pt::ptime& in_ptime) ptime_to_time_t(const pt::ptime& in_ptime)
{ {
static pt::ptime epoch(gt::date(1970, 1, 1)); static pt::ptime epoch(gt::date(1970, 1, 1));
pt::time_duration::sec_type no_seconds = (in_ptime - epoch).total_seconds(); pt::time_duration::sec_type no_seconds = (in_ptime - epoch).total_seconds();
return time_t(no_seconds); return time_t(no_seconds);
} }
bool bool
decode_ringct(const rct::rctSig& rv, decode_ringct(const rct::rctSig& rv,
const crypto::public_key pub, const crypto::public_key pub,
const crypto::secret_key &sec, const crypto::secret_key &sec,
unsigned int i, unsigned int i,
rct::key & mask, rct::key & mask,
uint64_t & amount) uint64_t & amount)
{ {
try try
{ {
crypto::key_derivation derivation; crypto::key_derivation derivation;
@ -953,11 +953,11 @@ decode_ringct(const rct::rctSig& rv,
} }
return true; return true;
} }
bool bool
url_decode(const std::string& in, std::string& out) url_decode(const std::string& in, std::string& out)
{ {
out.clear(); out.clear();
out.reserve(in.size()); out.reserve(in.size());
for (std::size_t i = 0; i < in.size(); ++i) 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; return true;
} }
map<std::string, std::string> map<std::string, std::string>
parse_crow_post_data(const string& req_body) parse_crow_post_data(const string& req_body)
{ {
map<std::string, std::string> body; map<std::string, std::string> body;
vector<string> vec; vector<string> vec;
@ -1020,15 +1020,15 @@ parse_crow_post_data(const string& req_body)
} }
} }
return body; return body;
} }
// from wallet2::decrypt // from wallet2::decrypt
string string
decrypt(const std::string &ciphertext, decrypt(const std::string &ciphertext,
const crypto::secret_key &skey, const crypto::secret_key &skey,
bool authenticated) bool authenticated)
{ {
const size_t prefix_size = sizeof(chacha8_iv) const size_t prefix_size = sizeof(chacha8_iv)
+ (authenticated ? sizeof(crypto::signature) : 0); + (authenticated ? sizeof(crypto::signature) : 0);
@ -1071,13 +1071,13 @@ decrypt(const std::string &ciphertext,
key, iv, &plaintext[0]); key, iv, &plaintext[0]);
return plaintext; return plaintext;
} }
// based on // based on
// crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const // crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const
public_key public_key
get_tx_pub_key_from_received_outs(const transaction &tx) get_tx_pub_key_from_received_outs(const transaction &tx)
{ {
std::vector<tx_extra_field> tx_extra_fields; std::vector<tx_extra_field> tx_extra_fields;
if(!parse_tx_extra(tx.extra, 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; return null_pkey;
} }
/** /**
* Check if given output (specified by output_index) * Check if given output (specified by output_index)
* belongs is ours based * belongs is ours based
* on our private view key and public spend key * on our private view key and public spend key
*/ */
bool bool
is_output_ours(const size_t& output_index, is_output_ours(const size_t& output_index,
const transaction& tx, const transaction& tx,
const public_key& pub_tx_key, const public_key& pub_tx_key,
const secret_key& private_view_key, const secret_key& private_view_key,
const public_key& public_spend_key) const public_key& public_spend_key)
{ {
// public transaction key is combined with our viewkey // public transaction key is combined with our viewkey
// to create, so called, derived key. // to create, so called, derived key.
key_derivation derivation; key_derivation derivation;
@ -1166,27 +1166,27 @@ is_output_ours(const size_t& output_index,
} }
return false; return false;
} }
bool bool
get_real_output_for_key_image(const key_image& ki, get_real_output_for_key_image(const key_image& ki,
const transaction& tx, const transaction& tx,
const secret_key& private_view_key, const secret_key& private_view_key,
const public_key& public_spend_key, const public_key& public_spend_key,
uint64_t output_idx, uint64_t output_idx,
public_key output_pub_key) public_key output_pub_key)
{ {
return false; return false;
} }
bool bool
make_tx_from_json(const string& json_str, transaction& tx) make_tx_from_json(const string& json_str, transaction& tx)
{ {
json j; json j;
try 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; //cout << "From reconstructed tx: " << obj_to_json_str(tx) << endl;
return true; return true;
} }
string string
make_printable(const string& in_s) make_printable(const string& in_s)
{ {
string output; string output;
for (char c: in_s) for (char c: in_s)
@ -1486,13 +1486,13 @@ make_printable(const string& in_s)
} }
return output; return output;
} }
string string
get_human_readable_timestamp(uint64_t ts) get_human_readable_timestamp(uint64_t ts)
{ {
char buffer[64]; char buffer[64];
if (ts < 1234567890) if (ts < 1234567890)
return "<unknown>"; return "<unknown>";
@ -1506,11 +1506,11 @@ get_human_readable_timestamp(uint64_t ts)
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M:%S", &tm); strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M:%S", &tm);
return std::string(buffer); return std::string(buffer);
} }
void void
pause_execution(uint64_t no_seconds, const string& text) pause_execution(uint64_t no_seconds, const string& text)
{ {
cout << "\nPausing " << text cout << "\nPausing " << text
<< " for " << no_seconds << " seconds: " << " for " << no_seconds << " seconds: "
@ -1523,7 +1523,6 @@ pause_execution(uint64_t no_seconds, const string& text)
} }
cout << endl; cout << endl;
} }
} }

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

Loading…
Cancel
Save