From 7dc93fe1442ab1a2b190bb50278487df6c357dbb Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 4 Oct 2021 13:11:56 +0200 Subject: [PATCH] added idle wallet store in server mode --- src/wallet/wallet_rpc_server.cpp | 13 +++++++++++++ src/wallet/wallet_rpc_server.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 9152c66a..e762ebbf 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -91,6 +91,18 @@ namespace tools LOG_PRINT_L2("wallet RPC idle: trying to do PoS iteration..."); m_wallet.try_mint_pos(miner_address); } + + //auto-store wallet in server mode, let's do it every 24-hour + if (m_wallet.get_top_block_height() < m_last_wallet_store_height) + { + LOG_ERROR("Unexpected m_last_wallet_store_height = " << m_last_wallet_store_height << " or " << m_wallet.get_top_block_height()); + } + else if (m_wallet.get_top_block_height() - m_last_wallet_store_height > CURRENCY_BLOCKS_PER_DAY) + { + //store wallet + m_wallet.store(); + m_last_wallet_store_height = m_wallet.get_top_block_height(); + } } catch (error::no_connection_to_daemon&) { @@ -132,6 +144,7 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::init(const boost::program_options::variables_map& vm) { + m_last_wallet_store_height = m_wallet.get_top_block_height(); m_net_server.set_threads_prefix("RPC"); bool r = handle_command_line(vm); CHECK_AND_ASSERT_MES(r, false, "Failed to process command line in core_rpc_server"); diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 3c75296e..b99420d4 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -118,6 +118,7 @@ namespace tools std::string m_bind_ip; bool m_do_mint; bool m_deaf; + uint64_t m_last_wallet_store_height; }; } // namespace tools