mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
rpc: Compute number of confirmations of a block from block height
Currently this uses a CMerkleTx, but that makes no sense as we have the CBlockIndex available. As noted by @jgarzik.
This commit is contained in:
parent
539abc4729
commit
57153d4e1a
@ -54,9 +54,11 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex)
|
|||||||
{
|
{
|
||||||
Object result;
|
Object result;
|
||||||
result.push_back(Pair("hash", block.GetHash().GetHex()));
|
result.push_back(Pair("hash", block.GetHash().GetHex()));
|
||||||
CMerkleTx txGen(block.vtx[0]);
|
int confirmations = -1;
|
||||||
txGen.SetMerkleBranch(&block);
|
// Only report confirmations if the block is on the main chain
|
||||||
result.push_back(Pair("confirmations", (int)txGen.GetDepthInMainChain()));
|
if (chainActive.Contains(blockindex))
|
||||||
|
confirmations = chainActive.Height() - blockindex->nHeight + 1;
|
||||||
|
result.push_back(Pair("confirmations", confirmations));
|
||||||
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
|
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
|
||||||
result.push_back(Pair("height", blockindex->nHeight));
|
result.push_back(Pair("height", blockindex->nHeight));
|
||||||
result.push_back(Pair("version", block.nVersion));
|
result.push_back(Pair("version", block.nVersion));
|
||||||
@ -242,7 +244,7 @@ Value getblock(const Array& params, bool fHelp)
|
|||||||
"\nResult (for verbose = true):\n"
|
"\nResult (for verbose = true):\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
|
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
|
||||||
" \"confirmations\" : n, (numeric) The number of confirmations\n"
|
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
|
||||||
" \"size\" : n, (numeric) The block size\n"
|
" \"size\" : n, (numeric) The block size\n"
|
||||||
" \"height\" : n, (numeric) The block height or index\n"
|
" \"height\" : n, (numeric) The block height or index\n"
|
||||||
" \"version\" : n, (numeric) The block version\n"
|
" \"version\" : n, (numeric) The block version\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user