Skip to content

Commit ee36717

Browse files
committed
Merge bitcoin#30621: wallet: fix blank legacy detection
6ed424f wallet: fix, detect blank legacy wallets in IsLegacy (furszy) Pull request description: 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. To test this: 1) Create a blank legacy wallet. 2) Try to migrate it using the GUI's toolbar "Migrate Wallet" button. -> In master: The button will be disabled because `CWallet::IsLegacy()` returns false for blank legacy wallet. -> In this PR: the button will be enabled, allowing the migration of legacy wallets. ACKs for top commit: achow101: ACK 6ed424f tdb3: ACK 6ed424f glozow: ACK 6ed424f Tree-SHA512: c06c4c4c2e546ccb033287b9aa3aee4ca36b47aeb2fac6fbed5de774b65caef9c818fc8dfdaac6ce78839b2d5d642a5632a5b44c5e889ea169ced80ed50501a7
2 parents 6474132 + 6ed424f commit ee36717

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/wallet/wallet.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -1038,22 +1038,22 @@ bool CWallet::IsSpentKey(const CScript& scriptPubKey) const
10381038
if (IsAddressPreviouslySpent(dest)) {
10391039
return true;
10401040
}
1041-
if (IsLegacy()) {
1042-
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
1043-
assert(spk_man != nullptr);
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;
1056-
}
1041+
1042+
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
1043+
if (!spk_man) return false;
1044+
1045+
for (const auto& keyid : GetAffectedKeys(scriptPubKey, *spk_man)) {
1046+
WitnessV0KeyHash wpkh_dest(keyid);
1047+
if (IsAddressPreviouslySpent(wpkh_dest)) {
1048+
return true;
1049+
}
1050+
ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest));
1051+
if (IsAddressPreviouslySpent(sh_wpkh_dest)) {
1052+
return true;
1053+
}
1054+
PKHash pkh_dest(keyid);
1055+
if (IsAddressPreviouslySpent(pkh_dest)) {
1056+
return true;
10571057
}
10581058
}
10591059
return false;
@@ -1626,7 +1626,9 @@ isminetype CWallet::IsMine(const CScript& script) const
16261626
}
16271627

16281628
// Legacy wallet
1629-
if (IsLegacy()) return GetLegacyScriptPubKeyMan()->IsMine(script);
1629+
if (LegacyScriptPubKeyMan* spkm = GetLegacyScriptPubKeyMan()) {
1630+
return spkm->IsMine(script);
1631+
}
16301632

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

35613563
// Legacy wallet
3562-
if (IsLegacy() && GetLegacyScriptPubKeyMan()->CanProvide(script, sigdata)) spk_mans.insert(GetLegacyScriptPubKeyMan());
3564+
LegacyScriptPubKeyMan* spkm = GetLegacyScriptPubKeyMan();
3565+
if (spkm && spkm->CanProvide(script, sigdata)) spk_mans.insert(spkm);
35633566

35643567
return spk_mans;
35653568
}
@@ -3589,7 +3592,8 @@ std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& scri
35893592
}
35903593

35913594
// Legacy wallet
3592-
if (IsLegacy() && GetLegacyScriptPubKeyMan()->CanProvide(script, sigdata)) return GetLegacyScriptPubKeyMan()->GetSolvingProvider(script);
3595+
LegacyScriptPubKeyMan* spkm = GetLegacyScriptPubKeyMan();
3596+
if (spkm && spkm->CanProvide(script, sigdata)) return spkm->GetSolvingProvider(script);
35933597

35943598
return nullptr;
35953599
}
@@ -3846,11 +3850,7 @@ void CWallet::DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool intern
38463850

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

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

0 commit comments

Comments
 (0)