Skip to content

Commit

Permalink
RPC clearmempool
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Dec 9, 2020
1 parent 329dff1 commit f51821b
Showing 1 changed file with 30 additions and 0 deletions.
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

0 comments on commit f51821b

Please sign in to comment.