Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | return " \"size\" : n, (numeric) transaction size.\n" | ||||
"of in-mempool ancestors (including this one)\n" | "of in-mempool ancestors (including this one)\n" | ||||
" \"depends\" : [ (array) unconfirmed transactions " | " \"depends\" : [ (array) unconfirmed transactions " | ||||
"used as inputs for this transaction\n" | "used as inputs for this transaction\n" | ||||
" \"transactionid\", (string) parent transaction id\n" | " \"transactionid\", (string) parent transaction id\n" | ||||
" ... ]\n"; | " ... ]\n"; | ||||
} | } | ||||
void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) { | void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) { | ||||
AssertLockHeld(mempool.cs); | AssertLockHeld(g_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.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 (mempool.exists(txin.prevout.GetTxId())) { | if (g_mempool.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 mempoolToJSON(bool fVerbose = false) { | UniValue mempoolToJSON(bool fVerbose = false) { | ||||
if (fVerbose) { | if (fVerbose) { | ||||
LOCK(mempool.cs); | LOCK(g_mempool.cs); | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
for (const CTxMemPoolEntry &e : mempool.mapTx) { | for (const CTxMemPoolEntry &e : g_mempool.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(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; | ||||
mempool.queryHashes(vtxids); | g_mempool.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 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | UniValue getmempoolancestors(const Config &config, | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (request.params.size() > 1) { | if (request.params.size() > 1) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | uint256 hash = ParseHashV(request.params[0], "parameter 1"); | ||||
LOCK(mempool.cs); | LOCK(g_mempool.cs); | ||||
CTxMemPool::txiter it = mempool.mapTx.find(hash); | CTxMemPool::txiter it = g_mempool.mapTx.find(hash); | ||||
if (it == 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"); | ||||
} | } | ||||
CTxMemPool::setEntries setAncestors; | CTxMemPool::setEntries setAncestors; | ||||
uint64_t noLimit = std::numeric_limits<uint64_t>::max(); | uint64_t noLimit = std::numeric_limits<uint64_t>::max(); | ||||
std::string dummy; | std::string dummy; | ||||
mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, | g_mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, | ||||
noLimit, noLimit, dummy, false); | noLimit, noLimit, dummy, false); | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
UniValue o(UniValue::VARR); | UniValue o(UniValue::VARR); | ||||
for (CTxMemPool::txiter ancestorIt : setAncestors) { | for (CTxMemPool::txiter ancestorIt : setAncestors) { | ||||
o.push_back(ancestorIt->GetTx().GetId().ToString()); | o.push_back(ancestorIt->GetTx().GetId().ToString()); | ||||
} | } | ||||
return o; | return o; | ||||
Show All 38 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
HelpExampleRpc("getmempooldescendants", "\"mytxid\"")); | HelpExampleRpc("getmempooldescendants", "\"mytxid\"")); | ||||
} | } | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (request.params.size() > 1) fVerbose = request.params[1].get_bool(); | if (request.params.size() > 1) fVerbose = request.params[1].get_bool(); | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | uint256 hash = ParseHashV(request.params[0], "parameter 1"); | ||||
LOCK(mempool.cs); | LOCK(g_mempool.cs); | ||||
CTxMemPool::txiter it = mempool.mapTx.find(hash); | CTxMemPool::txiter it = g_mempool.mapTx.find(hash); | ||||
if (it == 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"); | ||||
} | } | ||||
CTxMemPool::setEntries setDescendants; | CTxMemPool::setEntries setDescendants; | ||||
mempool.CalculateDescendants(it, setDescendants); | g_mempool.CalculateDescendants(it, setDescendants); | ||||
// CTxMemPool::CalculateDescendants will include the given tx | // CTxMemPool::CalculateDescendants will include the given tx | ||||
setDescendants.erase(it); | setDescendants.erase(it); | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
UniValue o(UniValue::VARR); | UniValue o(UniValue::VARR); | ||||
for (CTxMemPool::txiter descendantIt : setDescendants) { | for (CTxMemPool::txiter descendantIt : setDescendants) { | ||||
o.push_back(descendantIt->GetTx().GetId().ToString()); | o.push_back(descendantIt->GetTx().GetId().ToString()); | ||||
} | } | ||||
Show All 25 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
EntryDescriptionString() + "}\n" | EntryDescriptionString() + "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getmempoolentry", "\"mytxid\"") + | HelpExampleCli("getmempoolentry", "\"mytxid\"") + | ||||
HelpExampleRpc("getmempoolentry", "\"mytxid\"")); | HelpExampleRpc("getmempoolentry", "\"mytxid\"")); | ||||
} | } | ||||
uint256 hash = ParseHashV(request.params[0], "parameter 1"); | uint256 hash = ParseHashV(request.params[0], "parameter 1"); | ||||
LOCK(mempool.cs); | LOCK(g_mempool.cs); | ||||
CTxMemPool::txiter it = mempool.mapTx.find(hash); | CTxMemPool::txiter it = g_mempool.mapTx.find(hash); | ||||
if (it == 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(info, e); | ||||
return info; | return info; | ||||
▲ Show 20 Lines • Show All 446 Lines • ▼ Show 20 Lines | UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | ||||
COutPoint out(hash, n); | COutPoint out(hash, n); | ||||
bool fMempool = true; | bool fMempool = true; | ||||
if (request.params.size() > 2) { | if (request.params.size() > 2) { | ||||
fMempool = request.params[2].get_bool(); | fMempool = request.params[2].get_bool(); | ||||
} | } | ||||
Coin coin; | Coin coin; | ||||
if (fMempool) { | if (fMempool) { | ||||
LOCK(mempool.cs); | LOCK(g_mempool.cs); | ||||
CCoinsViewMemPool view(pcoinsTip.get(), mempool); | CCoinsViewMemPool view(pcoinsTip.get(), g_mempool); | ||||
if (!view.GetCoin(out, coin) || mempool.isSpent(out)) { | if (!view.GetCoin(out, coin) || g_mempool.isSpent(out)) { | ||||
// TODO: this should be done by the CCoinsViewMemPool | // TODO: this should be done by the CCoinsViewMemPool | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
} else { | } else { | ||||
if (!pcoinsTip->GetCoin(out, coin)) { | if (!pcoinsTip->GetCoin(out, coin)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | for (const CBlockIndex *block : setTips) { | ||||
res.push_back(obj); | res.push_back(obj); | ||||
} | } | ||||
return res; | return res; | ||||
} | } | ||||
UniValue mempoolInfoToJSON() { | UniValue mempoolInfoToJSON() { | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("size", (int64_t)mempool.size()); | ret.pushKV("size", (int64_t)g_mempool.size()); | ||||
ret.pushKV("bytes", (int64_t)mempool.GetTotalTxSize()); | ret.pushKV("bytes", (int64_t)g_mempool.GetTotalTxSize()); | ||||
ret.pushKV("usage", (int64_t)mempool.DynamicMemoryUsage()); | ret.pushKV("usage", (int64_t)g_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.pushKV("mempoolminfee", | ret.pushKV("mempoolminfee", | ||||
ValueFromAmount(mempool.GetMinFee(maxmempool).GetFeePerK())); | ValueFromAmount(g_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 399 Lines • Show Last 20 Lines |