| 95 | } |
| 96 | |
| 97 | UniValue blockheaderToJSON(const CBlockIndex* blockindex) |
| 98 | { |
| 99 | AssertLockHeld(cs_main); |
| 100 | UniValue result(UniValue::VOBJ); |
| 101 | result.pushKV("hash", blockindex->GetBlockHash().GetHex()); |
| 102 | int confirmations = -1; |
| 103 | // Only report confirmations if the block is on the main chain |
| 104 | if (chainActive.Contains(blockindex)) |
| 105 | confirmations = chainActive.Height() - blockindex->nHeight + 1; |
| 106 | result.pushKV("confirmations", confirmations); |
| 107 | result.pushKV("height", blockindex->nHeight); |
| 108 | result.pushKV("version", blockindex->nVersion); |
| 109 | result.pushKV("versionHex", strprintf("%08x", blockindex->nVersion)); |
| 110 | result.pushKV("merkleroot", blockindex->hashMerkleRoot.GetHex()); |
| 111 | result.pushKV("time", (int64_t)blockindex->nTime); |
| 112 | result.pushKV("mediantime", (int64_t)blockindex->GetMedianTimePast()); |
| 113 | result.pushKV("nonceUint32", (uint64_t)((uint32_t)blockindex->nNonce.GetUint64(0))); |
| 114 | result.pushKV("nonce", blockindex->nNonce.GetHex()); |
| 115 | result.pushKV("solution", HexStr(blockindex->nSolution)); |
| 116 | result.pushKV("bits", strprintf("%08x", blockindex->nBits)); |
| 117 | result.pushKV("difficulty", GetDifficulty(blockindex)); |
| 118 | result.pushKV("chainwork", blockindex->nChainWork.GetHex()); |
| 119 | result.pushKV("nTx", (uint64_t)blockindex->nTx); |
| 120 | result.pushKV("receivedTime", (uint64_t)blockindex->GetHeaderReceivedTime()); |
| 121 | |
| 122 | if (blockindex->pprev) |
| 123 | result.pushKV("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()); |
| 124 | CBlockIndex *pnext = chainActive.Next(blockindex); |
| 125 | if (pnext) |
| 126 | result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); |
| 127 | return result; |
| 128 | } |
| 129 | |
| 130 | UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails) |
| 131 | { |
no test coverage detected