MCPcopy Create free account
hub / github.com/ElementsProject/elements / getblockstats

Function getblockstats

src/rpc/blockchain.cpp:2308–2564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2306static constexpr size_t PER_UTXO_OVERHEAD = sizeof(COutPoint) + sizeof(uint32_t) + sizeof(bool);
2307
2308static RPCHelpMan getblockstats()
2309{
2310 return RPCHelpMan{"getblockstats",
2311 "\nCompute per block statistics for a given window. All amounts are in satoshis.\n"
2312 "It won't work for some heights with pruning.\n",
2313 {
2314 {"hash_or_height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The block hash or height of the target block", "", {"", "string or numeric"}},
2315 {"stats", RPCArg::Type::ARR, RPCArg::DefaultHint{"all values"}, "Values to plot (see result below)",
2316 {
2317 {"height", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Selected statistic"},
2318 {"time", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Selected statistic"},
2319 },
2320 "stats"},
2321 },
2322 RPCResult{
2323 RPCResult::Type::OBJ, "", "",
2324 {
2325 {RPCResult::Type::NUM, "avgfee", /*optional=*/true, "Average fee in the block"},
2326 {RPCResult::Type::NUM, "avgfeerate", /*optional=*/true, "Average feerate (in satoshis per virtual byte)"},
2327 {RPCResult::Type::NUM, "avgtxsize", /*optional=*/true, "Average transaction size"},
2328 {RPCResult::Type::STR_HEX, "blockhash", /*optional=*/true, "The block hash (to check for potential reorgs)"},
2329 {RPCResult::Type::ARR_FIXED, "feerate_percentiles", /*optional=*/true, "Feerates at the 10th, 25th, 50th, 75th, and 90th percentile weight unit (in satoshis per virtual byte)",
2330 {
2331 {RPCResult::Type::NUM, "10th_percentile_feerate", "The 10th percentile feerate"},
2332 {RPCResult::Type::NUM, "25th_percentile_feerate", "The 25th percentile feerate"},
2333 {RPCResult::Type::NUM, "50th_percentile_feerate", "The 50th percentile feerate"},
2334 {RPCResult::Type::NUM, "75th_percentile_feerate", "The 75th percentile feerate"},
2335 {RPCResult::Type::NUM, "90th_percentile_feerate", "The 90th percentile feerate"},
2336 }},
2337 {RPCResult::Type::NUM, "height", /*optional=*/true, "The height of the block"},
2338 {RPCResult::Type::NUM, "ins", /*optional=*/true, "The number of inputs (excluding coinbase)"},
2339 {RPCResult::Type::NUM, "maxfee", /*optional=*/true, "Maximum fee in the block"},
2340 {RPCResult::Type::NUM, "maxfeerate", /*optional=*/true, "Maximum feerate (in satoshis per virtual byte)"},
2341 {RPCResult::Type::NUM, "maxtxsize", /*optional=*/true, "Maximum transaction size"},
2342 {RPCResult::Type::NUM, "medianfee", /*optional=*/true, "Truncated median fee in the block"},
2343 {RPCResult::Type::NUM, "mediantime", /*optional=*/true, "The block median time past"},
2344 {RPCResult::Type::NUM, "mediantxsize", /*optional=*/true, "Truncated median transaction size"},
2345 {RPCResult::Type::NUM, "minfee", /*optional=*/true, "Minimum fee in the block"},
2346 {RPCResult::Type::NUM, "minfeerate", /*optional=*/true, "Minimum feerate (in satoshis per virtual byte)"},
2347 {RPCResult::Type::NUM, "mintxsize", /*optional=*/true, "Minimum transaction size"},
2348 {RPCResult::Type::NUM, "outs", /*optional=*/true, "The number of outputs"},
2349 {RPCResult::Type::NUM, "subsidy", /*optional=*/true, "The block subsidy"},
2350 {RPCResult::Type::NUM, "swtotal_size", /*optional=*/true, "Total size of all segwit transactions"},
2351 {RPCResult::Type::NUM, "swtotal_weight", /*optional=*/true, "Total weight of all segwit transactions"},
2352 {RPCResult::Type::NUM, "swtxs", /*optional=*/true, "The number of segwit transactions"},
2353 {RPCResult::Type::NUM, "time", /*optional=*/true, "The block time"},
2354 {RPCResult::Type::NUM, "total_out", /*optional=*/true, "Total amount in all outputs (excluding coinbase and thus reward [ie subsidy + totalfee])"},
2355 {RPCResult::Type::NUM, "total_size", /*optional=*/true, "Total size of all non-coinbase transactions"},
2356 {RPCResult::Type::NUM, "total_weight", /*optional=*/true, "Total weight of all non-coinbase transactions"},
2357 {RPCResult::Type::NUM, "totalfee", /*optional=*/true, "The fee total"},
2358 {RPCResult::Type::NUM, "txs", /*optional=*/true, "The number of transactions (including coinbase)"},
2359 {RPCResult::Type::NUM, "utxo_increase", /*optional=*/true, "The increase/decrease in the number of unspent outputs"},
2360 {RPCResult::Type::NUM, "utxo_size_inc", /*optional=*/true, "The increase/decrease in size for the utxo index (not discounting op_return and similar)"},
2361 }},
2362 RPCExamples{
2363 HelpExampleCli("getblockstats", R"('"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"' '["minfeerate","avgfeerate"]')") +
2364 HelpExampleCli("getblockstats", R"(1000 '["minfeerate","avgfeerate"]')") +
2365 HelpExampleRpc("getblockstats", R"("00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09", ["minfeerate","avgfeerate"])") +

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
ParseHashOrHeightFunction · 0.85
SetHasKeysFunction · 0.85
GetSerializeSizeFunction · 0.85
GetTransactionWeightFunction · 0.85
CalculateTruncatedMedianFunction · 0.85
GetBlockSubsidyFunction · 0.85
JSONRPCErrorFunction · 0.85
countMethod · 0.80
IsFeeMethod · 0.80

Tested by

no test coverage detected