| 162 | } |
| 163 | |
| 164 | UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex, const uint256 pow_limit) |
| 165 | { |
| 166 | // Serialize passed information without accessing chain state of the active chain! |
| 167 | AssertLockNotHeld(cs_main); // For performance reasons |
| 168 | |
| 169 | UniValue result(UniValue::VOBJ); |
| 170 | result.pushKV("hash", blockindex.GetBlockHash().GetHex()); |
| 171 | const CBlockIndex* pnext; |
| 172 | int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext); |
| 173 | result.pushKV("confirmations", confirmations); |
| 174 | result.pushKV("height", blockindex.nHeight); |
| 175 | result.pushKV("version", blockindex.nVersion); |
| 176 | result.pushKV("versionHex", strprintf("%08x", blockindex.nVersion)); |
| 177 | result.pushKV("merkleroot", blockindex.hashMerkleRoot.GetHex()); |
| 178 | result.pushKV("time", blockindex.nTime); |
| 179 | result.pushKV("mediantime", blockindex.GetMedianTimePast()); |
| 180 | result.pushKV("nonce", blockindex.nNonce); |
| 181 | result.pushKV("bits", strprintf("%08x", blockindex.nBits)); |
| 182 | result.pushKV("target", GetTarget(blockindex, pow_limit).GetHex()); |
| 183 | result.pushKV("difficulty", GetDifficulty(blockindex)); |
| 184 | result.pushKV("chainwork", blockindex.nChainWork.GetHex()); |
| 185 | result.pushKV("nTx", blockindex.nTx); |
| 186 | |
| 187 | if (blockindex.pprev) |
| 188 | result.pushKV("previousblockhash", blockindex.pprev->GetBlockHash().GetHex()); |
| 189 | if (pnext) |
| 190 | result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); |
| 191 | return result; |
| 192 | } |
| 193 | |
| 194 | /** Serialize coinbase transaction metadata */ |
| 195 | UniValue coinbaseTxToJSON(const CTransaction& coinbase_tx) |
no test coverage detected