diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 46b3809..d4e1120 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -657,18 +657,9 @@ namespace monero { void onSyncStart(uint64_t startHeight, boost::optional syncListener) { if (syncStartHeight != boost::none || syncEndHeight != boost::none) throw runtime_error("Sync start or end height should not already be allocated, is previous sync in progress?"); syncStartHeight = startHeight; - syncEndHeight = wallet.getChainHeight() - 1; + syncEndHeight = wallet.getChainHeight(); this->syncListener = syncListener; updateListening(); - - // notify listeners of sync start - uint64_t numBlocksDone = 0; - uint64_t numBlocksTotal = *syncEndHeight - *syncStartHeight + 1; - if (numBlocksTotal < 1) return; // don't report 0% progress if no subsequent progress to report - double percentDone = numBlocksDone / (double) numBlocksTotal; - string message = string("Synchronizing"); - if (listener != boost::none) listener.get().onSyncProgress(*syncStartHeight, numBlocksDone, numBlocksTotal, percentDone, message); - if (syncListener != boost::none) syncListener.get().onSyncProgress(*syncStartHeight, numBlocksDone, numBlocksTotal, percentDone, message); } void onSyncEnd() { @@ -688,14 +679,12 @@ namespace monero { } // notify listeners of sync progress - if (syncStartHeight != boost::none && height > *syncStartHeight) { - if (height > *syncEndHeight) *syncEndHeight = height; // increase end height if necessary - uint64_t numBlocksDone = height - *syncStartHeight + 1; - uint64_t numBlocksTotal = *syncEndHeight - *syncStartHeight + 1; - double percentDone = numBlocksDone / (double) numBlocksTotal; + if (syncStartHeight != boost::none && height >= *syncStartHeight) { + if (height >= *syncEndHeight) syncEndHeight = height + 1; // increase end height if necessary + double percentDone = (double) (height - *syncStartHeight + 1) / (double) (*syncEndHeight - *syncStartHeight); string message = string("Synchronizing"); - if (listener != boost::none) listener.get().onSyncProgress(*syncStartHeight, numBlocksDone, numBlocksTotal, percentDone, message); - if (syncListener != boost::none) syncListener.get().onSyncProgress(*syncStartHeight, numBlocksDone, numBlocksTotal, percentDone, message); + if (listener != boost::none) listener.get().onSyncProgress(height, *syncStartHeight, *syncEndHeight, percentDone, message); + if (syncListener != boost::none) syncListener.get().onSyncProgress(height, *syncStartHeight, *syncEndHeight, percentDone, message); } } @@ -2238,7 +2227,7 @@ namespace monero { cout << "syncAux()" << endl; // validate inputs - if (endHeight != boost::none) throw runtime_error("Monero core wallet does not support syncing to an end height"); // TODO: custom exception type + if (endHeight != boost::none) throw runtime_error("Monero core wallet2 does not support syncing to an end height"); // TODO: custom exception type // determine sync start height uint64_t syncStartHeight = startHeight == boost::none ? max(getHeight(), getRestoreHeight()) : *startHeight; diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 526443e..31aae81 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -101,15 +101,13 @@ namespace monero { /** * Invoked when sync progress is made. * - * TODO: const uint64_t& startHeight, etc...? - * + * @param height is the height of the synced block * @param startHeight is the starting height of the sync request - * @param numBlocksDone is the number of blocks synced - * @param numBlocksTotal is the total number of blocks to sync + * @param endHeight is the ending height of the sync request * @param percentDone is the sync progress as a percentage * @param message is a human-readable description of the current progress */ - virtual void onSyncProgress(uint64_t startHeight, uint64_t numBlocksDone, uint64_t numBlocksTotal, double percentDone, string& message) {} + virtual void onSyncProgress(uint64_t height, uint64_t startHeight, uint64_t endHeight, double percentDone, const string& message) {} }; /**