tx_details class removed as it is not used

master
moneroexamples 8 years ago
parent 8a731907f5
commit 08e22f4870

@ -6,13 +6,12 @@ set(SOURCE_HEADERS
MicroCore.h
tools.h
monero_headers.h
tx_details.h)
)
set(SOURCE_FILES
MicroCore.cpp
tools.cpp
CmdLineOptions.cpp
tx_details.cpp
page.h
rpccalls.cpp rpccalls.h version.h.in)

@ -8,8 +8,7 @@
#include <iostream>
#include "monero_headers.h"
#include "tx_details.h"
#include "tools.h"
namespace xmreg
{

@ -2210,6 +2210,23 @@ public:
if (it != tx_key_imgs.end())
{
uint64_t xmr_amount = (*it).amount;
// RingCT, i.e., tx version is 2
// thus need to decode the amounts
// otherwise they all appear to be zero.
// so to find the amount, first we need to find
// our output in the key images's mixins, and then
if (tx.version == 2)
{
// bool r = decode_ringct(tx.rct_signatures,
// txd.pk,
// prv_view_key,
// i,
// tx.rct_signatures.ecdhInfo[i].mask,
// rct_amount);
}
key_img_info["amount"] = xmreg::xmr_amount_to_str(xmr_amount);
total_xmr += xmr_amount;
}

@ -9,15 +9,15 @@
namespace xmreg
{
/**
/**
* Parse key string, e.g., a viewkey in a string
* 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 @@ namespace xmreg
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);
// 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);
/**
/**
* 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 @@ namespace xmreg
}
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,65 +87,65 @@ namespace xmreg
}
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)
{
string path_str = in_path.native();
return bf::path(remove_trailing_path_separator(path_str));
}
}
string
timestamp_to_str(time_t timestamp, const char* format)
{
string
timestamp_to_str(time_t timestamp, const char* format)
{
auto a_time_point = chrono::system_clock::from_time_t(timestamp);
try
@ -163,12 +163,12 @@ namespace xmreg
return timestamp_to_str_local(timestamp, format);
}
}
}
string
timestamp_to_str_local(time_t timestamp, const char* format)
{
string
timestamp_to_str_local(time_t timestamp, const char* format)
{
const int TIME_LENGTH = 60;
@ -182,27 +182,27 @@ namespace xmreg
len = std::strftime(str_buff, TIME_LENGTH, format, tm_ptr);
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;
@ -241,12 +241,12 @@ namespace xmreg
}
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();
@ -258,19 +258,19 @@ namespace xmreg
// the default folder of the lmdb blockchain database
// is therefore as follows
return default_monero_dir + string("/lmdb");
}
}
/*
/*
* Ge blockchain exception from command line option
*
* 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);
@ -290,12 +290,12 @@ namespace xmreg
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)
@ -304,13 +304,13 @@ namespace xmreg
}
return sum_xmr;
}
}
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();
@ -331,25 +331,25 @@ namespace xmreg
}
return sum_xmr;
}
}
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)
@ -359,12 +359,12 @@ namespace xmreg
}
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)
@ -373,13 +373,13 @@ namespace xmreg
}
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)
@ -398,11 +398,11 @@ namespace xmreg
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)
@ -421,11 +421,11 @@ namespace xmreg
}
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();
@ -453,11 +453,11 @@ namespace xmreg
}
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)
@ -466,12 +466,12 @@ namespace xmreg
}
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();
@ -492,14 +492,14 @@ namespace xmreg
}
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;
@ -526,21 +526,21 @@ namespace xmreg
}
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;
@ -572,12 +572,12 @@ namespace xmreg
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;
@ -587,14 +587,14 @@ namespace xmreg
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();
@ -619,26 +619,26 @@ namespace xmreg
}
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)
{
// 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)
{
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)
{
{
crypto::key_derivation derivation;
bool r = crypto::generate_key_derivation(pub, sec, derivation);
@ -681,11 +681,11 @@ namespace xmreg
}
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)
@ -721,11 +721,11 @@ namespace xmreg
}
}
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;
@ -748,11 +748,11 @@ namespace xmreg
}
}
return body;
}
}
bool
get_dummy_account_keys(account_keys& dummy_keys, bool testnet)
{
bool
get_dummy_account_keys(account_keys& dummy_keys, bool testnet)
{
secret_key adress_prv_viewkey;
secret_key adress_prv_spendkey;
@ -784,16 +784,16 @@ namespace xmreg
};
return true;
}
}
// from wallet2::decrypt
string
decrypt(const std::string &ciphertext,
// from wallet2::decrypt
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);
@ -836,13 +836,13 @@ namespace xmreg
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)
{
// 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)
{
std::vector<tx_extra_field> tx_extra_fields;
if(!parse_tx_extra(tx.extra, tx_extra_fields))
@ -880,11 +880,11 @@ namespace xmreg
}
return null_pkey;
}
}
date::sys_seconds
parse(const std::string& str, string format)
{
date::sys_seconds
parse(const std::string& str, string format)
{
std::istringstream in(str);
date::sys_seconds tp;
in >> date::parse(format, tp);
@ -895,8 +895,58 @@ namespace xmreg
in >> date::parse(format, tp);
}
return tp;
}
/**
* 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,
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;
if (!generate_key_derivation(pub_tx_key, private_view_key, derivation))
{
cerr << "Cant get dervied key for: " << "\n"
<< "pub_tx_key: " << pub_tx_key << " and "
<< "prv_view_key" << private_view_key << endl;
return false;
}
// get the tx output public key
// that normally would be generated for us,
// if someone had sent us some xmr.
public_key pubkey;
derive_public_key(derivation,
output_index,
public_spend_key,
pubkey);
//cout << "\n" << tx.vout.size() << " " << output_index << endl;
// get tx output public key
const txout_to_key tx_out_to_key
= boost::get<txout_to_key>(tx.vout[output_index].target);
if (tx_out_to_key.key == pubkey)
{
return true;
}
return false;
}
}

@ -14,7 +14,6 @@
a_hash.substr(1, a_hash.size()-2)
#include "monero_headers.h"
#include "tx_details.h"
#include "../ext/infix_iterator.h"
#include "../ext/date/tz.h"
@ -249,6 +248,13 @@ 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);
}
#endif //XMREG01_TOOLS_H

@ -1,223 +0,0 @@
//
// Created by mwo on 14/11/15.
//
#include "tx_details.h"
namespace xmreg
{
crypto::hash
transfer_details::tx_hash() const
{
return get_transaction_hash(m_tx);
};
uint64_t
transfer_details::amount() const
{
return m_tx.vout[m_internal_output_index].amount;
}
ostream&
operator<<(ostream& os, const transfer_details& td)
{
os << "Block: " << td.m_block_height
<< " time: " << timestamp_to_str(td.m_block_timestamp)
<< " tx hash: " << td.tx_hash()
<< " out idx: " << td.m_internal_output_index
<< " amount: " << print_money(td.amount());
return os;
}
/**
* Get tx outputs associated with the given private view and public spend keys
*
*
*/
vector<xmreg::transfer_details>
get_belonging_outputs(const block& blk,
const transaction& tx,
const secret_key& private_view_key,
const public_key& public_spend_key,
uint64_t block_height)
{
// vector to be returned
vector<xmreg::transfer_details> our_outputs;
// get transaction's public key
public_key pub_tx_key = get_tx_pub_key_from_extra(tx);
// check if transaction has valid public key
// if no, then skip
if (pub_tx_key == null_pkey)
{
return our_outputs;
}
// get the total number of outputs in a transaction.
size_t output_no = tx.vout.size();
// check if the given transaction has any outputs
// if no, then finish
if (output_no == 0)
{
return our_outputs;
}
// public transaction key is combined with our viewkey
// to create, so called, derived key.
key_derivation derivation;
if (!generate_key_derivation(pub_tx_key, private_view_key, derivation))
{
cerr << "Cant get dervied key for: " << "\n"
<< "pub_tx_key: " << private_view_key << " and "
<< "prv_view_key" << private_view_key << endl;
return our_outputs;
}
// each tx that we (or the address we are checking) received
// contains a number of outputs.
// some of them are ours, some not. so we need to go through
// all of them in a given tx block, to check which outputs are ours.
// sum amount of xmr sent to us
// in the given transaction
uint64_t money_transfered {0};
// loop through outputs in the given tx
// to check which outputs our ours. we compare outputs'
// public keys with the public key that would had been
// generated for us if we had gotten the outputs.
// not sure this is the case though, but that's my understanding.
for (size_t i = 0; i < output_no; ++i)
{
// get the tx output public key
// that normally would be generated for us,
// if someone had sent us some xmr.
public_key pubkey;
derive_public_key(derivation,
i,
public_spend_key,
pubkey);
// get tx output public key
const txout_to_key tx_out_to_key
= boost::get<txout_to_key>(tx.vout[i].target);
//cout << "Output no: " << i << ", " << tx_out_to_key.key;
// check if the output's public key is ours
if (tx_out_to_key.key == pubkey)
{
// if so, then add this output to the
// returned vector
//our_outputs.push_back(tx.vout[i]);
our_outputs.push_back(
xmreg::transfer_details {block_height,
blk.timestamp,
tx, i, false}
);
}
}
return our_outputs;
}
/**
* 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,
const transaction& tx,
const secret_key& private_view_key,
const public_key& public_spend_key)
{
// get transaction's public key
public_key pub_tx_key = get_tx_pub_key_from_extra(tx);
// check if transaction has valid public key
// if no, then skip
if (pub_tx_key == null_pkey)
{
return false;
}
// public transaction key is combined with our viewkey
// to create, so called, derived key.
key_derivation derivation;
if (!generate_key_derivation(pub_tx_key, private_view_key, derivation))
{
cerr << "Cant get dervied key for: " << "\n"
<< "pub_tx_key: " << pub_tx_key << " and "
<< "prv_view_key" << private_view_key << endl;
return false;
}
// get the tx output public key
// that normally would be generated for us,
// if someone had sent us some xmr.
public_key pubkey;
derive_public_key(derivation,
output_index,
public_spend_key,
pubkey);
//cout << "\n" << tx.vout.size() << " " << output_index << endl;
// get tx output public key
const txout_to_key tx_out_to_key
= boost::get<txout_to_key>(tx.vout[output_index].target);
if (tx_out_to_key.key == pubkey)
{
return true;
}
return false;
}
}
template<>
csv::ofstream&
operator<<(csv::ofstream& ostm, const xmreg::transfer_details& td)
{
ostm << xmreg::timestamp_to_str(td.m_block_timestamp, "%F");
ostm << xmreg::timestamp_to_str(td.m_block_timestamp, "%T");
ostm << td.m_block_height;
ostm << td.tx_hash();
ostm << td.m_internal_output_index;
ostm << cryptonote::print_money(td.amount());
return ostm;
}

@ -1,64 +0,0 @@
//
// Created by mwo on 14/11/15.
//
#ifndef XMR2CSV_TXDATA_H
#define XMR2CSV_TXDATA_H
#include "../ext/minicsv.h"
#include "monero_headers.h"
#include "tools.h"
namespace xmreg
{
using namespace cryptonote;
using namespace crypto;
using namespace std;
struct transfer_details
{
uint64_t m_block_height;
uint64_t m_block_timestamp;
transaction m_tx;
size_t m_internal_output_index;
bool m_spent;
crypto::hash tx_hash() const;
uint64_t amount() const;
};
ostream&
operator<<(ostream& os, const transfer_details& dt);
vector<xmreg::transfer_details>
get_belonging_outputs(const block& blk,
const transaction& tx,
const secret_key& private_view_key,
const public_key& public_spend_key,
uint64_t block_height = 0);
bool
is_output_ours(const size_t& output_index,
const transaction& tx,
const secret_key& private_view_key,
const public_key& public_spend_key);
}
template<>
csv::ostringstream&
operator<<(csv::ostringstream& ostm, const xmreg::transfer_details& td);
#endif //XMR2CSV_TXDATA_H
Loading…
Cancel
Save