fix: no more parsing json of each tx in mempool 5 times!

master
moneroexamples 8 years ago
parent d22cb6a827
commit 89ec634422

@ -557,30 +557,35 @@ public:
delta_time[3], delta_time[4]); delta_time[3], delta_time[4]);
} }
//cout << _tx_info.tx_json << endl;
// sum xmr in inputs and ouputs in the given tx // sum xmr in inputs and ouputs in the given tx
pair<uint64_t, uint64_t> sum_inputs = xmreg::sum_money_in_inputs(_tx_info.tx_json); pair<uint64_t, uint64_t> sum_inputs;
pair<uint64_t, uint64_t> sum_outputs = xmreg::sum_money_in_outputs(_tx_info.tx_json); pair<uint64_t, uint64_t> sum_outputs;
uint64_t num_nonrct_inputs = xmreg::count_nonrct_inputs(_tx_info.tx_json); uint64_t num_nonrct_inputs;
// get mixin number in each transaction // get mixin number in each transaction
vector<uint64_t> mixin_numbers = xmreg::get_mixin_no(_tx_info.tx_json); vector<uint64_t> mixin_numbers;
uint64_t mixin_no = 0;
if (!mixin_numbers.empty())
mixin_no = mixin_numbers.at(0) - 1;
json j_tx; uint64_t mixin_no {0};
string is_ringct_str {"N/A"}; string is_ringct_str {"N/A"};
string rct_type_str {"N/A"}; string rct_type_str {"N/A"};
try try
{ {
json j_tx;
j_tx = json::parse(_tx_info.tx_json); j_tx = json::parse(_tx_info.tx_json);
// sum xmr in inputs and ouputs in the given tx
sum_inputs = xmreg::sum_money_in_inputs(j_tx);
sum_outputs = xmreg::sum_money_in_outputs(j_tx);
num_nonrct_inputs = xmreg::count_nonrct_inputs(j_tx);
mixin_numbers = xmreg::get_mixin_no(j_tx);
if (!mixin_numbers.empty())
mixin_no = mixin_numbers.at(0) - 1;
if (j_tx["version"].get<size_t>() > 1) if (j_tx["version"].get<size_t>() > 1)
{ {
is_ringct_str = "yes"; is_ringct_str = "yes";

@ -343,7 +343,19 @@ sum_money_in_outputs(const string& json_str)
return sum_xmr; return sum_xmr;
}; };
pair<uint64_t, uint64_t>
sum_money_in_outputs(const json& _json)
{
pair<uint64_t, uint64_t> sum_xmr {0ULL, 0ULL};
for (const json& vout: _json["vout"])
{
sum_xmr.first += vout["amount"].get<uint64_t>();
++sum_xmr.second;
}
return sum_xmr;
};
uint64_t uint64_t
sum_money_in_inputs(const transaction& tx) sum_money_in_inputs(const transaction& tx)
@ -395,6 +407,21 @@ sum_money_in_inputs(const string& json_str)
return sum_xmr; return sum_xmr;
}; };
pair<uint64_t, uint64_t>
sum_money_in_inputs(const json& _json)
{
pair<uint64_t, uint64_t> sum_xmr {0, 0};
for (const json& vin: _json["vin"])
{
sum_xmr.first += vin["key"]["amount"].get<uint64_t>();
++sum_xmr.second;
}
return sum_xmr;
};
uint64_t uint64_t
count_nonrct_inputs(const transaction& tx) count_nonrct_inputs(const transaction& tx)
{ {
@ -447,6 +474,22 @@ count_nonrct_inputs(const string& json_str)
return num; return num;
}; };
uint64_t
count_nonrct_inputs(const json& _json)
{
uint64_t num {0};
for (const json& vin: _json["vin"])
{
uint64_t amount = vin["key"]["amount"].get<uint64_t>();
if (amount != 0)
++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)
{ {
@ -590,6 +633,16 @@ get_mixin_no(const string& json_str)
return mixin_no; return mixin_no;
} }
vector<uint64_t>
get_mixin_no(const json& _json)
{
vector<uint64_t> mixin_no;
mixin_no.push_back(_json["vin"].at(0)["key"]["key_offsets"].size());
return mixin_no;
}
vector<uint64_t> vector<uint64_t>

@ -133,18 +133,27 @@ sum_money_in_outputs(const transaction& tx);
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_money_in_outputs(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>
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
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);
@ -160,6 +169,9 @@ 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>
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);

Loading…
Cancel
Save