diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-01-30 13:28:26 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-01-30 13:28:26 +0000 |
commit | bf6d1474c097ee0affe827fe2e3dac489b290f40 (patch) | |
tree | c662b2241380a793c64c2f1254de14cdf34339c8 /src/daemon | |
parent | rpc: add missing return on error when getting a tx (diff) | |
download | monero-bf6d1474c097ee0affe827fe2e3dac489b290f40.tar.xz |
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)
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/command_parser_executor.cpp | 18 | ||||
-rw-r--r-- | src/daemon/command_parser_executor.h | 2 | ||||
-rw-r--r-- | src/daemon/command_server.cpp | 5 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 30 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.h | 2 |
5 files changed, 57 insertions, 0 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index d1d48b6da..0b42257e7 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -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 diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h index 2d9315df8..51c55a8c0 100644 --- a/src/daemon/command_parser_executor.h +++ b/src/daemon/command_parser_executor.h @@ -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 diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp index f99b0844a..206de9d4a 100644 --- a/src/daemon/command_server.cpp +++ b/src/daemon/command_server.cpp @@ -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) diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 6809f68b9..1ab1c8ed8 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -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 diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index 9589dff64..bc3f2d5c5 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -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 |