ready to implement autoSyncThreadFunc()

This commit is contained in:
woodser
2019-07-17 18:52:46 -04:00
parent 95dea54afe
commit 5fb2acaa8b
2 changed files with 31 additions and 14 deletions
+19 -14
View File
@@ -730,7 +730,7 @@ namespace monero {
cout << "MoneroWallet(3b)" << endl;
wallet2 = unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<network_type>(networkType), 1, true));
wallet2->load(path, password);
wallet2Listener = unique_ptr<Wallet2Listener>(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<Wallet2Listener>(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<Wallet2Listener>(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<Wallet2Listener>(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<Wallet2Listener>(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<uint64_t> startHeight, boost::optional<uint64_t> endHeight, boost::optional<MoneroSyncListener&> listener) {
cout << "syncAux()" << endl;
+12
View File
@@ -1148,7 +1148,19 @@ namespace monero {
unique_ptr<Wallet2Listener> wallet2Listener; // listener for internal wallet implementation
boost::optional<MoneroWalletListener&> listener = boost::none; // wallet's external listener
void initCommon();
MoneroSyncResult syncAux(boost::optional<uint64_t> startHeight, boost::optional<uint64_t> endHeight, boost::optional<MoneroSyncListener&> listener);
vector<MoneroSubaddress> getSubaddressesAux(uint32_t accountIdx, vector<uint32_t> subaddressIndices, const vector<tools::wallet2::transfer_details>& transfers) const;
// sync thread management
boost::condition_variable syncCV; // to awaken sync threads
std::mutex syncMutex; // synchronize sync() and syncAsync() requests
std::atomic<bool> rescanOnSync; // whether or not to rescan on sync
std::atomic<bool> autoSyncEnabled; // whether or not auto sync is enabled
std::atomic<int> autoSyncIntervalMillis; // auto sync loop inteval
boost::thread autoSyncThread; // thread for auto sync loop
std::mutex autoSyncMutex; // synchronize auto sync loop
std::atomic<bool> autoSyncThreadDone; // whether or not auto sync loop is done (cannot be re-started)
void autoSyncThreadFunc(); // function to run auto sync loop thread
};
}