From 5fb2acaa8b4e2c699bae30ee805055469deacb9f Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 17 Jul 2019 18:52:46 -0400 Subject: [PATCH] ready to implement autoSyncThreadFunc() --- src/wallet/MoneroWallet.cpp | 33 +++++++++++++++++++-------------- src/wallet/MoneroWallet.h | 12 ++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index e976bbb..b308f4b 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -730,7 +730,7 @@ namespace monero { cout << "MoneroWallet(3b)" << endl; wallet2 = unique_ptr(new tools::wallet2(static_cast(networkType), 1, true)); wallet2->load(path, password); - wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); + initCommon(); } MoneroWallet::MoneroWallet(const string& path, const string& password) { @@ -745,7 +745,7 @@ namespace monero { wallet2->set_seed_language(language); crypto::secret_key secret_key; wallet2->generate(path, password, secret_key, false, false); - wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); + initCommon(); } MoneroWallet::MoneroWallet(const string& path, const string& password, const string& mnemonic, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, uint64_t restoreHeight) { @@ -763,12 +763,7 @@ namespace monero { wallet2->set_seed_language(language); wallet2->generate(path, password, recoveryKey, true, false); wallet2->set_refresh_from_block_height(restoreHeight); - wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); - - // print the mnemonic - epee::wipeable_string fetchedMnemonic; - wallet2->get_seed(fetchedMnemonic); - cout << "Mnemonic: " << string(fetchedMnemonic.data(), fetchedMnemonic.size()) << endl; + initCommon(); } MoneroWallet::MoneroWallet(const string& path, const string& password, const string& address, const string& viewKey, const string& spendKey, const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, uint64_t restoreHeight, const string& language) { @@ -824,12 +819,7 @@ namespace monero { setDaemonConnection(daemonConnection); wallet2->set_refresh_from_block_height(restoreHeight); wallet2->set_seed_language(language); - wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); - - // print the mnemonic - epee::wipeable_string fetchedMnemonic; - wallet2->get_seed(fetchedMnemonic); - cout << "Mnemonic: " << string(fetchedMnemonic.data(), fetchedMnemonic.size()) << endl; + initCommon(); } MoneroWallet::~MoneroWallet() { @@ -2240,6 +2230,21 @@ namespace monero { // ------------------------------- PRIVATE HELPERS ---------------------------- + void MoneroWallet::initCommon() { + cout << "MoneroWallet.cpp initCommon()" << endl; + wallet2Listener = unique_ptr(new Wallet2Listener(*this, *wallet2)); + + // start auto sync loop + autoSyncThread = boost::thread([this]() { + this->autoSyncThreadFunc(); + }); + } + + void MoneroWallet::autoSyncThreadFunc() { + cout << "autoSyncThreadFunc()" << endl; + throw runtime_error("autoSyncThreadFunc() not implemented"); + } + MoneroSyncResult MoneroWallet::syncAux(boost::optional startHeight, boost::optional endHeight, boost::optional listener) { cout << "syncAux()" << endl; diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index cf43c94..ae266e4 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -1148,7 +1148,19 @@ namespace monero { unique_ptr wallet2Listener; // listener for internal wallet implementation boost::optional listener = boost::none; // wallet's external listener + void initCommon(); MoneroSyncResult syncAux(boost::optional startHeight, boost::optional endHeight, boost::optional listener); vector getSubaddressesAux(uint32_t accountIdx, vector subaddressIndices, const vector& transfers) const; + + // sync thread management + boost::condition_variable syncCV; // to awaken sync threads + std::mutex syncMutex; // synchronize sync() and syncAsync() requests + std::atomic rescanOnSync; // whether or not to rescan on sync + std::atomic autoSyncEnabled; // whether or not auto sync is enabled + std::atomic autoSyncIntervalMillis; // auto sync loop inteval + boost::thread autoSyncThread; // thread for auto sync loop + std::mutex autoSyncMutex; // synchronize auto sync loop + std::atomic autoSyncThreadDone; // whether or not auto sync loop is done (cannot be re-started) + void autoSyncThreadFunc(); // function to run auto sync loop thread }; }