mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #16695: rpc: Add window final block height to getchaintxstats
d48c1e837ae1bd08e0f18ad1b57ff72675c3d6ad Add window final block height to getchaintxstats (Jonathan "Duke" Leto) Pull request description: This patch is motivated by the desire to make the output of `getchaintxstats` more useful and optimized for applications to consume and render the data. Firstly, this data is already available to the RPC, no additional work is done. Currently additional RPC calls will be needed to look up the height of the final block in the window or the block height that began the window. By adding the block height of the final block in the window, the JSON is "self-contained" and applications can calculate the exact block height range of the window with no additional RPC requests. For example, a web application which wants to render historical information for `getchaintxstats` RPC on various window sizes might call the RPC with various window lengths, once per day, and store the JSON results somewhere. Because the final block height of each dataset is included, it's no extra work to determine the exact block window range of each JSON response. ACKs for top commit: promag: ACK d48c1e837ae1bd08e0f18ad1b57ff72675c3d6ad. Tree-SHA512: fd4952c125f81a4ad18f7c78498c6b3e265b93cb574832166ac25596321ce84957f971f3f78f37d7e42638dc65f2a5d4d760f289873c9c2f2a82eb00a0f87c3f
This commit is contained in:
parent
33aa4c2840
commit
12b5403aa6
5
doc/release-notes-16695.md
Normal file
5
doc/release-notes-16695.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Updated RPCs
|
||||||
|
------------
|
||||||
|
|
||||||
|
- The `getchaintxstats` RPC now returns the additional key of
|
||||||
|
`window_final_block_height`.
|
@ -1787,6 +1787,7 @@ static UniValue getchaintxstats(const JSONRPCRequest& request)
|
|||||||
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
|
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
|
||||||
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
|
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
|
||||||
" \"window_final_block_hash\": \"...\", (string) The hash of the final block in the window.\n"
|
" \"window_final_block_hash\": \"...\", (string) The hash of the final block in the window.\n"
|
||||||
|
" \"window_final_block_height\": xxxxx, (numeric) The height of the final block in the window.\n"
|
||||||
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
|
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
|
||||||
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
|
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
|
||||||
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
|
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
|
||||||
@ -1835,6 +1836,7 @@ static UniValue getchaintxstats(const JSONRPCRequest& request)
|
|||||||
ret.pushKV("time", (int64_t)pindex->nTime);
|
ret.pushKV("time", (int64_t)pindex->nTime);
|
||||||
ret.pushKV("txcount", (int64_t)pindex->nChainTx);
|
ret.pushKV("txcount", (int64_t)pindex->nChainTx);
|
||||||
ret.pushKV("window_final_block_hash", pindex->GetBlockHash().GetHex());
|
ret.pushKV("window_final_block_hash", pindex->GetBlockHash().GetHex());
|
||||||
|
ret.pushKV("window_final_block_height", pindex->nHeight);
|
||||||
ret.pushKV("window_block_count", blockcount);
|
ret.pushKV("window_block_count", blockcount);
|
||||||
if (blockcount > 0) {
|
if (blockcount > 0) {
|
||||||
ret.pushKV("window_tx_count", nTxDiff);
|
ret.pushKV("window_tx_count", nTxDiff);
|
||||||
|
@ -155,6 +155,7 @@ class BlockchainTest(BitcoinTestFramework):
|
|||||||
assert_equal(chaintxstats['time'], b200['time'])
|
assert_equal(chaintxstats['time'], b200['time'])
|
||||||
assert_equal(chaintxstats['txcount'], 201)
|
assert_equal(chaintxstats['txcount'], 201)
|
||||||
assert_equal(chaintxstats['window_final_block_hash'], b200_hash)
|
assert_equal(chaintxstats['window_final_block_hash'], b200_hash)
|
||||||
|
assert_equal(chaintxstats['window_final_block_height'], 200)
|
||||||
assert_equal(chaintxstats['window_block_count'], 199)
|
assert_equal(chaintxstats['window_block_count'], 199)
|
||||||
assert_equal(chaintxstats['window_tx_count'], 199)
|
assert_equal(chaintxstats['window_tx_count'], 199)
|
||||||
assert_equal(chaintxstats['window_interval'], time_diff)
|
assert_equal(chaintxstats['window_interval'], time_diff)
|
||||||
@ -164,6 +165,7 @@ class BlockchainTest(BitcoinTestFramework):
|
|||||||
assert_equal(chaintxstats['time'], b1['time'])
|
assert_equal(chaintxstats['time'], b1['time'])
|
||||||
assert_equal(chaintxstats['txcount'], 2)
|
assert_equal(chaintxstats['txcount'], 2)
|
||||||
assert_equal(chaintxstats['window_final_block_hash'], b1_hash)
|
assert_equal(chaintxstats['window_final_block_hash'], b1_hash)
|
||||||
|
assert_equal(chaintxstats['window_final_block_height'], 1)
|
||||||
assert_equal(chaintxstats['window_block_count'], 0)
|
assert_equal(chaintxstats['window_block_count'], 0)
|
||||||
assert('window_tx_count' not in chaintxstats)
|
assert('window_tx_count' not in chaintxstats)
|
||||||
assert('window_interval' not in chaintxstats)
|
assert('window_interval' not in chaintxstats)
|
||||||
|
Loading…
Reference in New Issue
Block a user