Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC clearmempool #133

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,35 @@ static UniValue getrawmempool(const JSONRPCRequest& request)
return MempoolToJSON(::mempool, fVerbose);
}

static UniValue clearmempool(const JSONRPCRequest& request)
{
RPCHelpMan("clearmempool",
"\nClears the memory pool and returns a list of the removed transactions.\n",
{},
RPCResult{
"[ (json array of string)\n"
" \"hash\" (string) The transaction hash\n"
" ,...\n"
"]\n"
},
RPCExamples{
HelpExampleCli("clearmempool", "")
+ HelpExampleRpc("clearmempool", "")
}
).Check(request);

std::vector<uint256> vtxid;
mempool.queryHashes(vtxid);

UniValue removed(UniValue::VARR);
for (const uint256& hash : vtxid)
removed.push_back(hash.ToString());

mempool.clear();

return removed;
}

static UniValue getmempoolancestors(const JSONRPCRequest& request)
{
RPCHelpMan{"getmempoolancestors",
Expand Down Expand Up @@ -2263,6 +2292,7 @@ static const CRPCCommand commands[] =
{ "blockchain", "getmempooldescendants", &getmempooldescendants, {"txid","verbose"} },
{ "blockchain", "getmempoolentry", &getmempoolentry, {"txid"} },
{ "blockchain", "getmempoolinfo", &getmempoolinfo, {} },
{ "blockchain", "clearmempool", &clearmempool, {} },
{ "blockchain", "getrawmempool", &getrawmempool, {"verbose"} },
{ "blockchain", "gettxout", &gettxout, {"txid","n","include_mempool"} },
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, {} },
Expand Down