mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-13 10:21:34 +02:00
Split SetActiveScriptPubKeyMan into Add/LoadActiveScriptPubKeyMan
Remove the memonly bool and follow the Add and Load pattern we use everywhere else.
This commit is contained in:
parent
0122fbab4c
commit
d9cd095b59
@ -1568,7 +1568,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
|
|||||||
if (!w_desc.descriptor->GetOutputType()) {
|
if (!w_desc.descriptor->GetOutputType()) {
|
||||||
warnings.push_back("Unknown output type, cannot set descriptor to active.");
|
warnings.push_back("Unknown output type, cannot set descriptor to active.");
|
||||||
} else {
|
} else {
|
||||||
pwallet->SetActiveScriptPubKeyMan(spk_manager->GetID(), *w_desc.descriptor->GetOutputType(), internal);
|
pwallet->AddActiveScriptPubKeyMan(spk_manager->GetID(), *w_desc.descriptor->GetOutputType(), internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4374,12 +4374,21 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
|
|||||||
spk_manager->SetupDescriptorGeneration(master_key, t);
|
spk_manager->SetupDescriptorGeneration(master_key, t);
|
||||||
uint256 id = spk_manager->GetID();
|
uint256 id = spk_manager->GetID();
|
||||||
m_spk_managers[id] = std::move(spk_manager);
|
m_spk_managers[id] = std::move(spk_manager);
|
||||||
SetActiveScriptPubKeyMan(id, t, internal);
|
AddActiveScriptPubKeyMan(id, t, internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal, bool memonly)
|
void CWallet::AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
|
||||||
|
{
|
||||||
|
WalletBatch batch(*database);
|
||||||
|
if (!batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(type), id, internal)) {
|
||||||
|
throw std::runtime_error(std::string(__func__) + ": writing active ScriptPubKeyMan id failed");
|
||||||
|
}
|
||||||
|
LoadActiveScriptPubKeyMan(id, type, internal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWallet::LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
|
||||||
{
|
{
|
||||||
WalletLogPrintf("Setting spkMan to active: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
|
WalletLogPrintf("Setting spkMan to active: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
|
||||||
auto& spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers;
|
auto& spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers;
|
||||||
@ -4387,12 +4396,6 @@ void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool interna
|
|||||||
spk_man->SetInternal(internal);
|
spk_man->SetInternal(internal);
|
||||||
spk_mans[type] = spk_man;
|
spk_mans[type] = spk_man;
|
||||||
|
|
||||||
if (!memonly) {
|
|
||||||
WalletBatch batch(*database);
|
|
||||||
if (!batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(type), id, internal)) {
|
|
||||||
throw std::runtime_error(std::string(__func__) + ": writing active ScriptPubKeyMan id failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NotifyCanGetAddressesChanged();
|
NotifyCanGetAddressesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1252,12 +1252,17 @@ public:
|
|||||||
//! Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it
|
//! Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it
|
||||||
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc);
|
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc);
|
||||||
|
|
||||||
//! Sets the active ScriptPubKeyMan for the specified type and internal
|
//! Adds the active ScriptPubKeyMan for the specified type and internal. Writes it to the wallet file
|
||||||
//! @param[in] id The unique id for the ScriptPubKeyMan
|
//! @param[in] id The unique id for the ScriptPubKeyMan
|
||||||
//! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
|
//! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
|
||||||
//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
|
//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
|
||||||
//! @param[in] memonly Whether to record this update to the database. Set to true for wallet loading, normally false when actually updating the wallet.
|
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
|
||||||
void SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal, bool memonly = false);
|
|
||||||
|
//! Loads an active ScriptPubKeyMan for the specified type and internal. (used by LoadWallet)
|
||||||
|
//! @param[in] id The unique id for the ScriptPubKeyMan
|
||||||
|
//! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
|
||||||
|
//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
|
||||||
|
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
|
||||||
|
|
||||||
//! Create new DescriptorScriptPubKeyMans and add them to the wallet
|
//! Create new DescriptorScriptPubKeyMans and add them to the wallet
|
||||||
void SetupDescriptorScriptPubKeyMans();
|
void SetupDescriptorScriptPubKeyMans();
|
||||||
|
@ -748,10 +748,10 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
|||||||
|
|
||||||
// Set the active ScriptPubKeyMans
|
// Set the active ScriptPubKeyMans
|
||||||
for (auto spk_man_pair : wss.m_active_external_spks) {
|
for (auto spk_man_pair : wss.m_active_external_spks) {
|
||||||
pwallet->SetActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ false, /* memonly */ true);
|
pwallet->LoadActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ false);
|
||||||
}
|
}
|
||||||
for (auto spk_man_pair : wss.m_active_internal_spks) {
|
for (auto spk_man_pair : wss.m_active_internal_spks) {
|
||||||
pwallet->SetActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ true, /* memonly */ true);
|
pwallet->LoadActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the descriptor caches
|
// Set the descriptor caches
|
||||||
|
Loading…
x
Reference in New Issue
Block a user