@ -1047,13 +1047,26 @@ static RPCHelpMan pruneblockchain()
} ;
}
CoinStatsHashType ParseHashType ( const std : : string & hash_type_input )
{
if ( hash_type_input = = " hash_serialized_2 " ) {
return CoinStatsHashType : : HASH_SERIALIZED ;
} else if ( hash_type_input = = " muhash " ) {
return CoinStatsHashType : : MUHASH ;
} else if ( hash_type_input = = " none " ) {
return CoinStatsHashType : : NONE ;
} else {
throw JSONRPCError ( RPC_INVALID_PARAMETER , strprintf ( " %s is not a valid hash_type " , hash_type_input ) ) ;
}
}
static RPCHelpMan gettxoutsetinfo ( )
{
return RPCHelpMan { " gettxoutsetinfo " ,
" \n Returns statistics about the unspent transaction output set. \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), 'none'. " } ,
{ " hash_type " , RPCArg : : Type : : STR , /* default */ " hash_serialized_2 " , " Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), ' muhash', ' none'." } ,
} ,
RPCResult {
RPCResult : : Type : : OBJ , " " , " " ,
@ -1063,7 +1076,8 @@ static RPCHelpMan gettxoutsetinfo()
{ RPCResult : : Type : : NUM , " transactions " , " The number of transactions with unspent outputs " } ,
{ RPCResult : : Type : : NUM , " txouts " , " The number of unspent transaction outputs " } ,
{ RPCResult : : Type : : NUM , " bogosize " , " A meaningless metric for UTXO set size " } ,
{ RPCResult : : Type : : STR_HEX , " hash_serialized_2 " , " The serialized hash (only present if 'hash_serialized_2' hash_type is chosen) " } ,
{ RPCResult : : Type : : STR_HEX , " hash_serialized_2 " , /* optional */ true , " The serialized hash (only present if 'hash_serialized_2' hash_type is chosen) " } ,
{ RPCResult : : Type : : STR_HEX , " muhash " , /* optional */ true , " The serialized hash (only present if 'muhash' hash_type is chosen) " } ,
{ RPCResult : : Type : : NUM , " disk_size " , " The estimated size of the chainstate on disk " } ,
{ RPCResult : : Type : : STR_AMOUNT , " total_amount " , " The total amount " } ,
} } ,
@ -1078,7 +1092,7 @@ static RPCHelpMan gettxoutsetinfo()
CCoinsStats stats ;
: : ChainstateActive ( ) . ForceFlushStateToDisk ( ) ;
const CoinStatsHashType hash_type = ParseHashType ( request . params [ 0 ] , CoinStatsHashType : : HASH_SERIALIZED ) ;
const CoinStatsHashType hash_type { request . params [ 0 ] . isNull ( ) ? CoinStatsHashType : : HASH_SERIALIZED : ParseHashType ( request . params [ 0 ] . get_str ( ) ) } ;
CCoinsView * coins_view = WITH_LOCK ( cs_main , return & ChainstateActive ( ) . CoinsDB ( ) ) ;
NodeContext & node = EnsureNodeContext ( request . context ) ;
@ -1091,6 +1105,9 @@ static RPCHelpMan gettxoutsetinfo()
if ( hash_type = = CoinStatsHashType : : HASH_SERIALIZED ) {
ret . pushKV ( " hash_serialized_2 " , stats . hashSerialized . GetHex ( ) ) ;
}
if ( hash_type = = CoinStatsHashType : : MUHASH ) {
ret . pushKV ( " muhash " , stats . hashSerialized . GetHex ( ) ) ;
}
ret . pushKV ( " disk_size " , stats . nDiskSize ) ;
ret . pushKV ( " total_amount " , ValueFromAmount ( stats . nTotalAmount ) ) ;
} else {