mirror of
https://github.com/monero-project/monero.git
synced 2024-12-25 10:49:24 -05:00
wallet: add no_sync flag to wallet-rpc.
* encapsulate auto_refresh variable.
This commit is contained in:
parent
be87c56331
commit
a171225689
@ -59,8 +59,6 @@ using namespace epee;
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
|
||||
|
||||
#define DEFAULT_AUTO_REFRESH_PERIOD 20 // seconds
|
||||
#define REFRESH_INDICATIVE_BLOCK_CHUNK_SIZE 256 // just to split refresh in separate calls to play nicer with other threads
|
||||
|
||||
#define CHECK_MULTISIG_ENABLED() \
|
||||
do \
|
||||
@ -129,6 +127,7 @@ namespace
|
||||
const command_line::arg_descriptor<std::string> arg_wallet_dir = {"wallet-dir", "Directory for newly created wallets"};
|
||||
const command_line::arg_descriptor<bool> arg_prompt_for_password = {"prompt-for-password", "Prompts for password when not provided", false};
|
||||
const command_line::arg_descriptor<bool> arg_no_initial_sync = {"no-initial-sync", "Skips the initial sync before listening for connections", false};
|
||||
const command_line::arg_descriptor<bool> arg_no_sync = {"no-sync", "Don't synchronize the wallet with daemon", false};
|
||||
|
||||
constexpr const char default_rpc_username[] = "monero";
|
||||
|
||||
@ -195,9 +194,9 @@ namespace tools
|
||||
{
|
||||
m_stop = false;
|
||||
m_net_server.add_idle_handler([this](){
|
||||
if (m_auto_refresh_period == 0) // disabled
|
||||
if (this->auto_refresh_is_disabled())
|
||||
return true;
|
||||
if (boost::posix_time::microsec_clock::universal_time() < m_last_auto_refresh_time + boost::posix_time::seconds(m_auto_refresh_period))
|
||||
if (boost::posix_time::microsec_clock::universal_time() < m_last_auto_refresh_time + boost::posix_time::seconds(this->get_auto_refresh_period()))
|
||||
return true;
|
||||
uint64_t blocks_fetched = 0;
|
||||
try {
|
||||
@ -320,7 +319,8 @@ namespace tools
|
||||
assert(bool(http_login));
|
||||
} // end auth enabled
|
||||
|
||||
m_auto_refresh_period = DEFAULT_AUTO_REFRESH_PERIOD;
|
||||
if(!this->auto_refresh_is_disabled())
|
||||
this->set_auto_refresh_period(DEFAULT_AUTO_REFRESH_PERIOD);
|
||||
m_last_auto_refresh_time = boost::posix_time::min_date_time;
|
||||
|
||||
check_background_mining();
|
||||
@ -3339,8 +3339,8 @@ namespace tools
|
||||
}
|
||||
try
|
||||
{
|
||||
m_auto_refresh_period = req.enable ? req.period ? req.period : DEFAULT_AUTO_REFRESH_PERIOD : 0;
|
||||
MINFO("Auto refresh now " << (m_auto_refresh_period ? std::to_string(m_auto_refresh_period) + " seconds" : std::string("disabled")));
|
||||
this->set_auto_refresh_period(req.enable ? req.period ? req.period : DEFAULT_AUTO_REFRESH_PERIOD : 0);
|
||||
MINFO("Auto refresh now " << (!this->auto_refresh_is_disabled() ? std::to_string(this->get_auto_refresh_period()) + " seconds" : std::string("disabled")));
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@ -4815,7 +4815,14 @@ public:
|
||||
const auto password_file = command_line::get_arg(vm, arg_password_file);
|
||||
const auto prompt_for_password = command_line::get_arg(vm, arg_prompt_for_password);
|
||||
const auto password_prompt = prompt_for_password ? password_prompter : nullptr;
|
||||
wrpc->set_no_initial_sync(command_line::get_arg(vm, arg_no_initial_sync));
|
||||
const bool no_sync = command_line::get_arg(vm, arg_no_sync);
|
||||
wrpc->set_no_initial_sync(command_line::get_arg(vm, arg_no_initial_sync)
|
||||
|| no_sync);
|
||||
|
||||
if(no_sync) {
|
||||
LOG_PRINT_L1("--no-sync passed. Disabling the auto_refresh and not syncing the wallet.");
|
||||
wrpc->disable_auto_refresh();
|
||||
}
|
||||
|
||||
if(!wallet_file.empty() && !from_json.empty())
|
||||
{
|
||||
@ -4986,6 +4993,7 @@ int main(int argc, char** argv) {
|
||||
command_line::add_arg(desc_params, arg_wallet_dir);
|
||||
command_line::add_arg(desc_params, arg_prompt_for_password);
|
||||
command_line::add_arg(desc_params, arg_no_initial_sync);
|
||||
command_line::add_arg(desc_params, arg_no_sync);
|
||||
command_line::add_arg(hidden_options, daemonizer::arg_non_interactive);
|
||||
|
||||
daemonizer::init_options(hidden_options, desc_params);
|
||||
|
@ -41,6 +41,9 @@
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
|
||||
|
||||
#define DEFAULT_AUTO_REFRESH_PERIOD 20 // seconds
|
||||
#define REFRESH_INDICATIVE_BLOCK_CHUNK_SIZE 256 // just to split refresh in separate calls to play nicer with other threads
|
||||
|
||||
namespace tools
|
||||
{
|
||||
/************************************************************************/
|
||||
@ -69,6 +72,22 @@ namespace tools
|
||||
return m_no_initial_sync;
|
||||
}
|
||||
|
||||
bool auto_refresh_is_disabled() {
|
||||
return this->m_auto_refresh_period == 0;
|
||||
}
|
||||
|
||||
void disable_auto_refresh() {
|
||||
this->m_auto_refresh_period = 0;
|
||||
}
|
||||
|
||||
void set_auto_refresh_period(uint32_t auto_refresh){
|
||||
this->m_auto_refresh_period = auto_refresh;
|
||||
}
|
||||
|
||||
uint32_t get_auto_refresh_period() {
|
||||
return this->m_auto_refresh_period;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
CHAIN_HTTP_TO_MAP2(connection_context); //forward http requests to uri map
|
||||
@ -294,7 +313,7 @@ namespace tools
|
||||
bool m_restricted;
|
||||
bool m_no_initial_sync;
|
||||
const boost::program_options::variables_map *m_vm;
|
||||
uint32_t m_auto_refresh_period;
|
||||
uint32_t m_auto_refresh_period = DEFAULT_AUTO_REFRESH_PERIOD;
|
||||
boost::posix_time::ptime m_last_auto_refresh_time;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user