MCPcopy Create free account
hub / github.com/LUX-Core/lux / blockToJSON

Function blockToJSON

src/rpcblockchain.cpp:74–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
75{
76// printf("%s \n",__func__);
77 UniValue result(UniValue::VOBJ);
78 result.push_back(Pair("hash", block.GetHash(blockindex->nHeight).GetHex()));
79 int confirmations = -1;
80 // Only report confirmations if the block is on the main chain
81 if (chainActive.Contains(blockindex))
82 confirmations = chainActive.Height() - blockindex->nHeight + 1;
83 result.push_back(Pair("confirmations", confirmations));
84 result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
85 result.push_back(Pair("height", blockindex->nHeight));
86 result.push_back(Pair("version", block.nVersion));
87 result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
88 result.push_back(Pair("stateroot", block.hashStateRoot.GetHex()));
89 result.push_back(Pair("utxoroot", block.hashUTXORoot.GetHex()));
90 UniValue txs(UniValue::VARR);
91 for (const CTransaction& tx : block.vtx) {
92 if (txDetails) {
93 UniValue objTx(UniValue::VOBJ);
94 TxToJSON(tx, uint256(), objTx);
95 txs.push_back(objTx);
96 } else
97 txs.push_back(tx.GetHash().GetHex());
98 }
99 result.push_back(Pair("tx", txs));
100 result.push_back(Pair("time", block.GetBlockTime()));
101 result.push_back(Pair("nonce", (uint64_t)block.nNonce));
102 result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
103 result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
104 result.push_back(Pair("flags", strprintf("%s%s", blockindex->IsProofOfStake()?"proof-of-stake":"proof-of-work",
105 blockindex->IsProofOfStake() && blockindex->GeneratedStakeModifier()?" stake-modifier":"")));
106 result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
107
108 if (blockindex->pprev)
109 result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
110 CBlockIndex* pnext = chainActive.Next(blockindex);
111 if (pnext)
112 result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
113
114 // printf("leaving %s \n",__func__);
115 return result;
116}
117
118
119UniValue blockHeaderToJSON(const CBlock& block, const CBlockIndex* blockindex)

Callers 2

getblockFunction · 0.85
rest_blockFunction · 0.85

Calls 15

PairFunction · 0.85
GetSerializeSizeFunction · 0.85
TxToJSONFunction · 0.85
GetDifficultyFunction · 0.85
HeightMethod · 0.80
uint256Class · 0.70
push_backMethod · 0.45
GetHexMethod · 0.45
GetHashMethod · 0.45
ContainsMethod · 0.45
GetBlockTimeMethod · 0.45

Tested by

no test coverage detected