Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
751RPCExamples{752HelpExampleCli("getrawmempool", "true")753+ HelpExampleRpc("getrawmempool", "true")754},755[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue756{757bool fVerbose = false;758if (!request.params[0].isNull())759fVerbose = request.params[0].get_bool();761bool include_mempool_sequence = false;762if (!request.params[1].isNull()) {763include_mempool_sequence = request.params[1].get_bool();764}766return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);767},768};769}771static RPCMethod getmempoolancestors()772{773return RPCMethod{774"getmempoolancestors",775"If txid is in the mempool, returns all in-mempool ancestors.\n",776{777{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},778{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},779},780{781RPCResult{"for verbose = false",782RPCResult::Type::ARR, "", "",783{{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool ancestor transaction"}}},784RPCResult{"for verbose = true",785RPCResult::Type::OBJ_DYN, "", "",786{787{RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},788}},789},790RPCExamples{791HelpExampleCli("getmempoolancestors", "\"mytxid\"")792+ HelpExampleRpc("getmempoolancestors", "\"mytxid\"")793},794[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue795{796bool fVerbose = false;797if (!request.params[1].isNull())798fVerbose = request.params[1].get_bool();800auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};802const CTxMemPool& mempool = EnsureAnyMemPool(request.context);803LOCK(mempool.cs);805const auto entry{mempool.GetEntry(txid)};806if (entry == nullptr) {807throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");808}810auto ancestors{mempool.CalculateMemPoolAncestors(*entry)};812if (!fVerbose) {813UniValue o(UniValue::VARR);814for (CTxMemPool::txiter ancestorIt : ancestors) {815o.push_back(ancestorIt->GetTx().GetHash().ToString());816}817return o;818} else {819UniValue o(UniValue::VOBJ);820for (CTxMemPool::txiter ancestorIt : ancestors) {821const CTxMemPoolEntry &e = *ancestorIt;822UniValue info(UniValue::VOBJ);823entryToJSON(mempool, info, e);824o.pushKVEnd(e.GetTx().GetHash().ToString(), std::move(info));825}826return o;827}828},829};830}832static RPCMethod getmempooldescendants()833{834return RPCMethod{835"getmempooldescendants",836"If txid is in the mempool, returns all in-mempool descendants.\n",837{838{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},839{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},840},841{842RPCResult{"for verbose = false",843RPCResult::Type::ARR, "", "",844{{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool descendant transaction"}}},845RPCResult{"for verbose = true",846RPCResult::Type::OBJ_DYN, "", "",847{848{RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},849}},850},851RPCExamples{852HelpExampleCli("getmempooldescendants", "\"mytxid\"")853+ HelpExampleRpc("getmempooldescendants", "\"mytxid\"")854},855[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue856{857bool fVerbose = false;858if (!request.params[1].isNull())859fVerbose = request.params[1].get_bool();861auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};863const CTxMemPool& mempool = EnsureAnyMemPool(request.context);864LOCK(mempool.cs);866const auto it{mempool.GetIter(txid)};867if (!it) {868throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");869}871CTxMemPool::setEntries setDescendants;872mempool.CalculateDescendants(*it, setDescendants);873// CTxMemPool::CalculateDescendants will include the given tx874setDescendants.erase(*it);876if (!fVerbose) {877UniValue o(UniValue::VARR);878for (CTxMemPool::txiter descendantIt : setDescendants) {879o.push_back(descendantIt->GetTx().GetHash().ToString());880}882return o;883} else {884UniValue o(UniValue::VOBJ);885for (CTxMemPool::txiter descendantIt : setDescendants) {886const CTxMemPoolEntry &e = *descendantIt;887UniValue info(UniValue::VOBJ);888entryToJSON(mempool, info, e);889o.pushKVEnd(e.GetTx().GetHash().ToString(), std::move(info));890}891return o;892}893},894};895}897static RPCMethod getmempoolcluster()898{899return RPCMethod{"getmempoolcluster",900"Returns mempool data for given cluster\n",901{902{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The txid of a transaction in the cluster"},903},904RPCResult{905RPCResult::Type::OBJ, "", "", ClusterDescription()},906RPCExamples{907HelpExampleCli("getmempoolcluster", "txid")908+ HelpExampleRpc("getmempoolcluster", R"("txid")")909},910[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue911{912uint256 hash = ParseHashV(request.params[0], "txid");914const CTxMemPool& mempool = EnsureAnyMemPool(request.context);915LOCK(mempool.cs);917auto txid = Txid::FromUint256(hash);918const auto entry{mempool.GetEntry(txid)};919if (entry == nullptr) {920throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");921}923auto cluster = mempool.GetCluster(txid);925UniValue info(UniValue::VOBJ);926clusterToJSON(mempool, info, cluster);927return info;928},929};930}932static RPCMethod getmempoolentry()933{934return RPCMethod{935"getmempoolentry",936"Returns mempool data for given transaction\n",937{938{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},939},940RPCResult{941RPCResult::Type::OBJ, "", "", MempoolEntryDescription()},942RPCExamples{943HelpExampleCli("getmempoolentry", "\"mytxid\"")944+ HelpExampleRpc("getmempoolentry", "\"mytxid\"")945},946[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue947{948auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};950const CTxMemPool& mempool = EnsureAnyMemPool(request.context);951LOCK(mempool.cs);953const auto entry{mempool.GetEntry(txid)};954if (entry == nullptr) {955throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");956}958UniValue info(UniValue::VOBJ);959entryToJSON(mempool, info, *entry);960return info;961},962};963}965static RPCMethod gettxspendingprevout()966{967return RPCMethod{"gettxspendingprevout",968"Scans the mempool (and the txospenderindex, if available) to find transactions spending any of the given outputs",969{970{"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The transaction outputs that we want to check, and within each, the txid (string) vout (numeric).",971{972{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",973{974{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},975{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},976},977},978},979},980{"options", RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "",981{982{"mempool_only", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true if txospenderindex unavailable, otherwise false"}, "If false and mempool lacks a relevant spend, use txospenderindex (throws an exception if not available)."},983{"return_spending_tx", RPCArg::Type::BOOL, RPCArg::DefaultHint{"false"}, "If true, return the full spending tx."},984},985},986},987RPCResult{988RPCResult::Type::ARR, "", "",989{990{RPCResult::Type::OBJ, "", "",991{992{RPCResult::Type::STR_HEX, "txid", "the transaction id of the checked output"},993{RPCResult::Type::NUM, "vout", "the vout value of the checked output"},994{RPCResult::Type::STR_HEX, "spendingtxid", /*optional=*/true, "the transaction id of the mempool transaction spending this output (omitted if unspent)"},995{RPCResult::Type::STR_HEX, "spendingtx", /*optional=*/true, "the transaction spending this output (only if return_spending_tx is set, omitted if unspent)"},996{RPCResult::Type::STR_HEX, "blockhash", /*optional=*/true, "the hash of the spending block (omitted if unspent or the spending tx is not confirmed)"},997}},998}999},1000RPCExamples{