Skip to content

Commit 1e48796

Browse files
committed
Make UpgradeWallet a member function of CWallet
1 parent c988f27 commit 1e48796

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/wallet/wallet.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,7 +3831,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
38313831
}
38323832

38333833
if (gArgs.GetBoolArg("-upgradewallet", false)) {
3834-
if (!UpgradeWallet(walletInstance, gArgs.GetBoolArg("-upgradewallet", 0), error, warnings)) {
3834+
if (!UpgradeWallet(gArgs.GetBoolArg("-upgradewallet", 0), error, warnings)) {
38353835
return nullptr;
38363836
}
38373837
}
@@ -4097,38 +4097,37 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest
40974097
return &address_book_it->second;
40984098
}
40994099

4100-
bool CWallet::UpgradeWallet(std::shared_ptr<CWallet> walletInstance, int version, std::string& error, std::vector<std::string>& warnings)
4100+
bool CWallet::UpgradeWallet(int version, std::string& error, std::vector<std::string>& warnings)
41014101
{
4102-
int prev_version = walletInstance->GetVersion();
4102+
int prev_version = GetVersion();
41034103
int nMaxVersion = version;
41044104
if (nMaxVersion == 0) // the -upgradewallet without argument case
41054105
{
4106-
walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
4106+
WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
41074107
nMaxVersion = FEATURE_LATEST;
4108-
walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
4108+
SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
41094109
}
41104110
else
4111-
walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
4112-
if (nMaxVersion < walletInstance->GetVersion())
4111+
WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
4112+
if (nMaxVersion < GetVersion())
41134113
{
41144114
error = _("Cannot downgrade wallet").translated;
41154115
return false;
41164116
}
4117-
walletInstance->SetMaxVersion(nMaxVersion);
4117+
SetMaxVersion(nMaxVersion);
41184118

4119-
LOCK(walletInstance->cs_wallet);
4119+
LOCK(cs_wallet);
41204120

41214121
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
4122-
int max_version = walletInstance->GetVersion();
4123-
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
4122+
int max_version = GetVersion();
4123+
if (!CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
41244124
error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated;
41254125
return false;
41264126
}
41274127

4128-
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) {
4129-
if (!spk_man->Upgrade(prev_version, error)) {
4130-
return false;
4131-
}
4128+
for (auto spk_man : GetActiveScriptPubKeyMans()) {
4129+
if (!spk_man->Upgrade(prev_version, error)) {
4130+
return false;
41324131
}
41334132
}
41344133
return true;

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
11761176
};
11771177

11781178
/** Upgrade the wallet */
1179-
static bool UpgradeWallet(std::shared_ptr<CWallet> wallet, int version, std::string& error, std::vector<std::string>& warnings);
1179+
bool UpgradeWallet(int version, std::string& error, std::vector<std::string>& warnings);
11801180

11811181
//! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers
11821182
std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;

0 commit comments

Comments
 (0)