Skip to content

Commit

Permalink
Merge pull request #133 from DeFiCh/rpc-clearmempool
Browse files Browse the repository at this point in the history
RPC clearmempool
  • Loading branch information
monstrobishi authored Dec 10, 2020
2 parents 329dff1 + f51821b commit aa55d2b
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 aa55d2b

Please sign in to comment.