Created
May 28, 2014 03:01
-
-
Save ryancdotorg/5e610e9ee546beed367d to your computer and use it in GitHub Desktop.
patch to add height, confirmations and nextblockhash to namecoin's getblock rpc call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp | |
index d0a0d1d..94b4305 100644 | |
--- a/src/bitcoinrpc.cpp | |
+++ b/src/bitcoinrpc.cpp | |
@@ -278,25 +278,33 @@ Value getblocknumber(const Array& params, bool fHelp) | |
} | |
-Value BlockToValue(CBlock &block) | |
+Value BlockToValue(CBlock &block, CBlockIndex* blockindex) | |
{ | |
Object obj; | |
obj.push_back(Pair("hash", block.GetHash().ToString().c_str())); | |
+ CMerkleTx txGen(block.vtx[0]); | |
+ txGen.SetMerkleBranch(&block); | |
+ obj.push_back(Pair("confirmations", (int)txGen.GetDepthInMainChain())); | |
+ obj.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK))); | |
+ obj.push_back(Pair("height", blockindex->nHeight)); | |
obj.push_back(Pair("version", block.nVersion)); | |
- obj.push_back(Pair("previousblockhash", block.hashPrevBlock.ToString().c_str())); | |
obj.push_back(Pair("merkleroot", block.hashMerkleRoot.ToString().c_str())); | |
- obj.push_back(Pair("time", (uint64_t)block.nTime)); | |
- obj.push_back(Pair("bits", (uint64_t)block.nBits)); | |
- obj.push_back(Pair("nonce", (uint64_t)block.nNonce)); | |
- obj.push_back(Pair("n_tx", (int)block.vtx.size())); | |
- obj.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK))); | |
- | |
Array tx; | |
for (int i = 0; i < block.vtx.size(); i++) { | |
tx.push_back(block.vtx[i].GetHash().ToString().c_str()); | |
} | |
- | |
obj.push_back(Pair("tx", tx)); | |
+ obj.push_back(Pair("time", (uint64_t)block.nTime)); | |
+ obj.push_back(Pair("nonce", (uint64_t)block.nNonce)); | |
+ obj.push_back(Pair("bits", (uint64_t)block.nBits)); | |
+ obj.push_back(Pair("n_tx", (int)block.vtx.size())); | |
+ | |
+ if (blockindex->pprev) | |
+ obj.push_back(Pair("previousblockhash", block.hashPrevBlock.ToString().c_str())); | |
+ if (blockindex->nHeight < nBestHeight) { | |
+ CBlockIndex *pnext = FindBlockByHeight(blockindex->nHeight+1); | |
+ obj.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex())); | |
+ } | |
Array mrkl; | |
for (int i = 0; i < block.vMerkleTree.size(); i++) | |
@@ -344,7 +352,7 @@ Value getblockbycount(const Array& params, bool fHelp) | |
block.ReadFromDisk(pindex); | |
block.BuildMerkleTree(); | |
- return BlockToValue(block); | |
+ return BlockToValue(block, pindex); | |
} | |
@@ -368,7 +376,7 @@ Value getblock(const Array& params, bool fHelp) | |
block.ReadFromDisk(pindex); | |
block.BuildMerkleTree(); | |
- return BlockToValue(block); | |
+ return BlockToValue(block, pindex); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment