@@ -1807,6 +1807,12 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
1807
1807
keyid_it++;
1808
1808
}
1809
1809
1810
+ WalletBatch batch (m_storage.GetDatabase ());
1811
+ if (!batch.TxnBegin ()) {
1812
+ LogPrintf (" Error generating descriptors for migration, cannot initialize db transaction\n " );
1813
+ return std::nullopt;
1814
+ }
1815
+
1810
1816
// keyids is now all non-HD keys. Each key will have its own combo descriptor
1811
1817
for (const CKeyID& keyid : keyids) {
1812
1818
CKey key;
@@ -1837,8 +1843,8 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
1837
1843
1838
1844
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
1839
1845
auto desc_spk_man = std::make_unique<DescriptorScriptPubKeyMan>(m_storage, w_desc, /* keypool_size=*/ 0 );
1840
- desc_spk_man->AddDescriptorKey ( key, key.GetPubKey ());
1841
- desc_spk_man->TopUp ( );
1846
+ WITH_LOCK ( desc_spk_man->cs_desc_man , desc_spk_man-> AddDescriptorKeyWithDB (batch, key, key.GetPubKey () ));
1847
+ desc_spk_man->TopUpWithDB (batch );
1842
1848
auto desc_spks = desc_spk_man->GetScriptPubKeys ();
1843
1849
1844
1850
// Remove the scriptPubKeys from our current set
@@ -1883,8 +1889,8 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
1883
1889
1884
1890
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
1885
1891
auto desc_spk_man = std::make_unique<DescriptorScriptPubKeyMan>(m_storage, w_desc, /* keypool_size=*/ 0 );
1886
- desc_spk_man->AddDescriptorKey ( master_key.key , master_key.key .GetPubKey ());
1887
- desc_spk_man->TopUp ( );
1892
+ WITH_LOCK ( desc_spk_man->cs_desc_man , desc_spk_man-> AddDescriptorKeyWithDB (batch, master_key.key , master_key.key .GetPubKey () ));
1893
+ desc_spk_man->TopUpWithDB (batch );
1888
1894
auto desc_spks = desc_spk_man->GetScriptPubKeys ();
1889
1895
1890
1896
// Remove the scriptPubKeys from our current set
@@ -1950,9 +1956,9 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
1950
1956
if (!GetKey (keyid, key)) {
1951
1957
continue ;
1952
1958
}
1953
- desc_spk_man->AddDescriptorKey ( key, key.GetPubKey ());
1959
+ WITH_LOCK ( desc_spk_man->cs_desc_man , desc_spk_man-> AddDescriptorKeyWithDB (batch, key, key.GetPubKey () ));
1954
1960
}
1955
- desc_spk_man->TopUp ( );
1961
+ desc_spk_man->TopUpWithDB (batch );
1956
1962
auto desc_spks_set = desc_spk_man->GetScriptPubKeys ();
1957
1963
desc_spks.insert (desc_spks.end (), desc_spks_set.begin (), desc_spks_set.end ());
1958
1964
@@ -2019,6 +2025,13 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
2019
2025
2020
2026
// Make sure that we have accounted for all scriptPubKeys
2021
2027
assert (spks.size () == 0 );
2028
+
2029
+ // Finalize transaction
2030
+ if (!batch.TxnCommit ()) {
2031
+ LogPrintf (" Error generating descriptors for migration, cannot commit db transaction\n " );
2032
+ return std::nullopt;
2033
+ }
2034
+
2022
2035
return out;
2023
2036
}
2024
2037
0 commit comments