This PR adds a new optional index (ScriptTypeIndex) that traks statistics about script types for each block. The index maintains both the count and total value (in satoshis) of outputs for each script type per block.
Tracking script type statistics enables analysis of Bitcoin’s UTXO set composition over time, (for example we can see addoption trends for: P2PKH, P2SH, SegWit, Taproot) and value distribution across script types.
Implementation
- New
ScriptTypeIndexclass extendingBaseIndex - Tracks all standard script types: NONSTANDARD, P2PK, P2PKH, P2SH, MULTISIG, NULL_DATA, P2WPKH, P2WSH, P2TR
- For each script type, tracks both output count and total sats locked
- Disabled by default, enabled with
-scripttypeindexflag
RPC Interface
Adds new RPC method getscripttypestats <blockhash> that returns nested objects with count and value for each script type:
0{
1 "nonstandard": {"count": 0, "value": 0},
2 "p2pk": {"count": 1, "value": 5000000000},
3 "p2pkh": {"count": 5, "value": 25000000000},
4 ...
5}
Testing
Unit tests included in src/test/scripttypeindex_tests.cpp:
- Basic initial sync test
- Test with multiple script types (P2PKH, P2SH, MULTISIG, NULL_DATA, P2WPKH, P2WSH, P2TR)