mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-17 15:21:30 +02:00
separate lockAndSync() from syncAux()
This commit is contained in:
+22
-10
@@ -1033,22 +1033,22 @@ namespace monero {
|
||||
|
||||
MoneroSyncResult MoneroWallet::sync() {
|
||||
cout << "sync()" << endl;
|
||||
return syncAux(boost::none, boost::none);
|
||||
return lockAndSync();
|
||||
}
|
||||
|
||||
MoneroSyncResult MoneroWallet::sync(MoneroSyncListener& listener) {
|
||||
cout << "sync(startHeight)" << endl;
|
||||
return syncAux(boost::none, listener);
|
||||
return lockAndSync(boost::none, listener);
|
||||
}
|
||||
|
||||
MoneroSyncResult MoneroWallet::sync(uint64_t startHeight) {
|
||||
cout << "sync(startHeight)" << endl;
|
||||
return syncAux(startHeight, boost::none);
|
||||
return lockAndSync(startHeight);
|
||||
}
|
||||
|
||||
MoneroSyncResult MoneroWallet::sync(uint64_t startHeight, MoneroSyncListener& listener) {
|
||||
cout << "sync(startHeight, listener)" << endl;
|
||||
return syncAux(startHeight, listener);
|
||||
return lockAndSync(startHeight, listener);
|
||||
}
|
||||
|
||||
void MoneroWallet::setAutoSync(bool autoSync) {
|
||||
@@ -1065,9 +1065,11 @@ namespace monero {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: support arguments bool hard, bool refresh = true, bool keep_key_images = false
|
||||
void MoneroWallet::rescanBlockchain() {
|
||||
cout << "rescanBlockchain()" << endl;
|
||||
wallet2->rescan_blockchain(false); // TODO: support arguments bool hard, bool refresh = true, bool keep_key_images = false
|
||||
rescanOnSync = true;
|
||||
syncAux();
|
||||
}
|
||||
|
||||
// isMultisigImportNeeded
|
||||
@@ -2325,22 +2327,32 @@ namespace monero {
|
||||
syncCV.wait(lock);
|
||||
}
|
||||
if (autoSyncEnabled) {
|
||||
autoSyncAux();
|
||||
lockAndSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MoneroWallet::autoSyncAux() {
|
||||
MoneroSyncResult MoneroWallet::lockAndSync(boost::optional<uint64_t> startHeight, boost::optional<MoneroSyncListener&> listener) {
|
||||
bool rescan = rescanOnSync.exchange(false);
|
||||
boost::lock_guard<boost::mutex> guarg(syncMutex);
|
||||
boost::lock_guard<boost::mutex> guarg(syncMutex); // synchronize sync() and syncAsync()
|
||||
MoneroSyncResult result;
|
||||
result.numBlocksFetched = 0;
|
||||
result.receivedMoney = false;
|
||||
do {
|
||||
// skip if daemon is not synced
|
||||
if (getIsDaemonSynced()) {
|
||||
|
||||
// rescan blockchain if requested
|
||||
if (rescan) wallet2->rescan_blockchain(false);
|
||||
syncAux(boost::none, boost::none);
|
||||
if (!isSynced) isSynced = true;
|
||||
|
||||
// sync wallet
|
||||
result = syncAux(startHeight, listener);
|
||||
|
||||
// find and save rings
|
||||
wallet2->find_and_save_rings(false);
|
||||
}
|
||||
} while (!rescan && (rescan = rescanOnSync.exchange(false))); // repeat if not rescanned and rescan was requested
|
||||
return result;
|
||||
}
|
||||
|
||||
MoneroSyncResult MoneroWallet::syncAux(boost::optional<uint64_t> startHeight, boost::optional<MoneroSyncListener&> listener) {
|
||||
|
||||
@@ -1177,7 +1177,7 @@ namespace monero {
|
||||
boost::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
|
||||
void autoSyncAux(); // internal synchronized sync function
|
||||
MoneroSyncResult syncAux(boost::optional<uint64_t> startHeight, boost::optional<MoneroSyncListener&> listener);
|
||||
MoneroSyncResult lockAndSync(boost::optional<uint64_t> startHeight = boost::none, boost::optional<MoneroSyncListener&> listener = boost::none); // internal function to synchronize request to sync and rescan
|
||||
MoneroSyncResult syncAux(boost::optional<uint64_t> startHeight = boost::none, boost::optional<MoneroSyncListener&> listener = boost::none); // internal function to immediately block, sync, and report progress
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user