mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-27 09:21:43 +02:00
rpc: Add hash_type NONE to gettxoutsetinfo
This commit is contained in:
parent
a712cf6f68
commit
f17a4d1c4d
@ -41,6 +41,17 @@ static void ApplyStats(CCoinsStats& stats, CHashWriter& ss, const uint256& hash,
|
|||||||
ss << VARINT(0u);
|
ss << VARINT(0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ApplyStats(CCoinsStats& stats, std::nullptr_t, const uint256& hash, const std::map<uint32_t, Coin>& outputs)
|
||||||
|
{
|
||||||
|
assert(!outputs.empty());
|
||||||
|
stats.nTransactions++;
|
||||||
|
for (const auto& output : outputs) {
|
||||||
|
stats.nTransactionOutputs++;
|
||||||
|
stats.nTotalAmount += output.second.out.nValue;
|
||||||
|
stats.nBogoSize += GetBogoSize(output.second.out.scriptPubKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//! Calculate statistics about the unspent transaction output set
|
//! Calculate statistics about the unspent transaction output set
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point)
|
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
|
|||||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
||||||
return GetUTXOStats(view, stats, ss, interruption_point);
|
return GetUTXOStats(view, stats, ss, interruption_point);
|
||||||
}
|
}
|
||||||
|
case(CoinStatsHashType::NONE): {
|
||||||
|
return GetUTXOStats(view, stats, nullptr, interruption_point);
|
||||||
|
}
|
||||||
} // no default case, so the compiler can warn about missing cases
|
} // no default case, so the compiler can warn about missing cases
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
@ -102,8 +116,10 @@ static void PrepareHash(CHashWriter& ss, CCoinsStats& stats)
|
|||||||
{
|
{
|
||||||
ss << stats.hashBlock;
|
ss << stats.hashBlock;
|
||||||
}
|
}
|
||||||
|
static void PrepareHash(std::nullptr_t, CCoinsStats& stats) {}
|
||||||
|
|
||||||
static void FinalizeHash(CHashWriter& ss, CCoinsStats& stats)
|
static void FinalizeHash(CHashWriter& ss, CCoinsStats& stats)
|
||||||
{
|
{
|
||||||
stats.hashSerialized = ss.GetHash();
|
stats.hashSerialized = ss.GetHash();
|
||||||
}
|
}
|
||||||
|
static void FinalizeHash(std::nullptr_t, CCoinsStats& stats) {}
|
||||||
|
@ -16,6 +16,7 @@ class CCoinsView;
|
|||||||
|
|
||||||
enum class CoinStatsHashType {
|
enum class CoinStatsHashType {
|
||||||
HASH_SERIALIZED,
|
HASH_SERIALIZED,
|
||||||
|
NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CCoinsStats
|
struct CCoinsStats
|
||||||
|
@ -973,7 +973,7 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
|
|||||||
"\nReturns statistics about the unspent transaction output set.\n"
|
"\nReturns statistics about the unspent transaction output set.\n"
|
||||||
"Note this call may take some time.\n",
|
"Note this call may take some time.\n",
|
||||||
{
|
{
|
||||||
{"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm)."},
|
{"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'none'."},
|
||||||
},
|
},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
RPCResult::Type::OBJ, "", "",
|
RPCResult::Type::OBJ, "", "",
|
||||||
@ -2322,7 +2322,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
::ChainstateActive().ForceFlushStateToDisk();
|
::ChainstateActive().ForceFlushStateToDisk();
|
||||||
|
|
||||||
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::HASH_SERIALIZED, RpcInterruptionPoint)) {
|
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::NONE, RpcInterruptionPoint)) {
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +122,8 @@ CoinStatsHashType ParseHashType(const UniValue& param, const CoinStatsHashType d
|
|||||||
|
|
||||||
if (hash_type_input == "hash_serialized_2") {
|
if (hash_type_input == "hash_serialized_2") {
|
||||||
return CoinStatsHashType::HASH_SERIALIZED;
|
return CoinStatsHashType::HASH_SERIALIZED;
|
||||||
|
} else if (hash_type_input == "none") {
|
||||||
|
return CoinStatsHashType::NONE;
|
||||||
} else {
|
} else {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%d is not a valid hash_type", hash_type_input));
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%d is not a valid hash_type", hash_type_input));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user