Skip to content

Commit f17a4d1

Browse files
committed
rpc: Add hash_type NONE to gettxoutsetinfo
1 parent a712cf6 commit f17a4d1

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/node/coinstats.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ static void ApplyStats(CCoinsStats& stats, CHashWriter& ss, const uint256& hash,
4141
ss << VARINT(0u);
4242
}
4343

44+
static void ApplyStats(CCoinsStats& stats, std::nullptr_t, const uint256& hash, const std::map<uint32_t, Coin>& outputs)
45+
{
46+
assert(!outputs.empty());
47+
stats.nTransactions++;
48+
for (const auto& output : outputs) {
49+
stats.nTransactionOutputs++;
50+
stats.nTotalAmount += output.second.out.nValue;
51+
stats.nBogoSize += GetBogoSize(output.second.out.scriptPubKey);
52+
}
53+
}
54+
4455
//! Calculate statistics about the unspent transaction output set
4556
template <typename T>
4657
static bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point)
@@ -93,6 +104,9 @@ bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, CoinStatsHashType hash_t
93104
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
94105
return GetUTXOStats(view, stats, ss, interruption_point);
95106
}
107+
case(CoinStatsHashType::NONE): {
108+
return GetUTXOStats(view, stats, nullptr, interruption_point);
109+
}
96110
} // no default case, so the compiler can warn about missing cases
97111
assert(false);
98112
}
@@ -102,8 +116,10 @@ static void PrepareHash(CHashWriter& ss, CCoinsStats& stats)
102116
{
103117
ss << stats.hashBlock;
104118
}
119+
static void PrepareHash(std::nullptr_t, CCoinsStats& stats) {}
105120

106121
static void FinalizeHash(CHashWriter& ss, CCoinsStats& stats)
107122
{
108123
stats.hashSerialized = ss.GetHash();
109124
}
125+
static void FinalizeHash(std::nullptr_t, CCoinsStats& stats) {}

src/node/coinstats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CCoinsView;
1616

1717
enum class CoinStatsHashType {
1818
HASH_SERIALIZED,
19+
NONE,
1920
};
2021

2122
struct CCoinsStats

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
973973
"\nReturns statistics about the unspent transaction output set.\n"
974974
"Note this call may take some time.\n",
975975
{
976-
{"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm)."},
976+
{"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'none'."},
977977
},
978978
RPCResult{
979979
RPCResult::Type::OBJ, "", "",
@@ -2322,7 +2322,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23222322

23232323
::ChainstateActive().ForceFlushStateToDisk();
23242324

2325-
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::HASH_SERIALIZED, RpcInterruptionPoint)) {
2325+
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::NONE, RpcInterruptionPoint)) {
23262326
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
23272327
}
23282328

src/rpc/util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ CoinStatsHashType ParseHashType(const UniValue& param, const CoinStatsHashType d
122122

123123
if (hash_type_input == "hash_serialized_2") {
124124
return CoinStatsHashType::HASH_SERIALIZED;
125+
} else if (hash_type_input == "none") {
126+
return CoinStatsHashType::NONE;
125127
} else {
126128
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%d is not a valid hash_type", hash_type_input));
127129
}

0 commit comments

Comments
 (0)