diff options
Diffstat (limited to 'src/walletcmd.cpp')
| -rw-r--r-- | src/walletcmd.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/walletcmd.cpp b/src/walletcmd.cpp index 94e9d72..8eb3592 100644 --- a/src/walletcmd.cpp +++ b/src/walletcmd.cpp | |||
| @@ -94,13 +94,17 @@ bool RestoreFromPhrase(const std::string& strMnemonic, | |||
| 94 | if (!CanScanWalletTransactions(strErrorRet)) | 94 | if (!CanScanWalletTransactions(strErrorRet)) |
| 95 | return false; | 95 | return false; |
| 96 | 96 | ||
| 97 | size_t nWalletStart = 0; | ||
| 98 | CRITICAL_BLOCK(cs_mapWallet) | ||
| 99 | nWalletStart = mapWallet.size(); | ||
| 100 | |||
| 97 | if (!SetHDSeedFromMnemonic(strMnemonic, strErrorRet)) | 101 | if (!SetHDSeedFromMnemonic(strMnemonic, strErrorRet)) |
| 98 | return false; | 102 | return false; |
| 99 | 103 | ||
| 100 | // Derive forward in batches, scanning after each, until a whole batch turns | 104 | // Derive forward in batches, scanning after each, until a whole batch turns |
| 101 | // up nothing. Every derived key is written to the wallet before the scan, | 105 | // up nothing. Every derived key is written to the wallet before the scan, |
| 102 | // because the scan asks the wallet what belongs to it. | 106 | // because the scan asks the wallet what belongs to it. |
| 103 | int nTotalDerived = 0; | 107 | int nTotalDerived = (int)nHDNext; |
| 104 | while (nTotalDerived < RESTORE_MAX) | 108 | while (nTotalDerived < RESTORE_MAX) |
| 105 | { | 109 | { |
| 106 | // Count wallet transactions, not scan hits. | 110 | // Count wallet transactions, not scan hits. |
| @@ -134,7 +138,11 @@ bool RestoreFromPhrase(const std::string& strMnemonic, | |||
| 134 | nWalletAfter = mapWallet.size(); | 138 | nWalletAfter = mapWallet.size(); |
| 135 | 139 | ||
| 136 | if (fnProgress) | 140 | if (fnProgress) |
| 137 | fnProgress(pArg, nTotalDerived, (int)nWalletAfter); | 141 | { |
| 142 | size_t nRecoveredNow = nWalletAfter > nWalletStart ? | ||
| 143 | nWalletAfter - nWalletStart : 0; | ||
| 144 | fnProgress(pArg, nTotalDerived, (int)nRecoveredNow); | ||
| 145 | } | ||
| 138 | 146 | ||
| 139 | // A whole batch with nothing in it means far enough -- unless the | 147 | // A whole batch with nothing in it means far enough -- unless the |
| 140 | // caller asked to look deeper anyway. | 148 | // caller asked to look deeper anyway. |
| @@ -148,8 +156,11 @@ bool RestoreFromPhrase(const std::string& strMnemonic, | |||
| 148 | mapKeyPool.clear(); | 156 | mapKeyPool.clear(); |
| 149 | TopUpKeyPool(); | 157 | TopUpKeyPool(); |
| 150 | 158 | ||
| 159 | size_t nWalletEnd = 0; | ||
| 151 | CRITICAL_BLOCK(cs_mapWallet) | 160 | CRITICAL_BLOCK(cs_mapWallet) |
| 152 | nRecoveredRet = (int)mapWallet.size(); | 161 | nWalletEnd = mapWallet.size(); |
| 162 | nRecoveredRet = (int)(nWalletEnd > nWalletStart ? | ||
| 163 | nWalletEnd - nWalletStart : 0); | ||
| 153 | nDerivedRet = nTotalDerived; | 164 | nDerivedRet = nTotalDerived; |
| 154 | return true; | 165 | return true; |
| 155 | } | 166 | } |