@@ -2007,10 +2007,7 @@ DBErrors CWallet::LoadWallet()
2007
2007
assert (m_internal_spk_managers.empty ());
2008
2008
}
2009
2009
2010
- if (nLoadWalletRet != DBErrors::LOAD_OK)
2011
- return nLoadWalletRet;
2012
-
2013
- return DBErrors::LOAD_OK;
2010
+ return nLoadWalletRet;
2014
2011
}
2015
2012
2016
2013
DBErrors CWallet::ZapSelectTx (std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)
@@ -2542,6 +2539,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
2542
2539
// TODO: Can't use std::make_shared because we need a custom deleter but
2543
2540
// should be possible to use std::allocate_shared.
2544
2541
std::shared_ptr<CWallet> walletInstance (new CWallet (chain, name, std::move (database)), ReleaseWallet);
2542
+ bool rescan_required = false ;
2545
2543
DBErrors nLoadWalletRet = walletInstance->LoadWallet ();
2546
2544
if (nLoadWalletRet != DBErrors::LOAD_OK) {
2547
2545
if (nLoadWalletRet == DBErrors::CORRUPT) {
@@ -2562,6 +2560,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
2562
2560
{
2563
2561
error = strprintf (_ (" Wallet needed to be rewritten: restart %s to complete" ), PACKAGE_NAME);
2564
2562
return nullptr ;
2563
+ } else if (nLoadWalletRet == DBErrors::RESCAN_REQUIRED) {
2564
+ warnings.push_back (strprintf (_ (" Error reading %s! Transaction data may be missing or incorrect."
2565
+ " Rescanning wallet." ), walletFile));
2566
+ rescan_required = true ;
2565
2567
}
2566
2568
else {
2567
2569
error = strprintf (_ (" Error loading %s" ), walletFile);
@@ -2753,7 +2755,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
2753
2755
2754
2756
LOCK (walletInstance->cs_wallet );
2755
2757
2756
- if (chain && !AttachChain (walletInstance, *chain, error, warnings)) {
2758
+ if (chain && !AttachChain (walletInstance, *chain, rescan_required, error, warnings)) {
2757
2759
return nullptr ;
2758
2760
}
2759
2761
@@ -2775,7 +2777,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
2775
2777
return walletInstance;
2776
2778
}
2777
2779
2778
- bool CWallet::AttachChain (const std::shared_ptr<CWallet>& walletInstance, interfaces::Chain& chain, bilingual_str& error, std::vector<bilingual_str>& warnings)
2780
+ bool CWallet::AttachChain (const std::shared_ptr<CWallet>& walletInstance, interfaces::Chain& chain, const bool rescan_required, bilingual_str& error, std::vector<bilingual_str>& warnings)
2779
2781
{
2780
2782
LOCK (walletInstance->cs_wallet );
2781
2783
// allow setting the chain if it hasn't been set already but prevent changing it
@@ -2792,8 +2794,9 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
2792
2794
// interface.
2793
2795
walletInstance->m_chain_notifications_handler = walletInstance->chain ().handleNotifications (walletInstance);
2794
2796
2797
+ // If either rescan_required = true or -rescan is set, rescan_height remains equal to 0
2795
2798
int rescan_height = 0 ;
2796
- if (!gArgs .GetBoolArg (" -rescan" , false ))
2799
+ if (!rescan_required && ! gArgs .GetBoolArg (" -rescan" , false ))
2797
2800
{
2798
2801
WalletBatch batch (walletInstance->GetDatabase ());
2799
2802
CBlockLocator locator;
0 commit comments