new flush_txpool command, and associated RPC call

It can flush a particular tx, or the whole pool (the RPC command
can flush a list of transactions too)
This commit is contained in:
moneromooo-monero
2016-01-30 13:28:26 +00:00
parent 6288295f8e
commit bf6d1474c0
12 changed files with 175 additions and 0 deletions
+18
View File
@@ -421,5 +421,23 @@ bool t_command_parser_executor::unban(const std::vector<std::string>& args)
return m_executor.unban(ip);
}
bool t_command_parser_executor::flush_txpool(const std::vector<std::string>& args)
{
if (args.size() > 1) return false;
std::string txid;
if (args.size() == 1)
{
crypto::hash hash;
if (!parse_hash256(args[0], hash))
{
std::cout << "failed to parse tx id" << std::endl;
return true;
}
txid = args[0];
}
return m_executor.flush_txpool(txid);
}
} // namespace daemonize
+2
View File
@@ -112,6 +112,8 @@ public:
bool ban(const std::vector<std::string>& args);
bool unban(const std::vector<std::string>& args);
bool flush_txpool(const std::vector<std::string>& args);
};
} // namespace daemonize
+5
View File
@@ -209,6 +209,11 @@ t_command_server::t_command_server(
, std::bind(&t_command_parser_executor::unban, &m_parser, p::_1)
, "Unban a given IP"
);
m_command_lookup.set_handler(
"flush_txpool"
, std::bind(&t_command_parser_executor::flush_txpool, &m_parser, p::_1)
, "Flush a transaction from the tx pool by its txid, or the whole tx pool"
);
}
bool t_command_server::process_command_str(const std::string& cmd)
+30
View File
@@ -1161,4 +1161,34 @@ bool t_rpc_command_executor::unban(const std::string &ip)
return true;
}
bool t_rpc_command_executor::flush_txpool(const std::string &txid)
{
cryptonote::COMMAND_RPC_FLUSH_TRANSACTION_POOL::request req;
cryptonote::COMMAND_RPC_FLUSH_TRANSACTION_POOL::response res;
std::string fail_message = "Unsuccessful";
epee::json_rpc::error error_resp;
if (!txid.empty())
req.txids.push_back(txid);
if (m_is_rpc)
{
if (!m_rpc_client->json_rpc_request(req, res, "flush_txpool", fail_message.c_str()))
{
return true;
}
}
else
{
if (!m_rpc_server->on_flush_txpool(req, res, error_resp))
{
tools::fail_msg_writer() << fail_message.c_str();
return true;
}
}
return true;
}
}// namespace daemonize
+2
View File
@@ -130,6 +130,8 @@ public:
bool ban(const std::string &ip, time_t seconds);
bool unban(const std::string &ip);
bool flush_txpool(const std::string &txid);
};
} // namespace daemonize