MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / blockToJSON

Function blockToJSON

src/rpcblockchain.cpp:83–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
84{
85 UniValue result(UniValue::VOBJ);
86 result.push_back(Pair("hash", block.GetHash().GetHex()));
87 int confirmations = -1;
88 // Only report confirmations if the block is on the main chain
89 if (chainActive.Contains(blockindex))
90 confirmations = chainActive.Height() - blockindex->nHeight + 1;
91 result.push_back(Pair("confirmations", confirmations));
92 result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
93 result.push_back(Pair("height", blockindex->nHeight));
94 result.push_back(Pair("version", block.nVersion));
95 result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
96 UniValue txs(UniValue::VARR);
97 BOOST_FOREACH(const CTransaction&tx, block.vtx)
98 {
99 if(txDetails)
100 {
101 UniValue objTx(UniValue::VOBJ);
102 TxToJSON(tx, uint256(), objTx);
103 txs.push_back(objTx);
104 }
105 else
106 txs.push_back(tx.GetHash().GetHex());
107 }
108 result.push_back(Pair("tx", txs));
109 result.push_back(Pair("time", block.GetBlockTime()));
110 result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
111 result.push_back(Pair("nonce", (uint64_t)block.nNonce));
112 result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
113 result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
114 result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
115 result.push_back(Pair("sizelimit", blockindex->nMaxBlockSize));
116 result.push_back(Pair("sizelimitvote", blockindex->nMaxBlockSizeVote));
117
118 if (blockindex->pprev)
119 result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
120 CBlockIndex *pnext = chainActive.Next(blockindex);
121 if (pnext)
122 result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
123 return result;
124}
125
126UniValue getblockcount(const UniValue& params, bool fHelp)
127{

Callers 2

getblockFunction · 0.85
rest_blockFunction · 0.85

Calls 12

PairFunction · 0.85
GetSerializeSizeFunction · 0.85
GetDifficultyFunction · 0.85
HeightMethod · 0.80
GetMedianTimePastMethod · 0.80
push_backMethod · 0.45
GetHexMethod · 0.45
GetHashMethod · 0.45
ContainsMethod · 0.45
GetBlockTimeMethod · 0.45
GetBlockHashMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected