@@ -1755,6 +1755,13 @@ static UniValue getblockstats(const JSONRPCRequest& request)
17551755 " \" dust_bins\" : xxxxx, (numeric_array) The total number of outputs that are dust at several fee-rates\n "
17561756 " \" mto_consolidations\" : xxxxx, (numeric) The total number of transactions with at least 3 inputs and exactly 1 output\n "
17571757 " \" mto_output_count\" : xxxxx, (numeric) The total number of outputs spent in all mto_consolidation transactions\n "
1758+ " \" mto_total_value\" : xxxxx, (numeric) The sum of values of all outputs from mto_consolidation transactions\n "
1759+ " \" value_of_nested_p2wpkh_outputs_spent\" : xxxxx, (numeric) The total value of spent nested P2WPKH outputs\n "
1760+ " \" value_of_nested_p2wsh_outputs_spent\" : xxxxx, (numeric) The total value of spent nested P2WSH outputs\n "
1761+ " \" value_of_native_p2wpkh_outputs_spent\" : xxxxx, (numeric) The total value of spent native P2WPKH outputs\n "
1762+ " \" value_of_native_p2wsh_outputs_spent\" : xxxxx, (numeric) The total value of spent native P2WSH outputs\n "
1763+ " \" value_of_native_p2wpkh_outputs_created\" : xxxxx, (numeric) The total value of new native P2WPKH outputs\n "
1764+ " \" value_of_native_p2wsh_outputs_created\" : xxxxx, (numeric) The total value of new native P2WSH outputs\n "
17581765 " }\n "
17591766 " \n Examples:\n "
17601767 + HelpExampleCli (" getblockstats" , " 1000 '[\" minfeerate\" ,\" avgfeerate\" ]'" )
@@ -1800,7 +1807,6 @@ static UniValue getblockstats(const JSONRPCRequest& request)
18001807 }
18011808
18021809 const CBlock block = GetBlockChecked (pindex);
1803-
18041810 const bool do_all = stats.size () == 0 ; // Calculate everything if nothing selected (default)
18051811 const bool do_mediantxsize = do_all || stats.count (" mediantxsize" ) != 0 ;
18061812 const bool do_medianfee = do_all || stats.count (" medianfee" ) != 0 ;
@@ -1836,6 +1842,12 @@ static UniValue getblockstats(const JSONRPCRequest& request)
18361842 int64_t native_p2wsh_outputs_spent = 0 ;
18371843 int64_t nested_p2wpkh_outputs_spent = 0 ;
18381844 int64_t nested_p2wsh_outputs_spent = 0 ;
1845+ int64_t value_of_native_p2wpkh_outputs_created = 0 ;
1846+ int64_t value_of_native_p2wsh_outputs_created = 0 ;
1847+ int64_t value_of_native_p2wpkh_outputs_spent = 0 ;
1848+ int64_t value_of_native_p2wsh_outputs_spent = 0 ;
1849+ int64_t value_of_nested_p2wpkh_outputs_spent = 0 ;
1850+ int64_t value_of_nested_p2wsh_outputs_spent = 0 ;
18391851 int64_t txs_spending_nested_p2wpkh_outputs = 0 ;
18401852 int64_t txs_spending_nested_p2wsh_outputs = 0 ;
18411853 int64_t txs_spending_native_p2wpkh_outputs = 0 ;
@@ -1853,6 +1865,7 @@ static UniValue getblockstats(const JSONRPCRequest& request)
18531865 std::vector<int64_t > cons_in_count;
18541866 int64_t many_to_one_consolidating_txs = 0 ;
18551867 int64_t many_to_one_consolidated_outputs = 0 ;
1868+ CAmount many_to_one_total_value = 0 ;
18561869
18571870 // Batch ranges = [(1), (2), (3-4), (5-9), (10-49), (50-99), (100+)]
18581871 constexpr int NUM_OUTCOUNT_BINS = 7 ;
@@ -1895,9 +1908,11 @@ static UniValue getblockstats(const JSONRPCRequest& request)
18951908 if (scriptPubKey.IsPayToWitnessScriptHash ()) {
18961909 ++new_p2wsh_outputs;
18971910 creates_p2wsh_output = true ;
1911+ value_of_native_p2wsh_outputs_created += out.nValue ;
18981912 } else if (scriptPubKey.IsNativePayToWitnessPubKeyHash ()) {
18991913 ++new_p2wpkh_outputs;
19001914 creates_p2wpkh_output = true ;
1915+ value_of_native_p2wpkh_outputs_created += out.nValue ;
19011916 }
19021917
19031918 tx_total_out += out.nValue ;
@@ -1933,10 +1948,12 @@ static UniValue getblockstats(const JSONRPCRequest& request)
19331948 outputs_consolidated += tx->vin .size ();
19341949 }
19351950
1951+ bool tx_is_many_to_one = false ;
19361952 // Look for transactions with high number of inputs and low outputs
19371953 if ((tx->vin .size () >= CONSOLIDATION_THRESHOLD) && tx->vout .size () == 1 ) {
19381954 ++many_to_one_consolidating_txs;
19391955 many_to_one_consolidated_outputs += tx->vin .size ();
1956+ tx_is_many_to_one = true ;
19401957 }
19411958
19421959 int64_t tx_size = 0 ;
@@ -1993,15 +2010,19 @@ static UniValue getblockstats(const JSONRPCRequest& request)
19932010 if (in.SpendsNestedPayToWitnessPubKeyHashOutput (scriptPubKey)) {
19942011 spends_nested_p2wpkh_output = true ;
19952012 ++nested_p2wpkh_outputs_spent;
2013+ value_of_nested_p2wpkh_outputs_spent += prevoutput.nValue ;
19962014 } else if (in.SpendsNestedPayToWitnessScriptHashOutput (scriptPubKey)) {
19972015 spends_nested_p2wsh_output = true ;
19982016 ++nested_p2wsh_outputs_spent;
2017+ value_of_nested_p2wsh_outputs_spent += prevoutput.nValue ;
19992018 } else if (in.SpendsNativePayToWitnessPubKeyHashOutput (scriptPubKey)) {
20002019 spends_native_p2wpkh_output = true ;
20012020 ++native_p2wpkh_outputs_spent;
2021+ value_of_native_p2wpkh_outputs_spent += prevoutput.nValue ;
20022022 } else if (in.SpendsNativePayToWitnessScriptHashOutput (scriptPubKey)) {
20032023 spends_native_p2wsh_output = true ;
20042024 ++native_p2wsh_outputs_spent;
2025+ value_of_native_p2wsh_outputs_spent += prevoutput.nValue ;
20052026 }
20062027
20072028 tx_total_in += prevoutput.nValue ;
@@ -2046,6 +2067,10 @@ static UniValue getblockstats(const JSONRPCRequest& request)
20462067 }
20472068 maxfeerate = std::max (maxfeerate, feerate);
20482069 minfeerate = std::min (minfeerate, feerate);
2070+
2071+ if (tx_is_many_to_one) {
2072+ many_to_one_total_value += tx_total_out;
2073+ }
20492074 }
20502075 }
20512076
@@ -2123,6 +2148,14 @@ static UniValue getblockstats(const JSONRPCRequest& request)
21232148
21242149 ret_all.pushKV (" mto_consolidations" , many_to_one_consolidating_txs);
21252150 ret_all.pushKV (" mto_output_count" , many_to_one_consolidated_outputs);
2151+ ret_all.pushKV (" mto_total_value" , many_to_one_total_value);
2152+
2153+ ret_all.pushKV (" value_of_nested_p2wpkh_outputs_spent" , value_of_nested_p2wpkh_outputs_spent);
2154+ ret_all.pushKV (" value_of_nested_p2wsh_outputs_spent" , value_of_nested_p2wsh_outputs_spent);
2155+ ret_all.pushKV (" value_of_native_p2wpkh_outputs_spent" , value_of_native_p2wpkh_outputs_spent);
2156+ ret_all.pushKV (" value_of_native_p2wsh_outputs_spent" , value_of_native_p2wsh_outputs_spent);
2157+ ret_all.pushKV (" value_of_native_p2wpkh_outputs_created" , value_of_native_p2wpkh_outputs_created);
2158+ ret_all.pushKV (" value_of_native_p2wsh_outputs_created" , value_of_native_p2wsh_outputs_created);
21262159
21272160 if (do_all) {
21282161 return ret_all;
0 commit comments