Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 529 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static void entryToJSON(const CTxMemPool &pool, UniValue &info, | static void entryToJSON(const CTxMemPool &pool, UniValue &info, | ||||
const CTxMemPoolEntry &e) | const CTxMemPoolEntry &e) | ||||
EXCLUSIVE_LOCKS_REQUIRED(pool.cs) { | EXCLUSIVE_LOCKS_REQUIRED(pool.cs) { | ||||
AssertLockHeld(pool.cs); | AssertLockHeld(pool.cs); | ||||
UniValue fees(UniValue::VOBJ); | UniValue fees(UniValue::VOBJ); | ||||
fees.pushKV("base", ValueFromAmount(e.GetFee())); | fees.pushKV("base", e.GetFee()); | ||||
fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee())); | fees.pushKV("modified", e.GetModifiedFee()); | ||||
fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors())); | fees.pushKV("ancestor", e.GetModFeesWithAncestors()); | ||||
fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants())); | fees.pushKV("descendant", e.GetModFeesWithDescendants()); | ||||
info.pushKV("fees", fees); | info.pushKV("fees", fees); | ||||
info.pushKV("size", (int)e.GetTxSize()); | info.pushKV("size", (int)e.GetTxSize()); | ||||
info.pushKV("fee", ValueFromAmount(e.GetFee())); | info.pushKV("fee", e.GetFee()); | ||||
info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee())); | info.pushKV("modifiedfee", e.GetModifiedFee()); | ||||
info.pushKV("time", count_seconds(e.GetTime())); | info.pushKV("time", count_seconds(e.GetTime())); | ||||
info.pushKV("height", (int)e.GetHeight()); | info.pushKV("height", (int)e.GetHeight()); | ||||
info.pushKV("descendantcount", e.GetCountWithDescendants()); | info.pushKV("descendantcount", e.GetCountWithDescendants()); | ||||
info.pushKV("descendantsize", e.GetSizeWithDescendants()); | info.pushKV("descendantsize", e.GetSizeWithDescendants()); | ||||
info.pushKV("descendantfees", e.GetModFeesWithDescendants() / SATOSHI); | info.pushKV("descendantfees", e.GetModFeesWithDescendants() / SATOSHI); | ||||
info.pushKV("ancestorcount", e.GetCountWithAncestors()); | info.pushKV("ancestorcount", e.GetCountWithAncestors()); | ||||
info.pushKV("ancestorsize", e.GetSizeWithAncestors()); | info.pushKV("ancestorsize", e.GetSizeWithAncestors()); | ||||
info.pushKV("ancestorfees", e.GetModFeesWithAncestors() / SATOSHI); | info.pushKV("ancestorfees", e.GetModFeesWithAncestors() / SATOSHI); | ||||
▲ Show 20 Lines • Show All 662 Lines • ▼ Show 20 Lines | static UniValue gettxoutsetinfo(const Config &config, | ||||
if (GetUTXOStats(coins_view, stats, node.rpc_interruption_point)) { | if (GetUTXOStats(coins_view, stats, node.rpc_interruption_point)) { | ||||
ret.pushKV("height", int64_t(stats.nHeight)); | ret.pushKV("height", int64_t(stats.nHeight)); | ||||
ret.pushKV("bestblock", stats.hashBlock.GetHex()); | ret.pushKV("bestblock", stats.hashBlock.GetHex()); | ||||
ret.pushKV("transactions", int64_t(stats.nTransactions)); | ret.pushKV("transactions", int64_t(stats.nTransactions)); | ||||
ret.pushKV("txouts", int64_t(stats.nTransactionOutputs)); | ret.pushKV("txouts", int64_t(stats.nTransactionOutputs)); | ||||
ret.pushKV("bogosize", int64_t(stats.nBogoSize)); | ret.pushKV("bogosize", int64_t(stats.nBogoSize)); | ||||
ret.pushKV("hash_serialized", stats.hashSerialized.GetHex()); | ret.pushKV("hash_serialized", stats.hashSerialized.GetHex()); | ||||
ret.pushKV("disk_size", stats.nDiskSize); | ret.pushKV("disk_size", stats.nDiskSize); | ||||
ret.pushKV("total_amount", ValueFromAmount(stats.nTotalAmount)); | ret.pushKV("total_amount", stats.nTotalAmount); | ||||
} else { | } else { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set"); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | ||||
const CBlockIndex *pindex = LookupBlockIndex(coins_view->GetBestBlock()); | const CBlockIndex *pindex = LookupBlockIndex(coins_view->GetBestBlock()); | ||||
ret.pushKV("bestblock", pindex->GetBlockHash().GetHex()); | ret.pushKV("bestblock", pindex->GetBlockHash().GetHex()); | ||||
if (coin.GetHeight() == MEMPOOL_HEIGHT) { | if (coin.GetHeight() == MEMPOOL_HEIGHT) { | ||||
ret.pushKV("confirmations", 0); | ret.pushKV("confirmations", 0); | ||||
} else { | } else { | ||||
ret.pushKV("confirmations", | ret.pushKV("confirmations", | ||||
int64_t(pindex->nHeight - coin.GetHeight() + 1)); | int64_t(pindex->nHeight - coin.GetHeight() + 1)); | ||||
} | } | ||||
ret.pushKV("value", ValueFromAmount(coin.GetTxOut().nValue)); | ret.pushKV("value", coin.GetTxOut().nValue); | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
ScriptPubKeyToUniv(coin.GetTxOut().scriptPubKey, o, true); | ScriptPubKeyToUniv(coin.GetTxOut().scriptPubKey, o, true); | ||||
ret.pushKV("scriptPubKey", o); | ret.pushKV("scriptPubKey", o); | ||||
ret.pushKV("coinbase", coin.IsCoinBase()); | ret.pushKV("coinbase", coin.IsCoinBase()); | ||||
return ret; | return ret; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 398 Lines • ▼ Show 20 Lines | UniValue MempoolInfoToJSON(const CTxMemPool &pool) { | ||||
ret.pushKV("size", (int64_t)pool.size()); | ret.pushKV("size", (int64_t)pool.size()); | ||||
ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize()); | ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize()); | ||||
ret.pushKV("usage", (int64_t)pool.DynamicMemoryUsage()); | ret.pushKV("usage", (int64_t)pool.DynamicMemoryUsage()); | ||||
size_t maxmempool = | size_t maxmempool = | ||||
gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; | gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; | ||||
ret.pushKV("maxmempool", (int64_t)maxmempool); | ret.pushKV("maxmempool", (int64_t)maxmempool); | ||||
ret.pushKV( | ret.pushKV( | ||||
"mempoolminfee", | "mempoolminfee", | ||||
ValueFromAmount(std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee) | std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee).GetFeePerK()); | ||||
.GetFeePerK())); | ret.pushKV("minrelaytxfee", ::minRelayTxFee.GetFeePerK()); | ||||
ret.pushKV("minrelaytxfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); | |||||
ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()}); | ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()}); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue getmempoolinfo(const Config &config, | static UniValue getmempoolinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getmempoolinfo", | "getmempoolinfo", | ||||
▲ Show 20 Lines • Show All 628 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < block.vtx.size(); ++i) { | ||||
feerate_array.push_back(feerate); | feerate_array.push_back(feerate); | ||||
} | } | ||||
maxfeerate = std::max(maxfeerate, feerate); | maxfeerate = std::max(maxfeerate, feerate); | ||||
minfeerate = std::min(minfeerate, feerate); | minfeerate = std::min(minfeerate, feerate); | ||||
} | } | ||||
} | } | ||||
UniValue ret_all(UniValue::VOBJ); | UniValue ret_all(UniValue::VOBJ); | ||||
ret_all.pushKV("avgfee", | ret_all.pushKV("avgfee", block.vtx.size() > 1 | ||||
ValueFromAmount((block.vtx.size() > 1) | ? (totalfee / int((block.vtx.size() - 1))) | ||||
? totalfee / int((block.vtx.size() - 1)) | : Amount::zero()); | ||||
: Amount::zero())); | |||||
ret_all.pushKV("avgfeerate", | ret_all.pushKV("avgfeerate", | ||||
ValueFromAmount((total_size > 0) ? totalfee / total_size | total_size > 0 ? (totalfee / total_size) : Amount::zero()); | ||||
: Amount::zero())); | |||||
ret_all.pushKV("avgtxsize", (block.vtx.size() > 1) | ret_all.pushKV("avgtxsize", (block.vtx.size() > 1) | ||||
? total_size / (block.vtx.size() - 1) | ? total_size / (block.vtx.size() - 1) | ||||
: 0); | : 0); | ||||
ret_all.pushKV("blockhash", pindex->GetBlockHash().GetHex()); | ret_all.pushKV("blockhash", pindex->GetBlockHash().GetHex()); | ||||
ret_all.pushKV("height", (int64_t)pindex->nHeight); | ret_all.pushKV("height", (int64_t)pindex->nHeight); | ||||
ret_all.pushKV("ins", inputs); | ret_all.pushKV("ins", inputs); | ||||
ret_all.pushKV("maxfee", ValueFromAmount(maxfee)); | ret_all.pushKV("maxfee", maxfee); | ||||
ret_all.pushKV("maxfeerate", ValueFromAmount(maxfeerate)); | ret_all.pushKV("maxfeerate", maxfeerate); | ||||
ret_all.pushKV("maxtxsize", maxtxsize); | ret_all.pushKV("maxtxsize", maxtxsize); | ||||
ret_all.pushKV("medianfee", | ret_all.pushKV("medianfee", CalculateTruncatedMedian(fee_array)); | ||||
ValueFromAmount(CalculateTruncatedMedian(fee_array))); | ret_all.pushKV("medianfeerate", CalculateTruncatedMedian(feerate_array)); | ||||
ret_all.pushKV("medianfeerate", | |||||
ValueFromAmount(CalculateTruncatedMedian(feerate_array))); | |||||
ret_all.pushKV("mediantime", pindex->GetMedianTimePast()); | ret_all.pushKV("mediantime", pindex->GetMedianTimePast()); | ||||
ret_all.pushKV("mediantxsize", CalculateTruncatedMedian(txsize_array)); | ret_all.pushKV("mediantxsize", CalculateTruncatedMedian(txsize_array)); | ||||
ret_all.pushKV( | ret_all.pushKV("minfee", minfee == MAX_MONEY ? Amount::zero() : minfee); | ||||
"minfee", | |||||
ValueFromAmount((minfee == MAX_MONEY) ? Amount::zero() : minfee)); | |||||
ret_all.pushKV("minfeerate", | ret_all.pushKV("minfeerate", | ||||
ValueFromAmount((minfeerate == MAX_MONEY) ? Amount::zero() | minfeerate == MAX_MONEY ? Amount::zero() : minfeerate); | ||||
: minfeerate)); | |||||
ret_all.pushKV("mintxsize", mintxsize == blockMaxSize ? 0 : mintxsize); | ret_all.pushKV("mintxsize", mintxsize == blockMaxSize ? 0 : mintxsize); | ||||
ret_all.pushKV("outs", outputs); | ret_all.pushKV("outs", outputs); | ||||
ret_all.pushKV("subsidy", ValueFromAmount(GetBlockSubsidy( | ret_all.pushKV("subsidy", | ||||
pindex->nHeight, Params().GetConsensus()))); | GetBlockSubsidy(pindex->nHeight, Params().GetConsensus())); | ||||
ret_all.pushKV("time", pindex->GetBlockTime()); | ret_all.pushKV("time", pindex->GetBlockTime()); | ||||
ret_all.pushKV("total_out", ValueFromAmount(total_out)); | ret_all.pushKV("total_out", total_out); | ||||
ret_all.pushKV("total_size", total_size); | ret_all.pushKV("total_size", total_size); | ||||
ret_all.pushKV("totalfee", ValueFromAmount(totalfee)); | ret_all.pushKV("totalfee", totalfee); | ||||
ret_all.pushKV("txs", (int64_t)block.vtx.size()); | ret_all.pushKV("txs", (int64_t)block.vtx.size()); | ||||
ret_all.pushKV("utxo_increase", outputs - inputs); | ret_all.pushKV("utxo_increase", outputs - inputs); | ||||
ret_all.pushKV("utxo_size_inc", utxo_size_inc); | ret_all.pushKV("utxo_size_inc", utxo_size_inc); | ||||
if (do_all) { | if (do_all) { | ||||
return ret_all; | return ret_all; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 293 Lines • ▼ Show 20 Lines | if (request.params[0].get_str() == "status") { | ||||
input_txos.push_back(txo); | input_txos.push_back(txo); | ||||
total_in += txo.nValue; | total_in += txo.nValue; | ||||
UniValue unspent(UniValue::VOBJ); | UniValue unspent(UniValue::VOBJ); | ||||
unspent.pushKV("txid", outpoint.GetTxId().GetHex()); | unspent.pushKV("txid", outpoint.GetTxId().GetHex()); | ||||
unspent.pushKV("vout", int32_t(outpoint.GetN())); | unspent.pushKV("vout", int32_t(outpoint.GetN())); | ||||
unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey)); | unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey)); | ||||
unspent.pushKV("desc", descriptors[txo.scriptPubKey]); | unspent.pushKV("desc", descriptors[txo.scriptPubKey]); | ||||
unspent.pushKV("amount", ValueFromAmount(txo.nValue)); | unspent.pushKV("amount", txo.nValue); | ||||
unspent.pushKV("height", int32_t(coin.GetHeight())); | unspent.pushKV("height", int32_t(coin.GetHeight())); | ||||
unspents.push_back(unspent); | unspents.push_back(unspent); | ||||
} | } | ||||
result.pushKV("unspents", unspents); | result.pushKV("unspents", unspents); | ||||
result.pushKV("total_amount", ValueFromAmount(total_in)); | result.pushKV("total_amount", total_in); | ||||
} else { | } else { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid command"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid command"); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue getblockfilter(const Config &config, | static UniValue getblockfilter(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines |