Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 451 Lines • ▼ Show 20 Lines | return " \"size\" : n, (numeric) transaction size.\n" | ||||
" \"transactionid\", (string) parent transaction id\n" | " \"transactionid\", (string) parent transaction id\n" | ||||
" ... ]\n" | " ... ]\n" | ||||
" \"spentby\" : [ (array) unconfirmed transactions " | " \"spentby\" : [ (array) unconfirmed transactions " | ||||
"spending outputs from this transaction\n" | "spending outputs from this transaction\n" | ||||
" \"transactionid\", (string) child transaction id\n" | " \"transactionid\", (string) child transaction id\n" | ||||
" ... ]\n"; | " ... ]\n"; | ||||
} | } | ||||
static void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) | static void entryToJSON(const CTxMemPool &pool, UniValue &info, | ||||
EXCLUSIVE_LOCKS_REQUIRED(g_mempool.cs) { | const CTxMemPoolEntry &e) | ||||
AssertLockHeld(g_mempool.cs); | EXCLUSIVE_LOCKS_REQUIRED(pool.cs) { | ||||
AssertLockHeld(pool.cs); | |||||
UniValue fees(UniValue::VOBJ); | UniValue fees(UniValue::VOBJ); | ||||
fees.pushKV("base", ValueFromAmount(e.GetFee())); | fees.pushKV("base", ValueFromAmount(e.GetFee())); | ||||
fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee())); | fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee())); | ||||
fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors())); | fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors())); | ||||
fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants())); | fees.pushKV("descendant", ValueFromAmount(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", 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.pushKV("currentpriority", e.GetPriority(chainActive.Height())); | info.pushKV("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.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); | ||||
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 (g_mempool.exists(txin.prevout.GetTxId())) { | if (pool.exists(txin.prevout.GetTxId())) { | ||||
setDepends.insert(txin.prevout.GetTxId().ToString()); | setDepends.insert(txin.prevout.GetTxId().ToString()); | ||||
} | } | ||||
} | } | ||||
UniValue depends(UniValue::VARR); | UniValue depends(UniValue::VARR); | ||||
for (const std::string &dep : setDepends) { | for (const std::string &dep : setDepends) { | ||||
depends.push_back(dep); | depends.push_back(dep); | ||||
} | } | ||||
info.pushKV("depends", depends); | info.pushKV("depends", depends); | ||||
UniValue spent(UniValue::VARR); | UniValue spent(UniValue::VARR); | ||||
const CTxMemPool::txiter &it = g_mempool.mapTx.find(tx.GetId()); | const CTxMemPool::txiter &it = pool.mapTx.find(tx.GetId()); | ||||
const CTxMemPool::setEntries &setChildren = | const CTxMemPool::setEntries &setChildren = pool.GetMemPoolChildren(it); | ||||
g_mempool.GetMemPoolChildren(it); | |||||
for (CTxMemPool::txiter childiter : setChildren) { | for (CTxMemPool::txiter childiter : setChildren) { | ||||
spent.push_back(childiter->GetTx().GetId().ToString()); | spent.push_back(childiter->GetTx().GetId().ToString()); | ||||
} | } | ||||
info.pushKV("spentby", spent); | info.pushKV("spentby", spent); | ||||
} | } | ||||
UniValue mempoolToJSON(bool fVerbose) { | UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose) { | ||||
if (fVerbose) { | if (verbose) { | ||||
LOCK(g_mempool.cs); | LOCK(pool.cs); | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (const CTxMemPoolEntry &e : g_mempool.mapTx) { | for (const CTxMemPoolEntry &e : pool.mapTx) { | ||||
const uint256 &txid = e.GetTx().GetId(); | const uint256 &txid = e.GetTx().GetId(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(pool, info, e); | ||||
o.pushKV(txid.ToString(), info); | o.pushKV(txid.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} else { | } else { | ||||
std::vector<uint256> vtxids; | std::vector<uint256> vtxids; | ||||
g_mempool.queryHashes(vtxids); | pool.queryHashes(vtxids); | ||||
UniValue a(UniValue::VARR); | UniValue a(UniValue::VARR); | ||||
for (const uint256 &txid : vtxids) { | for (const uint256 &txid : vtxids) { | ||||
a.push_back(txid.ToString()); | a.push_back(txid.ToString()); | ||||
} | } | ||||
return a; | return a; | ||||
} | } | ||||
Show All 27 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
HelpExampleRpc("getrawmempool", "true")); | HelpExampleRpc("getrawmempool", "true")); | ||||
} | } | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
fVerbose = request.params[0].get_bool(); | fVerbose = request.params[0].get_bool(); | ||||
} | } | ||||
return mempoolToJSON(fVerbose); | return MempoolToJSON(::g_mempool, fVerbose); | ||||
} | } | ||||
static UniValue getmempoolancestors(const Config &config, | static UniValue getmempoolancestors(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempoolancestors txid (verbose)\n" | "getmempoolancestors txid (verbose)\n" | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if (!fVerbose) { | ||||
return o; | return o; | ||||
} else { | } else { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (CTxMemPool::txiter ancestorIt : setAncestors) { | for (CTxMemPool::txiter ancestorIt : setAncestors) { | ||||
const CTxMemPoolEntry &e = *ancestorIt; | const CTxMemPoolEntry &e = *ancestorIt; | ||||
const uint256 &_hash = e.GetTx().GetId(); | const uint256 &_hash = e.GetTx().GetId(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(::g_mempool, info, e); | ||||
o.pushKV(_hash.ToString(), info); | o.pushKV(_hash.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
static UniValue getmempooldescendants(const Config &config, | static UniValue getmempooldescendants(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | if (!fVerbose) { | ||||
return o; | return o; | ||||
} else { | } else { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (CTxMemPool::txiter descendantIt : setDescendants) { | for (CTxMemPool::txiter descendantIt : setDescendants) { | ||||
const CTxMemPoolEntry &e = *descendantIt; | const CTxMemPoolEntry &e = *descendantIt; | ||||
const uint256 &_hash = e.GetTx().GetId(); | const uint256 &_hash = e.GetTx().GetId(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(::g_mempool, info, e); | ||||
o.pushKV(_hash.ToString(), info); | o.pushKV(_hash.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
static UniValue getmempoolentry(const Config &config, | static UniValue getmempoolentry(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
Show All 20 Lines | static UniValue getmempoolentry(const Config &config, | ||||
CTxMemPool::txiter it = g_mempool.mapTx.find(hash); | CTxMemPool::txiter it = g_mempool.mapTx.find(hash); | ||||
if (it == g_mempool.mapTx.end()) { | if (it == g_mempool.mapTx.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not in mempool"); | "Transaction not in mempool"); | ||||
} | } | ||||
const CTxMemPoolEntry &e = *it; | const CTxMemPoolEntry &e = *it; | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(::g_mempool, info, e); | ||||
return info; | return info; | ||||
} | } | ||||
static UniValue getblockhash(const Config &config, | static UniValue getblockhash(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getblockhash height\n" | "getblockhash height\n" | ||||
▲ Show 20 Lines • Show All 732 Lines • ▼ Show 20 Lines | for (const CBlockIndex *block : setTips) { | ||||
obj.pushKV("status", status); | obj.pushKV("status", status); | ||||
res.push_back(obj); | res.push_back(obj); | ||||
} | } | ||||
return res; | return res; | ||||
} | } | ||||
UniValue mempoolInfoToJSON() { | UniValue MempoolInfoToJSON(const CTxMemPool &pool) { | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("size", (int64_t)g_mempool.size()); | ret.pushKV("size", (int64_t)pool.size()); | ||||
ret.pushKV("bytes", (int64_t)g_mempool.GetTotalTxSize()); | ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize()); | ||||
ret.pushKV("usage", (int64_t)g_mempool.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("mempoolminfee", | ret.pushKV( | ||||
ValueFromAmount( | "mempoolminfee", | ||||
std::max(g_mempool.GetMinFee(maxmempool), ::minRelayTxFee) | ValueFromAmount(std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee) | ||||
.GetFeePerK())); | .GetFeePerK())); | ||||
ret.pushKV("minrelaytxfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); | ret.pushKV("minrelaytxfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue getmempoolinfo(const Config &config, | static UniValue getmempoolinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
Show All 15 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
" \"minrelaytxfee\": xxxxx (numeric) Current minimum relay " | " \"minrelaytxfee\": xxxxx (numeric) Current minimum relay " | ||||
"fee for transactions\n" | "fee for transactions\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getmempoolinfo", "") + | HelpExampleCli("getmempoolinfo", "") + | ||||
HelpExampleRpc("getmempoolinfo", "")); | HelpExampleRpc("getmempoolinfo", "")); | ||||
} | } | ||||
return mempoolInfoToJSON(); | return MempoolInfoToJSON(::g_mempool); | ||||
} | } | ||||
static UniValue preciousblock(const Config &config, | static UniValue preciousblock(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"preciousblock \"blockhash\"\n" | "preciousblock \"blockhash\"\n" | ||||
"\nTreats a block as if it were received before others with the " | "\nTreats a block as if it were received before others with the " | ||||
▲ Show 20 Lines • Show All 716 Lines • Show Last 20 Lines |