Browse Source

Lots of more data for z_getstats

pull/321/head
Duke 9 months ago
parent
commit
ff7a597032
  1. 31
      src/wallet/rpcwallet.cpp

31
src/wallet/rpcwallet.cpp

@ -3683,7 +3683,9 @@ UniValue z_getstats(const UniValue& params, bool fHelp, const CPubKey& mypk)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
int total_ztxs = 0, total_zins = 0, total_zouts = 0;
int total_ztxs_10_or_more_zins = 0, total_ztxs_10_or_more_zouts = 0;
int largest_zins = 0, largest_zouts = 0;
std::string largest_zins_txid = "", largest_zouts_txid = "";
// given a single block height, we calculate stats for that height
if (params.size() == 1) {
@ -3695,24 +3697,33 @@ UniValue z_getstats(const UniValue& params, bool fHelp, const CPubKey& mypk)
num_zouts = tx.vShieldedOutput.size();
num_zins = tx.vShieldedSpend.size();
// tx must have some zins and zouts to count towards our stats,
// which ignores shielding coinbase txs, which have only transparent inputs
// which ignores shielding coinbase txs, which have only transparent inputs.
// This mostly will only count "z2z" txs but also counts (z,t)=>z and z=>(z,t)
// which are possible but unlikely, since RPCs will not create them
// which are possible but unlikely, since RPCs cannot currently create (z,t)=>z txs
// and z=>(z,t) are disallowed when ac_private=1
if(num_zins > 0 && num_zouts > 0) {
total_ztxs++;
total_zins += num_zins;
total_zouts += num_zouts;
if (num_zins > largest_zins) {
largest_zins = num_zins;
largest_zins_txid = tx.GetHash().ToString();
}
if (num_zouts > largest_zouts) {
largest_zouts = num_zouts;
largest_zouts_txid = tx.GetHash().ToString();
}
if (num_zins >= 10) {
total_ztxs_10_or_more_zins++;
}
if (num_zouts >= 10) {
total_ztxs_10_or_more_zouts++;
}
}
}
}
} else {
// given two blocks, we calculate delta for that range
// given two blocks, we calculate stats for that range
std::string strHeight2 = params[1].get_str();
int nHeight2 = -1;
try {
@ -3729,7 +3740,7 @@ UniValue z_getstats(const UniValue& params, bool fHelp, const CPubKey& mypk)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height out of range");
}
// get the delta for every block in the range
// get the stats for every block in the range
for(int currentHeight = nHeight; currentHeight <= nHeight2; currentHeight++) {
auto strHash = chainActive[currentHeight]->GetBlockHash().GetHex();
uint256 hash(uint256S(strHash));
@ -3760,9 +3771,17 @@ UniValue z_getstats(const UniValue& params, bool fHelp, const CPubKey& mypk)
}
if (num_zins > largest_zins) {
largest_zins = num_zins;
largest_zins_txid = tx.GetHash().ToString();
}
if (num_zouts > largest_zouts) {
largest_zouts = num_zouts;
largest_zouts_txid = tx.GetHash().ToString();
}
if (num_zins >= 10) {
total_ztxs_10_or_more_zins++;
}
if (num_zouts >= 10) {
total_ztxs_10_or_more_zouts++;
}
}
}
@ -3774,10 +3793,14 @@ UniValue z_getstats(const UniValue& params, bool fHelp, const CPubKey& mypk)
ret.pushKV("total_ztxs", total_ztxs);
ret.pushKV("total_zins", total_zins);
ret.pushKV("total_zouts", total_zouts);
ret.pushKV("total_ztxs_10_or_more_zins", total_ztxs_10_or_more_zins);
ret.pushKV("total_ztxs_10_or_more_zouts", total_ztxs_10_or_more_zouts);
ret.pushKV("avg_zins", avg_zins);
ret.pushKV("avg_zouts", avg_zouts);
ret.pushKV("largest_zins", largest_zins);
ret.pushKV("largest_zins_txid", largest_zins_txid);
ret.pushKV("largest_zouts", largest_zouts);
ret.pushKV("largest_zouts_txid", largest_zouts_txid);
return ret;
}

Loading…
Cancel
Save