mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
expose CBlockIndex::nTx in getblock(header)
This commit is contained in:
parent
9644d663f6
commit
7bfb1001df
2 changed files with 11 additions and 4 deletions
|
|
@ -269,10 +269,17 @@ class PruneTest(BitcoinTestFramework):
|
||||||
# should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000)
|
# should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000)
|
||||||
assert_raises_message(JSONRPCException, "Blockchain is too short for pruning", node.pruneblockchain, height(500))
|
assert_raises_message(JSONRPCException, "Blockchain is too short for pruning", node.pruneblockchain, height(500))
|
||||||
|
|
||||||
|
# Save block transaction count before pruning, assert value
|
||||||
|
block1_details = node.getblock(node.getblockhash(1))
|
||||||
|
assert_equal(block1_details["nTx"], len(block1_details["tx"]))
|
||||||
|
|
||||||
# mine 6 blocks so we are at height 1001 (i.e., above PruneAfterHeight)
|
# mine 6 blocks so we are at height 1001 (i.e., above PruneAfterHeight)
|
||||||
node.generate(6)
|
node.generate(6)
|
||||||
assert_equal(node.getblockchaininfo()["blocks"], 1001)
|
assert_equal(node.getblockchaininfo()["blocks"], 1001)
|
||||||
|
|
||||||
|
# Pruned block should still know the number of transactions
|
||||||
|
assert_equal(node.getblockheader(node.getblockhash(1))["nTx"], block1_details["nTx"])
|
||||||
|
|
||||||
# negative heights should raise an exception
|
# negative heights should raise an exception
|
||||||
assert_raises_message(JSONRPCException, "Negative", node.pruneblockchain, -10)
|
assert_raises_message(JSONRPCException, "Negative", node.pruneblockchain, -10)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
|
||||||
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
|
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
|
||||||
result.push_back(Pair("time", (int64_t)blockindex->nTime));
|
result.push_back(Pair("time", (int64_t)blockindex->nTime));
|
||||||
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
|
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
|
||||||
|
result.push_back(Pair("nTx", (uint64_t)blockindex->nTx));
|
||||||
result.push_back(Pair("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution)));
|
result.push_back(Pair("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution)));
|
||||||
result.push_back(Pair("signblock_witness_hex", HexStr(blockindex->proof.solution)));
|
result.push_back(Pair("signblock_witness_hex", HexStr(blockindex->proof.solution)));
|
||||||
|
|
||||||
|
|
@ -104,6 +105,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
|
||||||
result.push_back(Pair("tx", txs));
|
result.push_back(Pair("tx", txs));
|
||||||
result.push_back(Pair("time", block.GetBlockTime()));
|
result.push_back(Pair("time", block.GetBlockTime()));
|
||||||
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
|
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
|
||||||
|
result.push_back(Pair("nTx", (int64_t)blockindex->nTx));
|
||||||
result.push_back(Pair("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution)));
|
result.push_back(Pair("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution)));
|
||||||
result.push_back(Pair("signblock_witness_hex", HexStr(blockindex->proof.solution)));
|
result.push_back(Pair("signblock_witness_hex", HexStr(blockindex->proof.solution)));
|
||||||
|
|
||||||
|
|
@ -605,8 +607,7 @@ UniValue getblockheader(const JSONRPCRequest& request)
|
||||||
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
|
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
|
||||||
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||||
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||||
" \"signblock_witness_asm\":\"asm\", (string) scriptSig for block signing (asm)'\n"
|
" \"nTx\" : n, (numeric) The number of transactions in the block.\n"
|
||||||
" \"signblock_witness_hex\":\"hex\", (string) scriptSig for block signing (hex)'\n"
|
|
||||||
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
|
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
|
||||||
" \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
|
" \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
@ -691,8 +692,7 @@ static UniValue getblock(const JSONRPCRequest& request)
|
||||||
" ],\n"
|
" ],\n"
|
||||||
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||||
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||||
" \"signblock_witness_asm\":\"asm\", (string) scriptSig for block signing (asm)'\n"
|
" \"nTx\" : n, (numeric) The number of transactions in the block.\n"
|
||||||
" \"signblock_witness_hex\":\"hex\", (string) scriptSig for block signing (hex)'\n"
|
|
||||||
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
|
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
|
||||||
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
|
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue