Don't couple the cancelling wallet code with console_handler

This commit is contained in:
Doyle 2020-05-21 10:21:05 +10:00
parent 6a357fa499
commit c7cf2935a3
3 changed files with 5 additions and 29 deletions

View file

@ -298,16 +298,10 @@ eof:
{
}
template<class t_server, class chain_handler>
bool run(t_server* psrv, chain_handler ch_handler, std::function<std::string(void)> prompt, const std::string& usage = "")
{
return run(prompt, usage, [&](const std::string& cmd) { return ch_handler(psrv, cmd); }, [&] { psrv->send_stop_signal(); });
}
template<class chain_handler>
bool run(chain_handler ch_handler, std::function<std::string(void)> prompt, const std::string& usage = "", std::function<void(void)> exit_handler = NULL)
{
return run(prompt, usage, [&](const boost::optional<std::string>& cmd) { return ch_handler(cmd); }, exit_handler);
return run(prompt, usage, [&](const std::string& cmd) { return ch_handler(cmd); }, exit_handler);
}
void stop()
@ -374,7 +368,6 @@ eof:
if (m_cancel)
{
MDEBUG("Input cancelled");
cmd_handler(boost::none);
m_cancel = false;
continue;
}
@ -419,7 +412,6 @@ eof:
class command_handler {
public:
typedef std::function<bool(const std::vector<std::string> &)> callback;
typedef boost::function<bool (void)> empty_callback;
typedef std::map<std::string, std::pair<callback, std::pair<std::string, std::string>>> lookup;
/// Go through registered commands in sorted order, call the function with three string
@ -492,23 +484,15 @@ eof:
return false;
}
bool process_command_and_log(const boost::optional<std::string>& cmd)
bool process_command_and_log(const std::string& cmd)
{
if (!cmd)
return m_cancel_handler();
std::vector<std::string> cmd_v;
boost::split(cmd_v,*cmd,boost::is_any_of(" "), boost::token_compress_on);
boost::split(cmd_v, cmd, boost::is_any_of(" "), boost::token_compress_on);
return process_command_and_log(cmd_v);
}
void set_cancel_handler(const empty_callback& hndlr)
{
m_cancel_handler = hndlr;
}
private:
lookup m_command_handlers;
empty_callback m_cancel_handler;
};
/************************************************************************/

View file

@ -2146,12 +2146,6 @@ bool simple_wallet::version(const std::vector<std::string> &args)
return true;
}
bool simple_wallet::on_cancelled_command()
{
check_for_inactivity_lock(false);
return true;
}
bool simple_wallet::cold_sign_tx(const std::vector<tools::wallet2::pending_tx>& ptx_vector, tools::wallet2::signed_tx_set &exported_txs, std::vector<cryptonote::address_parse_info> const &dsts_info, std::function<bool(const tools::wallet2::signed_tx_set &)> accept_func)
{
std::vector<std::string> tx_aux;
@ -3106,8 +3100,6 @@ Pending or Failed: "failed"|"pending", "out", Lock, Checkpointed, Time, Amount*
tr(USAGE_HELP),
tr("Show the help section or the documentation about a <command>."));
m_cmd_binder.set_cancel_handler(boost::bind(&simple_wallet::on_cancelled_command, this));
//
// Loki
//
@ -8494,6 +8486,7 @@ bool simple_wallet::check_inactivity()
{
m_locked = true;
m_cmd_binder.cancel_input();
check_for_inactivity_lock(false);
}
}
return true;

View file

@ -298,7 +298,6 @@ namespace cryptonote
bool freeze_thaw(const std::vector<std::string>& args, bool freeze);
bool on_command(bool (simple_wallet::*cmd)(const std::vector<std::string>&), const std::vector<std::string> &args);
bool on_cancelled_command();
void check_for_inactivity_lock(bool user);
bool get_transfers(std::vector<std::string>& args_, std::vector<tools::transfer_view>& transfers);
@ -448,7 +447,7 @@ namespace cryptonote
std::atomic<bool> m_locked;
std::atomic<bool> m_in_command;
epee::math_helper::periodic_task m_inactivity_checker{1s};
epee::math_helper::periodic_task m_inactivity_checker{10s};
epee::math_helper::periodic_task m_refresh_checker{90s};
epee::math_helper::periodic_task m_mms_checker{90s};