Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, | UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, | ||||
const CBlockIndex *blockindex, bool txDetails) { | const CBlockIndex *blockindex, bool txDetails) { | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | ||||
const CBlockIndex *pnext; | const CBlockIndex *pnext; | ||||
int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext); | int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext); | ||||
result.pushKV("confirmations", confirmations); | result.pushKV("confirmations", confirmations); | ||||
result.pushKV( | result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION)); | ||||
"size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)); | |||||
result.pushKV("height", blockindex->nHeight); | result.pushKV("height", blockindex->nHeight); | ||||
result.pushKV("version", block.nVersion); | result.pushKV("version", block.nVersion); | ||||
result.pushKV("versionHex", strprintf("%08x", block.nVersion)); | result.pushKV("versionHex", strprintf("%08x", block.nVersion)); | ||||
result.pushKV("merkleroot", block.hashMerkleRoot.GetHex()); | result.pushKV("merkleroot", block.hashMerkleRoot.GetHex()); | ||||
UniValue txs(UniValue::VARR); | UniValue txs(UniValue::VARR); | ||||
for (const auto &tx : block.vtx) { | for (const auto &tx : block.vtx) { | ||||
if (txDetails) { | if (txDetails) { | ||||
UniValue objTx(UniValue::VOBJ); | UniValue objTx(UniValue::VOBJ); | ||||
▲ Show 20 Lines • Show All 1,933 Lines • ▼ Show 20 Lines | static UniValue getblockstats(const Config &config, | ||||
for (const auto &tx : block.vtx) { | for (const auto &tx : block.vtx) { | ||||
outputs += tx->vout.size(); | outputs += tx->vout.size(); | ||||
Amount tx_total_out = Amount::zero(); | Amount tx_total_out = Amount::zero(); | ||||
if (loop_outputs) { | if (loop_outputs) { | ||||
for (const CTxOut &out : tx->vout) { | for (const CTxOut &out : tx->vout) { | ||||
tx_total_out += out.nValue; | tx_total_out += out.nValue; | ||||
utxo_size_inc += | utxo_size_inc += | ||||
GetSerializeSize(out, SER_NETWORK, PROTOCOL_VERSION) + | GetSerializeSize(out, PROTOCOL_VERSION) + PER_UTXO_OVERHEAD; | ||||
PER_UTXO_OVERHEAD; | |||||
} | } | ||||
} | } | ||||
if (tx->IsCoinBase()) { | if (tx->IsCoinBase()) { | ||||
continue; | continue; | ||||
} | } | ||||
// Don't count coinbase's fake input | // Don't count coinbase's fake input | ||||
Show All 29 Lines | for (const auto &tx : block.vtx) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, | throw JSONRPCError(RPC_INTERNAL_ERROR, | ||||
std::string("Unexpected internal error " | std::string("Unexpected internal error " | ||||
"(tx index seems corrupt)")); | "(tx index seems corrupt)")); | ||||
} | } | ||||
CTxOut prevoutput = tx_in->vout[in.prevout.GetN()]; | CTxOut prevoutput = tx_in->vout[in.prevout.GetN()]; | ||||
tx_total_in += prevoutput.nValue; | tx_total_in += prevoutput.nValue; | ||||
utxo_size_inc -= GetSerializeSize(prevoutput, SER_NETWORK, | utxo_size_inc -= | ||||
PROTOCOL_VERSION) + | GetSerializeSize(prevoutput, PROTOCOL_VERSION) + | ||||
PER_UTXO_OVERHEAD; | PER_UTXO_OVERHEAD; | ||||
} | } | ||||
Amount txfee = tx_total_in - tx_total_out; | Amount txfee = tx_total_in - tx_total_out; | ||||
assert(MoneyRange(txfee)); | assert(MoneyRange(txfee)); | ||||
if (do_medianfee) { | if (do_medianfee) { | ||||
fee_array.push_back(txfee); | fee_array.push_back(txfee); | ||||
} | } | ||||
maxfee = std::max(maxfee, txfee); | maxfee = std::max(maxfee, txfee); | ||||
▲ Show 20 Lines • Show All 411 Lines • Show Last 20 Lines |