Skip to content

Commit 61d872f

Browse files
committed
wallet: Move MigrateToDescriptor and DeleteRecords to LegacyDataSPKM
1 parent b231f4d commit 61d872f

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ std::unordered_set<CScript, SaltedSipHasher> LegacyDataSPKM::GetScriptPubKeys()
17531753
return spks;
17541754
}
17551755

1756-
std::unordered_set<CScript, SaltedSipHasher> LegacyScriptPubKeyMan::GetNotMineScriptPubKeys() const
1756+
std::unordered_set<CScript, SaltedSipHasher> LegacyDataSPKM::GetNotMineScriptPubKeys() const
17571757
{
17581758
LOCK(cs_KeyStore);
17591759
std::unordered_set<CScript, SaltedSipHasher> spks;
@@ -1763,7 +1763,7 @@ std::unordered_set<CScript, SaltedSipHasher> LegacyScriptPubKeyMan::GetNotMineSc
17631763
return spks;
17641764
}
17651765

1766-
std::optional<MigrationData> LegacyScriptPubKeyMan::MigrateToDescriptor()
1766+
std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
17671767
{
17681768
LOCK(cs_KeyStore);
17691769
if (m_storage.IsLocked()) {
@@ -1830,7 +1830,7 @@ std::optional<MigrationData> LegacyScriptPubKeyMan::MigrateToDescriptor()
18301830
WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
18311831

18321832
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
1833-
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size));
1833+
auto desc_spk_man = std::make_unique<DescriptorScriptPubKeyMan>(m_storage, w_desc, /*keypool_size=*/0);
18341834
desc_spk_man->AddDescriptorKey(key, key.GetPubKey());
18351835
desc_spk_man->TopUp();
18361836
auto desc_spks = desc_spk_man->GetScriptPubKeys();
@@ -1875,7 +1875,7 @@ std::optional<MigrationData> LegacyScriptPubKeyMan::MigrateToDescriptor()
18751875
WalletDescriptor w_desc(std::move(desc), 0, 0, chain_counter, 0);
18761876

18771877
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
1878-
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size));
1878+
auto desc_spk_man = std::make_unique<DescriptorScriptPubKeyMan>(m_storage, w_desc, /*keypool_size=*/0);
18791879
desc_spk_man->AddDescriptorKey(master_key.key, master_key.key.GetPubKey());
18801880
desc_spk_man->TopUp();
18811881
auto desc_spks = desc_spk_man->GetScriptPubKeys();
@@ -1937,7 +1937,7 @@ std::optional<MigrationData> LegacyScriptPubKeyMan::MigrateToDescriptor()
19371937
} else {
19381938
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
19391939
WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
1940-
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size));
1940+
auto desc_spk_man = std::make_unique<DescriptorScriptPubKeyMan>(m_storage, w_desc, /*keypool_size=*/0);
19411941
for (const auto& keyid : privkeyids) {
19421942
CKey key;
19431943
if (!GetKey(keyid, key)) {
@@ -2015,7 +2015,7 @@ std::optional<MigrationData> LegacyScriptPubKeyMan::MigrateToDescriptor()
20152015
return out;
20162016
}
20172017

2018-
bool LegacyScriptPubKeyMan::DeleteRecords()
2018+
bool LegacyDataSPKM::DeleteRecords()
20192019
{
20202020
LOCK(cs_KeyStore);
20212021
WalletBatch batch(m_storage.GetDatabase());

src/wallet/scriptpubkeyman.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,18 @@ class LegacyDataSPKM : public ScriptPubKeyMan, public FillableSigningProvider
354354

355355
//! Fetches a pubkey from mapWatchKeys if it exists there
356356
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const;
357+
358+
/**
359+
* Retrieves scripts that were imported by bugs into the legacy spkm and are
360+
* simply invalid, such as a sh(sh(pkh())) script, or not watched.
361+
*/
362+
std::unordered_set<CScript, SaltedSipHasher> GetNotMineScriptPubKeys() const;
363+
364+
/** Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyScriptPubKeyMan.
365+
* Does not modify this ScriptPubKeyMan. */
366+
std::optional<MigrationData> MigrateToDescriptor();
367+
/** Delete all the records ofthis LegacyScriptPubKeyMan from disk*/
368+
bool DeleteRecords();
357369
};
358370

359371
// Implements the full legacy wallet behavior
@@ -548,18 +560,6 @@ class LegacyScriptPubKeyMan : public LegacyDataSPKM
548560
const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
549561

550562
std::set<CKeyID> GetKeys() const override;
551-
552-
/**
553-
* Retrieves scripts that were imported by bugs into the legacy spkm and are
554-
* simply invalid, such as a sh(sh(pkh())) script, or not watched.
555-
*/
556-
std::unordered_set<CScript, SaltedSipHasher> GetNotMineScriptPubKeys() const;
557-
558-
/** Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyScriptPubKeyMan.
559-
* Does not modify this ScriptPubKeyMan. */
560-
std::optional<MigrationData> MigrateToDescriptor();
561-
/** Delete all the records ofthis LegacyScriptPubKeyMan from disk*/
562-
bool DeleteRecords();
563563
};
564564

565565
/** Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr. Does not provide privkeys */

0 commit comments

Comments
 (0)