Skip to content

Commit 7f7ffae

Browse files
committed
[Wallet] Upgrade to HD from a locked wallet error notification + further old comments cleanup.
1 parent 5748d39 commit 7f7ffae

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

src/init.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static void registerSignalHandler(int signal, void(*handler)(int))
327327

328328
bool static InitError(const std::string& str)
329329
{
330-
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
330+
uiInterface.ThreadSafeMessageBox(str, "Init Error", CClientUIInterface::MSG_ERROR);
331331
return false;
332332
}
333333

@@ -1673,17 +1673,27 @@ bool AppInit2()
16731673

16741674
int prev_version = pwalletMain->GetVersion();
16751675
if (GetBoolArg("-upgradewallet", fFirstRun)) {
1676-
int nMaxVersion = GetArg("-upgradewallet", 0);
1677-
if (nMaxVersion == 0) // the -upgradewallet without argument case
1678-
{
1679-
LogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
1680-
nMaxVersion = FEATURE_LATEST;
1681-
pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
1682-
} else
1683-
LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
1684-
if (nMaxVersion < pwalletMain->GetVersion())
1685-
strErrors << _("Cannot downgrade wallet") << "\n";
1686-
pwalletMain->SetMaxVersion(nMaxVersion);
1676+
1677+
if (prev_version <= FEATURE_PRE_PIVX && pwalletMain->IsLocked()) {
1678+
// Cannot upgrade a locked wallet
1679+
std::string strProblem = "Cannot upgrade a locked wallet.\n";
1680+
strErrors << _("Error: ") << strProblem;
1681+
LogPrintf("%s", strErrors.str());
1682+
return InitError(strProblem);
1683+
} else {
1684+
1685+
int nMaxVersion = GetArg("-upgradewallet", 0);
1686+
if (nMaxVersion == 0) // the -upgradewallet without argument case
1687+
{
1688+
LogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
1689+
nMaxVersion = FEATURE_LATEST;
1690+
pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
1691+
} else
1692+
LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
1693+
if (nMaxVersion < pwalletMain->GetVersion())
1694+
strErrors << _("Cannot downgrade wallet") << "\n";
1695+
pwalletMain->SetMaxVersion(nMaxVersion);
1696+
}
16871697
}
16881698

16891699
// Upgrade to HD if explicit upgrade was requested.

src/wallet/scriptpubkeyman.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ int64_t ScriptPubKeyMan::GetOldestKeyPoolTime()
103103
int64_t oldestKey = GetOldestKeyTimeInPool(setExternalKeyPool, batch);
104104
if (IsHDEnabled()) {
105105
oldestKey = std::max(GetOldestKeyTimeInPool(setInternalKeyPool, batch), oldestKey);
106+
oldestKey = std::max(GetOldestKeyTimeInPool(setStakingKeyPool, batch), oldestKey);
106107
if (!set_pre_split_keypool.empty()) {
107108
oldestKey = std::max(GetOldestKeyTimeInPool(set_pre_split_keypool, batch), oldestKey);
108109
}
@@ -197,7 +198,7 @@ bool ScriptPubKeyMan::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool,
197198
if (!wallet->GetPubKey(keypool.vchPubKey.GetID(), pk)) {
198199
throw std::runtime_error(std::string(__func__) + ": unknown key in key pool");
199200
}
200-
// If the key was pre-split keypool, we don't care about what type it is //TODO: Add staking address
201+
// If the key was pre-split keypool, we don't care about what type it is
201202
if (use_split_keypool && keypool.IsInternal() != fReturningInternal) {
202203
throw std::runtime_error(std::string(__func__) + ": keypool internal entry misclassified");
203204
}

src/wallet/wallet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2937,7 +2937,6 @@ void CWallet::ReturnKey(int64_t nIndex, const bool& internal, const bool& stakin
29372937

29382938
bool CWallet::GetKeyFromPool(CPubKey& result, const uint8_t& type)
29392939
{
2940-
// TODO: Modify this for Staking addresses support if needed.
29412940
return m_spk_man->GetKeyFromPool(result, type);
29422941
}
29432942

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ enum WalletFeature {
8080
FEATURE_WALLETCRYPT = 40000, // wallet encryption
8181
FEATURE_COMPRPUBKEY = 60000, // compressed public keys
8282

83-
PRE_PIVX = 61000, // inherited version..
83+
FEATURE_PRE_PIVX = 61000, // inherited version..
8484

8585
// The following features were implemented in BTC but not in our wallet, we can simply skip them.
8686
// FEATURE_HD = 130000, Hierarchical key derivation after BIP32 (HD Wallet)

0 commit comments

Comments
 (0)