Skip to content

Commit 6ed424f

Browse files
committed
wallet: fix, detect blank legacy wallets in IsLegacy
Blank legacy wallets do not have active SPKM. They can only be detected by checking the descriptors' flag or the db format. This enables the migration of blank legacy wallets in the GUI.
1 parent c2d15d9 commit 6ed424f

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/wallet/wallet.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,22 +1037,22 @@ bool CWallet::IsSpentKey(const CScript& scriptPubKey) const
10371037
if (IsAddressPreviouslySpent(dest)) {
10381038
return true;
10391039
}
1040-
if (IsLegacy()) {
1041-
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
1042-
assert(spk_man != nullptr);
1043-
for (const auto& keyid : GetAffectedKeys(scriptPubKey, *spk_man)) {
1044-
WitnessV0KeyHash wpkh_dest(keyid);
1045-
if (IsAddressPreviouslySpent(wpkh_dest)) {
1046-
return true;
1047-
}
1048-
ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest));
1049-
if (IsAddressPreviouslySpent(sh_wpkh_dest)) {
1050-
return true;
1051-
}
1052-
PKHash pkh_dest(keyid);
1053-
if (IsAddressPreviouslySpent(pkh_dest)) {
1054-
return true;
1055-
}
1040+
1041+
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
1042+
if (!spk_man) return false;
1043+
1044+
for (const auto& keyid : GetAffectedKeys(scriptPubKey, *spk_man)) {
1045+
WitnessV0KeyHash wpkh_dest(keyid);
1046+
if (IsAddressPreviouslySpent(wpkh_dest)) {
1047+
return true;
1048+
}
1049+
ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest));
1050+
if (IsAddressPreviouslySpent(sh_wpkh_dest)) {
1051+
return true;
1052+
}
1053+
PKHash pkh_dest(keyid);
1054+
if (IsAddressPreviouslySpent(pkh_dest)) {
1055+
return true;
10561056
}
10571057
}
10581058
return false;
@@ -1625,7 +1625,9 @@ isminetype CWallet::IsMine(const CScript& script) const
16251625
}
16261626

16271627
// Legacy wallet
1628-
if (IsLegacy()) return GetLegacyScriptPubKeyMan()->IsMine(script);
1628+
if (LegacyScriptPubKeyMan* spkm = GetLegacyScriptPubKeyMan()) {
1629+
return spkm->IsMine(script);
1630+
}
16291631

16301632
return ISMINE_NO;
16311633
}
@@ -3558,7 +3560,8 @@ std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script) c
35583560
Assume(std::all_of(spk_mans.begin(), spk_mans.end(), [&script, &sigdata](ScriptPubKeyMan* spkm) { return spkm->CanProvide(script, sigdata); }));
35593561

35603562
// Legacy wallet
3561-
if (IsLegacy() && GetLegacyScriptPubKeyMan()->CanProvide(script, sigdata)) spk_mans.insert(GetLegacyScriptPubKeyMan());
3563+
LegacyScriptPubKeyMan* spkm = GetLegacyScriptPubKeyMan();
3564+
if (spkm && spkm->CanProvide(script, sigdata)) spk_mans.insert(spkm);
35623565

35633566
return spk_mans;
35643567
}
@@ -3588,7 +3591,8 @@ std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& scri
35883591
}
35893592

35903593
// Legacy wallet
3591-
if (IsLegacy() && GetLegacyScriptPubKeyMan()->CanProvide(script, sigdata)) return GetLegacyScriptPubKeyMan()->GetSolvingProvider(script);
3594+
LegacyScriptPubKeyMan* spkm = GetLegacyScriptPubKeyMan();
3595+
if (spkm && spkm->CanProvide(script, sigdata)) return spkm->GetSolvingProvider(script);
35923596

35933597
return nullptr;
35943598
}
@@ -3845,11 +3849,7 @@ void CWallet::DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool intern
38453849

38463850
bool CWallet::IsLegacy() const
38473851
{
3848-
if (m_internal_spk_managers.count(OutputType::LEGACY) == 0) {
3849-
return false;
3850-
}
3851-
auto spk_man = dynamic_cast<LegacyScriptPubKeyMan*>(m_internal_spk_managers.at(OutputType::LEGACY));
3852-
return spk_man != nullptr;
3852+
return !IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS);
38533853
}
38543854

38553855
DescriptorScriptPubKeyMan* CWallet::GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const

0 commit comments

Comments
 (0)