| 52 | } |
| 53 | |
| 54 | UniValue blockheaderToJSON(const CBlockIndex* blockindex) |
| 55 | { |
| 56 | UniValue result(UniValue::VOBJ); |
| 57 | result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex())); |
| 58 | int confirmations = -1; |
| 59 | // Only report confirmations if the block is on the main chain |
| 60 | if (chainActive.Contains(blockindex)) |
| 61 | confirmations = chainActive.Height() - blockindex->nHeight + 1; |
| 62 | result.push_back(Pair("confirmations", confirmations)); |
| 63 | result.push_back(Pair("height", blockindex->nHeight)); |
| 64 | result.push_back(Pair("version", blockindex->nVersion)); |
| 65 | result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex())); |
| 66 | result.push_back(Pair("time", (int64_t)blockindex->nTime)); |
| 67 | result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast())); |
| 68 | result.push_back(Pair("nonce", (uint64_t)blockindex->nNonce)); |
| 69 | result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits))); |
| 70 | result.push_back(Pair("difficulty", GetDifficulty(blockindex))); |
| 71 | result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); |
| 72 | result.push_back(Pair("sizelimit", blockindex->nMaxBlockSize)); |
| 73 | result.push_back(Pair("sizelimitvote", blockindex->nMaxBlockSizeVote)); |
| 74 | |
| 75 | if (blockindex->pprev) |
| 76 | result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex())); |
| 77 | CBlockIndex *pnext = chainActive.Next(blockindex); |
| 78 | if (pnext) |
| 79 | result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex())); |
| 80 | return result; |
| 81 | } |
| 82 | |
| 83 | UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) |
| 84 | { |
no test coverage detected