diff --git a/src/tools.cpp b/src/tools.cpp index a0a72e8..c226486 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -267,6 +267,128 @@ namespace xmreg } + uint64_t + sum_money_in_outputs(const transaction& tx) + { + uint64_t sum_xmr {0}; + + for (const tx_out& txout: tx.vout) + { + sum_xmr += txout.amount; + } + + return sum_xmr; + } + + + + uint64_t + sum_money_in_inputs(const transaction& tx) + { + uint64_t sum_xmr {0}; + + size_t input_no = tx.vin.size(); + + for (size_t i = 0; i < input_no; ++i) + { + + if(tx.vin[i].type() != typeid(cryptonote::txin_to_key)) + { + continue; + } + + // get tx input key + const cryptonote::txin_to_key& tx_in_to_key + = boost::get(tx.vin[i]); + + sum_xmr += tx_in_to_key.amount; + } + + return sum_xmr; + } + + vector> + get_ouputs(const transaction& tx) + { + vector> outputs; + + for (const tx_out& txout: tx.vout) + { + if (txout.target.type() != typeid(txout_to_key)) + { + continue; + } + + // get tx input key + const txout_to_key& txout_key + = boost::get(txout.target); + + outputs.push_back(make_pair(txout_key, txout.amount)); + } + + return outputs; + + + }; + + uint64_t + get_mixin_no(const transaction& tx) + { + uint64_t mixin_no {0}; + + size_t input_no = tx.vin.size(); + + for (size_t i = 0; i < input_no; ++i) + { + + if(tx.vin[i].type() != typeid(cryptonote::txin_to_key)) + { + continue; + } + + // get tx input key + const txin_to_key& tx_in_to_key + = boost::get(tx.vin[i]); + + mixin_no = tx_in_to_key.key_offsets.size(); + + // look for first mixin number. + // all inputs in a single transaction have same number + if (mixin_no > 0) + { + break; + } + } + + return mixin_no; + } + + + vector + get_key_images(const transaction& tx) + { + vector key_images; + + size_t input_no = tx.vin.size(); + + for (size_t i = 0; i < input_no; ++i) + { + + if(tx.vin[i].type() != typeid(txin_to_key)) + { + continue; + } + + // get tx input key + const txin_to_key& tx_in_to_key + = boost::get(tx.vin[i]); + + key_images.push_back(tx_in_to_key); + } + + return key_images; + } + /** * Rough estimate of block height from the time provided * diff --git a/src/tools.h b/src/tools.h index fdbf01c..f59a3fe 100644 --- a/src/tools.h +++ b/src/tools.h @@ -122,6 +122,21 @@ namespace xmreg get_blockchain_path(const boost::optional& bc_path, bf::path& blockchain_path); + uint64_t + sum_money_in_outputs(const transaction& tx); + + uint64_t + sum_money_in_inputs(const transaction& tx); + + uint64_t + get_mixin_no(const transaction& tx); + + vector> + get_ouputs(const transaction& tx); + + vector + get_key_images(const transaction& tx); + inline void enable_monero_log() {