Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 820 Lines • ▼ Show 20 Lines | |||||
static CBlock GetBlockChecked(const Config &config, | static CBlock GetBlockChecked(const Config &config, | ||||
const CBlockIndex *pblockindex) { | const CBlockIndex *pblockindex) { | ||||
CBlock block; | CBlock block; | ||||
if (fHavePruned && !pblockindex->nStatus.hasData() && | if (fHavePruned && !pblockindex->nStatus.hasData() && | ||||
pblockindex->nTx > 0) { | pblockindex->nTx > 0) { | ||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)"); | throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)"); | ||||
} | } | ||||
if (!ReadBlockFromDisk(block, pblockindex, config)) { | if (!ReadBlockFromDisk(block, pblockindex, | ||||
config.GetChainParams().GetConsensus())) { | |||||
// Block not found on disk. This could be because we have the block | // Block not found on disk. This could be because we have the block | ||||
// header in our index but don't have the block (for example if a | // header in our index but don't have the block (for example if a | ||||
// non-whitelisted node sends us an unrequested long chain of valid | // non-whitelisted node sends us an unrequested long chain of valid | ||||
// blocks, we add the headers to our index, but don't accept the block). | // blocks, we add the headers to our index, but don't accept the block). | ||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk"); | throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk"); | ||||
} | } | ||||
return block; | return block; | ||||
▲ Show 20 Lines • Show All 1,180 Lines • ▼ Show 20 Lines | static UniValue getblockstats(const Config &config, | ||||
int64_t mintxsize = blockMaxSize; | int64_t mintxsize = blockMaxSize; | ||||
int64_t outputs = 0; | int64_t outputs = 0; | ||||
int64_t total_size = 0; | int64_t total_size = 0; | ||||
int64_t utxo_size_inc = 0; | int64_t utxo_size_inc = 0; | ||||
std::vector<Amount> fee_array; | std::vector<Amount> fee_array; | ||||
std::vector<Amount> feerate_array; | std::vector<Amount> feerate_array; | ||||
std::vector<int64_t> txsize_array; | std::vector<int64_t> txsize_array; | ||||
const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); | |||||
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, SER_NETWORK, PROTOCOL_VERSION) + | ||||
Show All 18 Lines | for (const auto &tx : block.vtx) { | ||||
txsize_array.push_back(tx_size); | txsize_array.push_back(tx_size); | ||||
} | } | ||||
maxtxsize = std::max(maxtxsize, tx_size); | maxtxsize = std::max(maxtxsize, tx_size); | ||||
mintxsize = std::min(mintxsize, tx_size); | mintxsize = std::min(mintxsize, tx_size); | ||||
total_size += tx_size; | total_size += tx_size; | ||||
} | } | ||||
if (loop_inputs) { | if (loop_inputs) { | ||||
if (!g_txindex) { | if (!g_txindex) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"One or more of the selected stats requires " | "One or more of the selected stats requires " | ||||
"-txindex enabled"); | "-txindex enabled"); | ||||
} | } | ||||
Amount tx_total_in = Amount::zero(); | Amount tx_total_in = Amount::zero(); | ||||
for (const CTxIn &in : tx->vin) { | for (const CTxIn &in : tx->vin) { | ||||
CTransactionRef tx_in; | CTransactionRef tx_in; | ||||
uint256 hashBlock; | uint256 hashBlock; | ||||
if (!GetTransaction(config, in.prevout.GetTxId(), tx_in, | if (!GetTransaction(params, in.prevout.GetTxId(), tx_in, | ||||
hashBlock, false)) { | hashBlock, false)) { | ||||
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()]; | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |