Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | UniValue blockheaderToJSON(const CBlockIndex *blockindex) { | ||||
int confirmations = -1; | int confirmations = -1; | ||||
// Only report confirmations if the block is on the main chain | // Only report confirmations if the block is on the main chain | ||||
if (chainActive.Contains(blockindex)) { | if (chainActive.Contains(blockindex)) { | ||||
confirmations = chainActive.Height() - blockindex->nHeight + 1; | confirmations = chainActive.Height() - blockindex->nHeight + 1; | ||||
} | } | ||||
result.pushKV("confirmations", confirmations); | result.pushKV("confirmations", confirmations); | ||||
result.pushKV("height", blockindex->nHeight); | result.pushKV("height", blockindex->nHeight); | ||||
result.pushKV("version", blockindex->nVersion); | result.pushKV("version", blockindex->nVersion); | ||||
result.push_back( | result.pushKV("versionHex", strprintf("%08x", blockindex->nVersion)); | ||||
Pair("versionHex", strprintf("%08x", blockindex->nVersion))); | |||||
result.pushKV("merkleroot", blockindex->hashMerkleRoot.GetHex()); | result.pushKV("merkleroot", blockindex->hashMerkleRoot.GetHex()); | ||||
result.pushKV("time", int64_t(blockindex->nTime)); | result.pushKV("time", int64_t(blockindex->nTime)); | ||||
result.push_back( | result.pushKV("mediantime", int64_t(blockindex->GetMedianTimePast())); | ||||
Pair("mediantime", int64_t(blockindex->GetMedianTimePast()))); | |||||
result.pushKV("nonce", uint64_t(blockindex->nNonce)); | result.pushKV("nonce", uint64_t(blockindex->nNonce)); | ||||
result.pushKV("bits", strprintf("%08x", blockindex->nBits)); | result.pushKV("bits", strprintf("%08x", blockindex->nBits)); | ||||
result.pushKV("difficulty", GetDifficulty(blockindex)); | result.pushKV("difficulty", GetDifficulty(blockindex)); | ||||
result.pushKV("chainwork", blockindex->nChainWork.GetHex()); | result.pushKV("chainwork", blockindex->nChainWork.GetHex()); | ||||
if (blockindex->pprev) { | if (blockindex->pprev) { | ||||
result.push_back(Pair("previousblockhash", | result.pushKV("previousblockhash", | ||||
blockindex->pprev->GetBlockHash().GetHex())); | blockindex->pprev->GetBlockHash().GetHex()); | ||||
} | } | ||||
CBlockIndex *pnext = chainActive.Next(blockindex); | CBlockIndex *pnext = chainActive.Next(blockindex); | ||||
if (pnext) { | if (pnext) { | ||||
result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
UniValue blockToJSON(const Config &config, const CBlock &block, | UniValue blockToJSON(const Config &config, const CBlock &block, | ||||
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()); | ||||
int confirmations = -1; | int confirmations = -1; | ||||
// Only report confirmations if the block is on the main chain | // Only report confirmations if the block is on the main chain | ||||
if (chainActive.Contains(blockindex)) { | if (chainActive.Contains(blockindex)) { | ||||
confirmations = chainActive.Height() - blockindex->nHeight + 1; | confirmations = chainActive.Height() - blockindex->nHeight + 1; | ||||
} | } | ||||
result.pushKV("confirmations", confirmations); | result.pushKV("confirmations", confirmations); | ||||
result.push_back(Pair( | result.pushKV( | ||||
"size", (int)::GetSerializeSize(block, SER_NETWORK, 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); | ||||
TxToJSON(config, *tx, uint256(), objTx); | TxToJSON(config, *tx, uint256(), objTx); | ||||
txs.push_back(objTx); | txs.push_back(objTx); | ||||
} else { | } else { | ||||
txs.push_back(tx->GetId().GetHex()); | txs.push_back(tx->GetId().GetHex()); | ||||
} | } | ||||
} | } | ||||
result.pushKV("tx", txs); | result.pushKV("tx", txs); | ||||
result.pushKV("time", block.GetBlockTime()); | result.pushKV("time", block.GetBlockTime()); | ||||
result.push_back( | result.pushKV("mediantime", int64_t(blockindex->GetMedianTimePast())); | ||||
Pair("mediantime", int64_t(blockindex->GetMedianTimePast()))); | |||||
result.pushKV("nonce", uint64_t(block.nNonce)); | result.pushKV("nonce", uint64_t(block.nNonce)); | ||||
result.pushKV("bits", strprintf("%08x", block.nBits)); | result.pushKV("bits", strprintf("%08x", block.nBits)); | ||||
result.pushKV("difficulty", GetDifficulty(blockindex)); | result.pushKV("difficulty", GetDifficulty(blockindex)); | ||||
result.pushKV("chainwork", blockindex->nChainWork.GetHex()); | result.pushKV("chainwork", blockindex->nChainWork.GetHex()); | ||||
if (blockindex->pprev) { | if (blockindex->pprev) { | ||||
result.push_back(Pair("previousblockhash", | result.pushKV("previousblockhash", | ||||
blockindex->pprev->GetBlockHash().GetHex())); | blockindex->pprev->GetBlockHash().GetHex()); | ||||
} | } | ||||
CBlockIndex *pnext = chainActive.Next(blockindex); | CBlockIndex *pnext = chainActive.Next(blockindex); | ||||
if (pnext) { | if (pnext) { | ||||
result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) { | ||||
AssertLockHeld(mempool.cs); | AssertLockHeld(mempool.cs); | ||||
info.pushKV("size", (int)e.GetTxSize()); | info.pushKV("size", (int)e.GetTxSize()); | ||||
info.pushKV("fee", ValueFromAmount(e.GetFee())); | info.pushKV("fee", ValueFromAmount(e.GetFee())); | ||||
info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee())); | info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee())); | ||||
info.pushKV("time", e.GetTime()); | info.pushKV("time", e.GetTime()); | ||||
info.pushKV("height", (int)e.GetHeight()); | info.pushKV("height", (int)e.GetHeight()); | ||||
info.pushKV("startingpriority", e.GetPriority(e.GetHeight())); | info.pushKV("startingpriority", e.GetPriority(e.GetHeight())); | ||||
info.push_back( | info.pushKV("currentpriority", e.GetPriority(chainActive.Height())); | ||||
Pair("currentpriority", e.GetPriority(chainActive.Height()))); | |||||
info.pushKV("descendantcount", e.GetCountWithDescendants()); | info.pushKV("descendantcount", e.GetCountWithDescendants()); | ||||
info.pushKV("descendantsize", e.GetSizeWithDescendants()); | info.pushKV("descendantsize", e.GetSizeWithDescendants()); | ||||
info.push_back( | info.pushKV("descendantfees", e.GetModFeesWithDescendants() / SATOSHI); | ||||
Pair("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); | ||||
const CTransaction &tx = e.GetTx(); | const CTransaction &tx = e.GetTx(); | ||||
std::set<std::string> setDepends; | std::set<std::string> setDepends; | ||||
for (const CTxIn &txin : tx.vin) { | for (const CTxIn &txin : tx.vin) { | ||||
if (mempool.exists(txin.prevout.GetTxId())) { | if (mempool.exists(txin.prevout.GetTxId())) { | ||||
setDepends.insert(txin.prevout.GetTxId().ToString()); | setDepends.insert(txin.prevout.GetTxId().ToString()); | ||||
▲ Show 20 Lines • Show All 611 Lines • ▼ Show 20 Lines | UniValue gettxoutsetinfo(const Config &config, const JSONRPCRequest &request) { | ||||
if (GetUTXOStats(pcoinsdbview.get(), stats)) { | if (GetUTXOStats(pcoinsdbview.get(), stats)) { | ||||
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.push_back( | ret.pushKV("total_amount", ValueFromAmount(stats.nTotalAmount)); | ||||
Pair("total_amount", ValueFromAmount(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) { | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); | BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); | ||||
CBlockIndex *pindex = it->second; | CBlockIndex *pindex = it->second; | ||||
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.push_back(Pair("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", ValueFromAmount(coin.GetTxOut().nValue)); | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
ScriptPubKeyToJSON(config, coin.GetTxOut().scriptPubKey, o, true); | ScriptPubKeyToJSON(config, 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 57 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static UniValue SoftForkDesc(const std::string &name, int version, | static UniValue SoftForkDesc(const std::string &name, int version, | ||||
CBlockIndex *pindex, | CBlockIndex *pindex, | ||||
const Consensus::Params &consensusParams) { | const Consensus::Params &consensusParams) { | ||||
UniValue rv(UniValue::VOBJ); | UniValue rv(UniValue::VOBJ); | ||||
rv.pushKV("id", name); | rv.pushKV("id", name); | ||||
rv.pushKV("version", version); | rv.pushKV("version", version); | ||||
rv.push_back( | rv.pushKV("reject", SoftForkMajorityDesc(version, pindex, consensusParams)); | ||||
Pair("reject", SoftForkMajorityDesc(version, pindex, consensusParams))); | |||||
return rv; | return rv; | ||||
} | } | ||||
UniValue getblockchaininfo(const Config &config, | UniValue getblockchaininfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getblockchaininfo\n" | "getblockchaininfo\n" | ||||
Show All 38 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
HelpExampleRpc("getblockchaininfo", "")); | HelpExampleRpc("getblockchaininfo", "")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("chain", config.GetChainParams().NetworkIDString()); | obj.pushKV("chain", config.GetChainParams().NetworkIDString()); | ||||
obj.pushKV("blocks", int(chainActive.Height())); | obj.pushKV("blocks", int(chainActive.Height())); | ||||
obj.push_back( | obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1); | ||||
Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); | obj.pushKV("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()); | ||||
obj.push_back( | |||||
Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); | |||||
obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip()))); | obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip()))); | ||||
obj.push_back( | obj.pushKV("mediantime", int64_t(chainActive.Tip()->GetMedianTimePast())); | ||||
Pair("mediantime", int64_t(chainActive.Tip()->GetMedianTimePast()))); | obj.pushKV("verificationprogress", | ||||
obj.push_back( | |||||
Pair("verificationprogress", | |||||
GuessVerificationProgress(config.GetChainParams().TxData(), | GuessVerificationProgress(config.GetChainParams().TxData(), | ||||
chainActive.Tip()))); | chainActive.Tip())); | ||||
obj.pushKV("chainwork", chainActive.Tip()->nChainWork.GetHex()); | obj.pushKV("chainwork", chainActive.Tip()->nChainWork.GetHex()); | ||||
obj.pushKV("pruned", fPruneMode); | obj.pushKV("pruned", fPruneMode); | ||||
const Consensus::Params &consensusParams = | const Consensus::Params &consensusParams = | ||||
config.GetChainParams().GetConsensus(); | config.GetChainParams().GetConsensus(); | ||||
CBlockIndex *tip = chainActive.Tip(); | CBlockIndex *tip = chainActive.Tip(); | ||||
UniValue softforks(UniValue::VARR); | UniValue softforks(UniValue::VARR); | ||||
softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams)); | softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams)); | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | |||||
UniValue mempoolInfoToJSON() { | UniValue mempoolInfoToJSON() { | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("size", (int64_t)mempool.size()); | ret.pushKV("size", (int64_t)mempool.size()); | ||||
ret.pushKV("bytes", (int64_t)mempool.GetTotalTxSize()); | ret.pushKV("bytes", (int64_t)mempool.GetTotalTxSize()); | ||||
ret.pushKV("usage", (int64_t)mempool.DynamicMemoryUsage()); | ret.pushKV("usage", (int64_t)mempool.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.push_back( | ret.pushKV("mempoolminfee", | ||||
Pair("mempoolminfee", | ValueFromAmount(mempool.GetMinFee(maxmempool).GetFeePerK())); | ||||
ValueFromAmount(mempool.GetMinFee(maxmempool).GetFeePerK()))); | |||||
return ret; | return ret; | ||||
} | } | ||||
UniValue getmempoolinfo(const Config &config, const JSONRPCRequest &request) { | UniValue getmempoolinfo(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempoolinfo\n" | "getmempoolinfo\n" | ||||
▲ Show 20 Lines • Show All 398 Lines • Show Last 20 Lines |