Skip to content

Commit d9cd095

Browse files
committed
Split SetActiveScriptPubKeyMan into Add/LoadActiveScriptPubKeyMan
Remove the memonly bool and follow the Add and Load pattern we use everywhere else.
1 parent 0122fba commit d9cd095

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
15681568
if (!w_desc.descriptor->GetOutputType()) {
15691569
warnings.push_back("Unknown output type, cannot set descriptor to active.");
15701570
} else {
1571-
pwallet->SetActiveScriptPubKeyMan(spk_manager->GetID(), *w_desc.descriptor->GetOutputType(), internal);
1571+
pwallet->AddActiveScriptPubKeyMan(spk_manager->GetID(), *w_desc.descriptor->GetOutputType(), internal);
15721572
}
15731573
}
15741574

src/wallet/wallet.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,25 +4374,28 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
43744374
spk_manager->SetupDescriptorGeneration(master_key, t);
43754375
uint256 id = spk_manager->GetID();
43764376
m_spk_managers[id] = std::move(spk_manager);
4377-
SetActiveScriptPubKeyMan(id, t, internal);
4377+
AddActiveScriptPubKeyMan(id, t, internal);
43784378
}
43794379
}
43804380
}
43814381

4382-
void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal, bool memonly)
4382+
void CWallet::AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
4383+
{
4384+
WalletBatch batch(*database);
4385+
if (!batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(type), id, internal)) {
4386+
throw std::runtime_error(std::string(__func__) + ": writing active ScriptPubKeyMan id failed");
4387+
}
4388+
LoadActiveScriptPubKeyMan(id, type, internal);
4389+
}
4390+
4391+
void CWallet::LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
43834392
{
43844393
WalletLogPrintf("Setting spkMan to active: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
43854394
auto& spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers;
43864395
auto spk_man = m_spk_managers.at(id).get();
43874396
spk_man->SetInternal(internal);
43884397
spk_mans[type] = spk_man;
43894398

4390-
if (!memonly) {
4391-
WalletBatch batch(*database);
4392-
if (!batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(type), id, internal)) {
4393-
throw std::runtime_error(std::string(__func__) + ": writing active ScriptPubKeyMan id failed");
4394-
}
4395-
}
43964399
NotifyCanGetAddressesChanged();
43974400
}
43984401

src/wallet/wallet.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,12 +1252,17 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
12521252
//! Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it
12531253
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc);
12541254

1255-
//! Sets the active ScriptPubKeyMan for the specified type and internal
1255+
//! Adds the active ScriptPubKeyMan for the specified type and internal. Writes it to the wallet file
12561256
//! @param[in] id The unique id for the ScriptPubKeyMan
12571257
//! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
12581258
//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
1259-
//! @param[in] memonly Whether to record this update to the database. Set to true for wallet loading, normally false when actually updating the wallet.
1260-
void SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal, bool memonly = false);
1259+
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1260+
1261+
//! Loads an active ScriptPubKeyMan for the specified type and internal. (used by LoadWallet)
1262+
//! @param[in] id The unique id for the ScriptPubKeyMan
1263+
//! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
1264+
//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
1265+
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
12611266

12621267
//! Create new DescriptorScriptPubKeyMans and add them to the wallet
12631268
void SetupDescriptorScriptPubKeyMans();

src/wallet/walletdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,10 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
748748

749749
// Set the active ScriptPubKeyMans
750750
for (auto spk_man_pair : wss.m_active_external_spks) {
751-
pwallet->SetActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ false, /* memonly */ true);
751+
pwallet->LoadActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ false);
752752
}
753753
for (auto spk_man_pair : wss.m_active_internal_spks) {
754-
pwallet->SetActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ true, /* memonly */ true);
754+
pwallet->LoadActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ true);
755755
}
756756

757757
// Set the descriptor caches

0 commit comments

Comments
 (0)