Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 589 Lines • ▼ Show 20 Lines | static UniValue getrawmempool(const Config &config, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
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(::g_mempool, fVerbose); | return MempoolToJSON(EnsureMemPool(), fVerbose); | ||||
} | } | ||||
static UniValue getmempoolancestors(const Config &config, | static UniValue getmempoolancestors(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getmempoolancestors", | "getmempoolancestors", | ||||
"If txid is in the mempool, returns all in-mempool ancestors.\n", | "If txid is in the mempool, returns all in-mempool ancestors.\n", | ||||
{ | { | ||||
Show All 23 Lines | static UniValue getmempoolancestors(const Config &config, | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
TxId txid(ParseHashV(request.params[0], "parameter 1")); | TxId txid(ParseHashV(request.params[0], "parameter 1")); | ||||
LOCK(g_mempool.cs); | const CTxMemPool &mempool = EnsureMemPool(); | ||||
LOCK(mempool.cs); | |||||
CTxMemPool::txiter it = g_mempool.mapTx.find(txid); | CTxMemPool::txiter it = mempool.mapTx.find(txid); | ||||
if (it == g_mempool.mapTx.end()) { | if (it == 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; | ||||
g_mempool.CalculateMemPoolAncestors(*it, setAncestors, noLimit, noLimit, | 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; | ||||
} 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 TxId &_txid = e.GetTx().GetId(); | const TxId &_txid = e.GetTx().GetId(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(::g_mempool, info, e); | entryToJSON(mempool, info, e); | ||||
o.pushKV(_txid.ToString(), info); | o.pushKV(_txid.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 All 27 Lines | static UniValue getmempooldescendants(const Config &config, | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
TxId txid(ParseHashV(request.params[0], "parameter 1")); | TxId txid(ParseHashV(request.params[0], "parameter 1")); | ||||
LOCK(g_mempool.cs); | const CTxMemPool &mempool = EnsureMemPool(); | ||||
LOCK(mempool.cs); | |||||
CTxMemPool::txiter it = g_mempool.mapTx.find(txid); | CTxMemPool::txiter it = mempool.mapTx.find(txid); | ||||
if (it == g_mempool.mapTx.end()) { | if (it == 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; | ||||
g_mempool.CalculateDescendants(it, setDescendants); | 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()); | ||||
} | } | ||||
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 TxId &_txid = e.GetTx().GetId(); | const TxId &_txid = e.GetTx().GetId(); | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(::g_mempool, info, e); | entryToJSON(mempool, info, e); | ||||
o.pushKV(_txid.ToString(), info); | o.pushKV(_txid.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
static UniValue getmempoolentry(const Config &config, | static UniValue getmempoolentry(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getmempoolentry", | "getmempoolentry", | ||||
"Returns mempool data for given transaction\n", | "Returns mempool data for given transaction\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | ||||
"The transaction id (must be in mempool)"}, | "The transaction id (must be in mempool)"}, | ||||
}, | }, | ||||
RPCResult{"{ (json object)\n" + | RPCResult{"{ (json object)\n" + | ||||
EntryDescriptionString() + "}\n"}, | EntryDescriptionString() + "}\n"}, | ||||
RPCExamples{HelpExampleCli("getmempoolentry", "\"mytxid\"") + | RPCExamples{HelpExampleCli("getmempoolentry", "\"mytxid\"") + | ||||
HelpExampleRpc("getmempoolentry", "\"mytxid\"")}, | HelpExampleRpc("getmempoolentry", "\"mytxid\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
TxId txid(ParseHashV(request.params[0], "parameter 1")); | TxId txid(ParseHashV(request.params[0], "parameter 1")); | ||||
LOCK(g_mempool.cs); | const CTxMemPool &mempool = EnsureMemPool(); | ||||
LOCK(mempool.cs); | |||||
CTxMemPool::txiter it = g_mempool.mapTx.find(txid); | CTxMemPool::txiter it = mempool.mapTx.find(txid); | ||||
if (it == g_mempool.mapTx.end()) { | if (it == 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(::g_mempool, info, e); | entryToJSON(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) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getblockhash", | "getblockhash", | ||||
"Returns hash of block in best-block-chain at height provided.\n", | "Returns hash of block in best-block-chain at height provided.\n", | ||||
▲ Show 20 Lines • Show All 432 Lines • ▼ Show 20 Lines | UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | ||||
if (!request.params[2].isNull()) { | if (!request.params[2].isNull()) { | ||||
fMempool = request.params[2].get_bool(); | fMempool = request.params[2].get_bool(); | ||||
} | } | ||||
Coin coin; | Coin coin; | ||||
CCoinsViewCache *coins_view = &::ChainstateActive().CoinsTip(); | CCoinsViewCache *coins_view = &::ChainstateActive().CoinsTip(); | ||||
if (fMempool) { | if (fMempool) { | ||||
LOCK(g_mempool.cs); | const CTxMemPool &mempool = EnsureMemPool(); | ||||
CCoinsViewMemPool view(coins_view, g_mempool); | LOCK(mempool.cs); | ||||
if (!view.GetCoin(out, coin) || g_mempool.isSpent(out)) { | CCoinsViewMemPool view(coins_view, mempool); | ||||
if (!view.GetCoin(out, coin) || mempool.isSpent(out)) { | |||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
} else { | } else { | ||||
if (!coins_view->GetCoin(out, coin)) { | if (!coins_view->GetCoin(out, coin)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 418 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
" \"minrelaytxfee\": xxxxx (numeric) Current minimum relay " | " \"minrelaytxfee\": xxxxx (numeric) Current minimum relay " | ||||
"fee for transactions\n" | "fee for transactions\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("getmempoolinfo", "") + | RPCExamples{HelpExampleCli("getmempoolinfo", "") + | ||||
HelpExampleRpc("getmempoolinfo", "")}, | HelpExampleRpc("getmempoolinfo", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
return MempoolInfoToJSON(::g_mempool); | return MempoolInfoToJSON(EnsureMemPool()); | ||||
} | } | ||||
static UniValue preciousblock(const Config &config, | static UniValue preciousblock(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"preciousblock", | "preciousblock", | ||||
"Treats a block as if it were received before others with the same " | "Treats a block as if it were received before others with the same " | ||||
"work.\n" | "work.\n" | ||||
▲ Show 20 Lines • Show All 649 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"fully loaded.\n", | "fully loaded.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("savemempool", "") + | RPCExamples{HelpExampleCli("savemempool", "") + | ||||
HelpExampleRpc("savemempool", "")}, | HelpExampleRpc("savemempool", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!::g_mempool.IsLoaded()) { | const CTxMemPool &mempool = EnsureMemPool(); | ||||
if (!mempool.IsLoaded()) { | |||||
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet"); | throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet"); | ||||
} | } | ||||
if (!DumpMempool(::g_mempool)) { | if (!DumpMempool(mempool)) { | ||||
throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk"); | throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
//! Search for a given set of pubkey scripts | //! Search for a given set of pubkey scripts | ||||
static bool FindScriptPubKey(std::atomic<int> &scan_progress, | static bool FindScriptPubKey(std::atomic<int> &scan_progress, | ||||
▲ Show 20 Lines • Show All 491 Lines • Show Last 20 Lines |