message: Deduplicate some block-to-JSON code.
  Some of the logic converting blocks and block headers to JSON for
  the blockchain RPC methods (getblock, getlockheader) was duplicated.
  Instead of that, the blockToJSON RPC method now calls blockheaderToJSON
  first, and then fills in the missing, block-specific bits explicitly.
diff: @@ -162,21 +162,11 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
  UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails)
  {
  - // Serialize passed information without accessing chain state of the active chain!
  - AssertLockNotHeld(cs_main); // For performance reasons
  + UniValue result = blockheaderToJSON(tip, blockindex);
  - UniValue result(UniValue::VOBJ);
  - result.pushKV("hash", blockindex->GetBlockHash().GetHex());
  - const CBlockIndex* pnext;
  - int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext);
  - result.pushKV("confirmations", confirmations);
  result.pushKV("strippedsize", (int)::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS));
  result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION));
  result.pushKV("weight", (int)::GetBlockWeight(block));
  - result.pushKV("height", blockindex->nHeight);
  - result.pushKV("version", block.nVersion);
  - result.pushKV("versionHex", strprintf("%08x", block.nVersion));
  - result.pushKV("merkleroot", block.hashMerkleRoot.GetHex());
  UniValue txs(UniValue::VARR);
  if (txDetails) {
  CBlockUndo blockUndo;
  @@ -195,25 +185,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn
  }
  }
  result.pushKV("tx", txs);
  - result.pushKV("time", block.GetBlockTime());
  - result.pushKV("mediantime", (int64_t)blockindex->GetMedianTimePast());
  - result.pushKV("nonce", (uint64_t)block.nNonce);
  - result.pushKV("bits", strprintf("%08x", block.nBits));
  - result.pushKV("difficulty", GetDifficulty(blockindex));
  - result.pushKV("mint", ValueFromAmount(blockindex->nMint));
  - result.pushKV("chainwork", blockindex->nChainTrust.GetHex());
  - result.pushKV("nTx", (uint64_t)blockindex->nTx);
  - if (blockindex->pprev)
  - result.pushKV("previousblockhash", blockindex->pprev->GetBlockHash().GetHex());
  - if (pnext)
  - result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex());
  - result.pushKV("flags", strprintf("%s%s", blockindex->IsProofOfStake()? "proof-of-stake" : "proof-of-work", blockindex->GeneratedStakeModifier()? " stake-modifier": ""));
  - result.pushKV("proofhash", blockindex->IsProofOfStake()? blockindex->hashProofOfStake.GetHex() : blockindex->GetBlockHash().GetHex());
  - result.pushKV("entropybit", (int)blockindex->GetStakeEntropyBit());
  - result.pushKV("modifier", strprintf("%016llx", blockindex->nStakeModifier));
  - result.pushKV("modifierchecksum", strprintf("%08x", blockindex->nStakeModifierChecksum));
  - result.pushKV("blocksignature", HexStr(block.vchBlockSig));
  return result;
  }
  