From ff1921805929071d9610793eef5fd9fc11f43135 Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 20 Dec 2020 12:57:19 -0500 Subject: [PATCH] support wallet sync rate --- src/wallet/monero_wallet.h | 6 ++++-- src/wallet/monero_wallet_core.cpp | 5 ++--- src/wallet/monero_wallet_core.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 8aecae3..d25f1a5 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -460,9 +460,11 @@ namespace monero { } /** - * Start an asynchronous thread to continuously synchronize the wallet with the daemon. + * Start background synchronizing with a maximum number of seconds between syncs. + * + * @param sync_rate_in_seconds - maximum number of seconds between wallet syncs for updates (default 10 seconds) */ - virtual void start_syncing() { + virtual void start_syncing(uint32_t sync_rate_in_seconds = 10) { throw std::runtime_error("start_syncing() not supported"); } diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index 6a97424..5b22d7c 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -76,7 +76,6 @@ namespace monero { // ------------------------- INITIALIZE CONSTANTS --------------------------- - static const int DEFAULT_SYNC_INTERVAL_MILLIS = 1000 * 10; // default refresh interval 10 sec static const int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 1000 * 30; // default connection timeout 30 sec static const bool STRICT = false; // relies exclusively on blockchain data if true, includes local wallet data if false TODO: good use case to expose externally? @@ -1376,8 +1375,9 @@ namespace monero { /** * Start automatic syncing as its own thread. */ - void monero_wallet_core::start_syncing() { + void monero_wallet_core::start_syncing(uint32_t sync_rate_in_seconds) { if (!m_is_connected) throw std::runtime_error("Wallet is not connected to daemon"); + m_syncing_interval = sync_rate_in_seconds * 1000; // set sync rate // TODO: use ms instead of seconds? if (!m_syncing_enabled) { m_syncing_enabled = true; run_sync_loop(); // sync wallet on loop in background @@ -3209,7 +3209,6 @@ namespace monero { m_rescan_on_sync = false; m_syncing_enabled = false; m_sync_loop_running = false; - m_syncing_interval = DEFAULT_SYNC_INTERVAL_MILLIS; } std::vector> monero_wallet_core::get_transfers_aux(const monero_transfer_query& query) const { diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index 7278363..2ffb9cd 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -204,7 +204,7 @@ namespace monero { monero_sync_result sync(monero_wallet_listener& listener) override; monero_sync_result sync(uint64_t start_height) override; monero_sync_result sync(uint64_t start_height, monero_wallet_listener& listener) override; - void start_syncing() override; + void start_syncing(uint32_t sync_rate) override; void stop_syncing() override; void rescan_spent() override; void rescan_blockchain() override;