message: Make getblockheader RPC return more information
diff: @@ -51,6 +51,32 @@ double GetDifficulty(const CBlockIndex* blockindex)
  return dDiff;
  }
  +UniValue blockheaderToJSON(const CBlockIndex* blockindex)
  +{
  + UniValue result(UniValue::VOBJ);
  + result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex()));
  + int confirmations = -1;
  + // Only report confirmations if the block is on the main chain
  + if (chainActive.Contains(blockindex))
  + confirmations = chainActive.Height() - blockindex->nHeight + 1;
  + result.push_back(Pair("confirmations", confirmations));
  + result.push_back(Pair("height", blockindex->nHeight));
  + result.push_back(Pair("version", blockindex->nVersion));
  + result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
  + result.push_back(Pair("time", (int64_t)blockindex->nTime));
  + result.push_back(Pair("nonce", (uint64_t)blockindex->nNonce));
  + result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits)));
  + result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
  + result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
  + result.push_back(Pair("acc_checkpoint", blockindex->nAccumulatorCheckpoint.GetHex()));
  +
  + if (blockindex->pprev)
  + result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
  + CBlockIndex *pnext = chainActive.Next(blockindex);
  + if (pnext)
  + result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
  + return result;
  +}
  UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
  {
  @@ -100,21 +126,6 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
  return result;
  }
  -
  -UniValue blockHeaderToJSON(const CBlock& block, const CBlockIndex* blockindex)
  -{
  - UniValue result(UniValue::VOBJ);
  - result.push_back(Pair("version", block.nVersion));
  - if (blockindex->pprev)
  - result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
  - result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
  - result.push_back(Pair("time", block.GetBlockTime()));
  - result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
  - result.push_back(Pair("nonce", (uint64_t)block.nNonce));
  - return result;
  -}
  -
  -
  UniValue getblockcount(const UniValue& params, bool fHelp)
  {
  if (fHelp || params.size() != 0)
  @@ -368,20 +379,16 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
  if (mapBlockIndex.count(hash) == 0)
  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
  - CBlock block;
  CBlockIndex* pblockindex = mapBlockIndex[hash];
  - if (!ReadBlockFromDisk(block, pblockindex))
  - throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
  -
  if (!fVerbose) {
  CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
  - ssBlock << block.GetBlockHeader();
  + ssBlock << pblockindex->GetBlockHeader();
  std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
  return strHex;
  }
  - return blockHeaderToJSON(block, pblockindex);
  + return blockheaderToJSON(pblockindex);
  }
  UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
  