You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
6.2 KiB
C

9 years ago
//
// Created by mwo on 5/11/15.
9 years ago
//
#ifndef XMREG01_TOOLS_H
#define XMREG01_TOOLS_H
#define PATH_SEPARARTOR '/'
#define XMR_AMOUNT(value) \
static_cast<double>(value) / 1e12
#define REMOVE_HASH_BRAKETS(a_hash) \
a_hash.substr(1, a_hash.size()-2)
9 years ago
#include "monero_headers.h"
#include "../ext/infix_iterator.h"
#include "../ext/date/tz.h"
#include "../ext/format.h"
9 years ago
#include <boost/lexical_cast.hpp>
9 years ago
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
9 years ago
#include <string>
#include <vector>
#include <array>
/**
* Some helper functions used in the example.
* Names are rather self-explanatory, so I think
* there is no reason for any detailed explanations here
*/
namespace xmreg
{
using namespace cryptonote;
using namespace crypto;
using namespace std;
9 years ago
namespace bf = boost::filesystem;
namespace pt = boost::posix_time;
namespace gt = boost::gregorian;
namespace lt = boost::local_time;
9 years ago
struct outputs_visitor
{
std::vector<crypto::public_key >& m_output_keys;
9 years ago
const Blockchain& m_bch;
9 years ago
outputs_visitor(std::vector<crypto::public_key>& output_keys, const Blockchain& bch) :
m_output_keys(output_keys), m_bch(bch)
{
}
9 years ago
bool handle_output(uint64_t unlock_time, const crypto::public_key &pubkey)
{
m_output_keys.push_back(pubkey);
return true;
}
};
9 years ago
template <typename T>
bool
parse_str_secret_key(const string& key_str, T& secret_key);
9 years ago
bool
get_tx_pub_key_from_str_hash(Blockchain& core_storage,
const string& hash_str,
transaction& tx);
9 years ago
bool
parse_str_address(const string& address_str,
account_public_address& address,
bool testnet = false);
9 years ago
inline bool
is_separator(char c);
9 years ago
string
print_address(const account_public_address& address,
bool testnet = false);
9 years ago
string
print_sig (const signature& sig);
9 years ago
string
remove_trailing_path_separator(const string& in_path);
9 years ago
bf::path
remove_trailing_path_separator(const bf::path& in_path);
9 years ago
string
timestamp_to_str(time_t timestamp, const char* format = "%F %T");
9 years ago
string
timestamp_to_str_local(time_t timestamp, const char* format = "%F %T");
9 years ago
ostream&
operator<< (ostream& os, const account_public_address& addr);
9 years ago
string
get_default_lmdb_folder(bool testnet = false);
9 years ago
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);
9 years ago
bool
get_blockchain_path(const boost::optional<string>& bc_path,
bf::path& blockchain_path,
bool testnet = false);
9 years ago
uint64_t
sum_money_in_outputs(const transaction& tx);
uint64_t
sum_money_in_inputs(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);
uint64_t
sum_fees_in_txs(const vector<transaction>& txs);
uint64_t
get_mixin_no(const transaction& tx);
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<tuple<txout_to_key, uint64_t, uint64_t>>
get_ouputs_tuple(const transaction& tx);
vector<txin_to_key>
get_key_images(const transaction& tx);
9 years ago
bool
get_payment_id(const vector<uint8_t>& extra,
crypto::hash& payment_id,
crypto::hash8& payment_id8);
bool
get_payment_id(const transaction& tx,
crypto::hash& payment_id,
crypto::hash8& payment_id8);
inline void
enable_monero_log() {
uint32_t log_level = 0;
epee::log_space::get_set_log_detalisation_level(true, log_level);
epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
}
9 years ago
inline double
get_xmr(uint64_t core_amount)
{
return static_cast<double>(core_amount) / 1e12;
}
9 years ago
array<size_t, 5>
timestamp_difference(uint64_t t1, uint64_t t2);
9 years ago
string
read(string filename);
/**
* prints an iterable such as vector
*/
template<typename T>
void print_iterable(const T & elems) {
infix_ostream_iterator<typename T::value_type>
oiter(std::cout, ",");
std::cout << "[";
std::copy(elems.begin(), elems.end(),oiter);
std::cout << "]" << std::endl;
}
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 */);
9 years ago
time_t
ptime_to_time_t(const pt::ptime& in_ptime);
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);
map<std::string, std::string>
parse_crow_post_data(const string& req_body);
bool
get_dummy_account_keys(account_keys& dummy_keys, bool testnet = false);
// from wallet2::decrypt
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");
static
string
xmr_amount_to_str(const uint64_t& xmr_amount, string format="{:0.12f}")
{
return fmt::format("{:0.12f}", XMR_AMOUNT(xmr_amount));
}
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,
const transaction& tx,
const secret_key& private_view_key,
const public_key& public_spend_key,
uint64_t output_idx,
public_key output_pub_key);
9 years ago
}
#endif //XMREG01_TOOLS_H