From 26b1f0ca330901403ee456953943be17e7731578 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Tue, 11 Jun 2019 17:33:01 +0200 Subject: [PATCH] [RPC] 'getblockindexstats': count public spends separately --- src/rpc/blockchain.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ed132131657fb..00cb745b9a335 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1486,6 +1486,11 @@ UniValue getblockindexstats(const UniValue& params, bool fHelp) { " \"denom_5\": xxxx (numeric) number of spends of denom_5 occurred over the block range\n" " ... ... number of spends of other denominations: ..., 10, 50, 100, 500, 1000, 5000\n" " }\n" + " \"pubspendcount\": { [if fFeeOnly=False]\n" + " \"denom_1\": xxxx (numeric) number of PUBLIC spends of denom_1 occurred over the block range\n" + " \"denom_5\": xxxx (numeric) number of PUBLIC spends of denom_5 occurred over the block range\n" + " ... ... number of PUBLIC spends of other denominations: ..., 10, 50, 100, 500, 1000, 5000\n" + " }\n" " \"txbytes\": xxxxx (numeric) Sum of the size of all txes (zPIV excluded) over block range\n" " \"ttlfee\": xxxxx (numeric) Sum of the fee amount of all txes (zPIV mints excluded) over block range\n" " \"ttlfee_all\": xxxxx (numeric) Sum of the fee amount of all txes (zPIV mints included) over block range\n" @@ -1518,9 +1523,11 @@ UniValue getblockindexstats(const UniValue& params, bool fHelp) { std::map mapMintCount; std::map mapSpendCount; + std::map mapPublicSpendCount; for (auto& denom : libzerocoin::zerocoinDenomList) { mapMintCount.insert(make_pair(denom, 0)); mapSpendCount.insert(make_pair(denom, 0)); + mapPublicSpendCount.insert(make_pair(denom, 0)); } CBlockIndex* pindex = chainActive[heightStart]; @@ -1541,14 +1548,19 @@ UniValue getblockindexstats(const UniValue& params, bool fHelp) { for (const CTransaction& tx : block.vtx) { if (tx.IsCoinBase() || (tx.IsCoinStake() && !tx.HasZerocoinSpendInputs())) continue; - - // fetch input value from prevouts and count spends + + // fetch input value from prevouts and count spends for (unsigned int j = 0; j < tx.vin.size(); j++) { - if (tx.vin[j].IsZerocoinSpend() || tx.vin[j].IsZerocoinPublicSpend()) { + if (tx.vin[j].IsZerocoinSpend()) { if (!fFeeOnly) mapSpendCount[libzerocoin::IntToZerocoinDenomination(tx.vin[j].nSequence)]++; continue; } + if (tx.vin[j].IsZerocoinPublicSpend()) { + if (!fFeeOnly) + mapPublicSpendCount[libzerocoin::IntToZerocoinDenomination(tx.vin[j].nSequence)]++; + continue; + } COutPoint prevout = tx.vin[j].prevout; CTransaction txPrev; @@ -1598,12 +1610,15 @@ UniValue getblockindexstats(const UniValue& params, bool fHelp) { if (!fFeeOnly) { UniValue mint_obj(UniValue::VOBJ); UniValue spend_obj(UniValue::VOBJ); + UniValue pubspend_obj(UniValue::VOBJ); for (auto& denom : libzerocoin::zerocoinDenomList) { mint_obj.push_back(Pair(strprintf("denom_%d", ZerocoinDenominationToInt(denom)), mapMintCount[denom])); spend_obj.push_back(Pair(strprintf("denom_%d", ZerocoinDenominationToInt(denom)), mapSpendCount[denom])); + pubspend_obj.push_back(Pair(strprintf("denom_%d", ZerocoinDenominationToInt(denom)), mapPublicSpendCount[denom])); } ret.push_back(Pair("mintcount", mint_obj)); ret.push_back(Pair("spendcount", spend_obj)); + ret.push_back(Pair("publicspendcount", pubspend_obj)); } ret.push_back(Pair("txbytes", (int64_t)nBytes));