Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex) { Object result; result.push_back(Pair("hash", block.GetHash().GetHex())); CMerkleTx txGen(block.vptx[0]); txGen.SetMerkleBranch(&block); result.push_back(Pair("confirmations", (int)txGen.GetDepthInMainChain())); result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.GetVersion())); result.push_back(Pair("merkleroot", block.GetHashMerkleRoot().GetHex())); result.push_back(Pair("txnumber", (int)block.vptx.size())); Array txs; for (const auto& ptx : block.vptx) // txs.push_back(TxToJSON(ptx.get())); txs.push_back(ptx->GetHash().GetHex()); result.push_back(Pair("tx", txs)); result.push_back(Pair("time", block.GetBlockTime())); result.push_back(Pair("nonce", (uint64_t)block.GetNonce())); result.push_back(Pair("bits", HexBits(block.GetBits()))); result.push_back(Pair("difficulty", GetDifficulty(blockindex))); result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); result.push_back(Pair("fuel", blockindex->nFuel)); result.push_back(Pair("fuelrate", blockindex->nFuelRate)); 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; }
Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex) { Object result; result.push_back(Pair("hash", block.GetHash().GetHex())); CMerkleTx txGen(block.vtx[0]); txGen.SetMerkleBranch(&block); result.push_back(Pair("confirmations", (int)txGen.GetDepthInMainChain())); result.push_back(Pair("size", (int)blockindex->nSize)); result.push_back(Pair("chainsize", blockindex->nChainSize)); if (chainActive.Contains(blockindex)) result.push_back(Pair("maxsize", (int)chainActive.MaxBlockSize(blockindex->nHeight))); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", (uint64_t)block.GetVersion())); result.push_back(Pair("ispok", block.IsPoKBlock())); if (block.IsPoKBlock()) result.push_back(Pair("pok", (uint64_t)block.GetPoK())); result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); result.push_back(Pair("time", block.GetBlockTime())); result.push_back(Pair("bits", HexBits(block.nBits))); result.push_back(Pair("nonce", (uint64_t)block.nNonce)); Array txs; BOOST_FOREACH(const CTransaction&tx, block.vtx) txs.push_back(tx.GetHash().GetHex()); result.push_back(Pair("tx", txs)); result.push_back(Pair("difficulty", GetDifficulty(blockindex))); result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); result.push_back(Pair("ntx", (int64_t)blockindex->nTx)); result.push_back(Pair("nchaintx", (int64_t)blockindex->nChainTx)); 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; }