few tool functions added
This commit is contained in:
parent
9ea9dfdf7b
commit
69d6b27f31
122
src/tools.cpp
122
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<cryptonote::txin_to_key>(tx.vin[i]);
|
||||
|
||||
sum_xmr += tx_in_to_key.amount;
|
||||
}
|
||||
|
||||
return sum_xmr;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (txout.target.type() != typeid(txout_to_key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// get tx input key
|
||||
const txout_to_key& txout_key
|
||||
= boost::get<cryptonote::txout_to_key>(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<cryptonote::txin_to_key>(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<txin_to_key>
|
||||
get_key_images(const transaction& tx)
|
||||
{
|
||||
vector<txin_to_key> 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<cryptonote::txin_to_key>(tx.vin[i]);
|
||||
|
||||
key_images.push_back(tx_in_to_key);
|
||||
}
|
||||
|
||||
return key_images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rough estimate of block height from the time provided
|
||||
*
|
||||
|
|
15
src/tools.h
15
src/tools.h
|
@ -122,6 +122,21 @@ namespace xmreg
|
|||
get_blockchain_path(const boost::optional<string>& 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<pair<txout_to_key, uint64_t>>
|
||||
get_ouputs(const transaction& tx);
|
||||
|
||||
vector<txin_to_key>
|
||||
get_key_images(const transaction& tx);
|
||||
|
||||
|
||||
inline void
|
||||
enable_monero_log() {
|
||||
|
|
Loading…
Reference in New Issue