Skip to content

Commit 586f1d5

Browse files
committed
wallet: maintain SPK consistency on internal flag change
1 parent f1b7db1 commit 586f1d5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,12 +3153,21 @@ void CWallet::AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool interna
31533153

31543154
void CWallet::LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
31553155
{
3156+
// Activating ScriptPubKeyManager for a given output and change type is incompatible with legacy wallets.
3157+
// Legacy wallets have only one ScriptPubKeyManager and it's active for all output and change types.
3158+
Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
3159+
31563160
WalletLogPrintf("Setting spkMan to active: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
31573161
auto& spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers;
3162+
auto& spk_mans_other = internal ? m_external_spk_managers : m_internal_spk_managers;
31583163
auto spk_man = m_spk_managers.at(id).get();
31593164
spk_man->SetInternal(internal);
31603165
spk_mans[type] = spk_man;
31613166

3167+
if (spk_mans_other[type] == spk_man) {
3168+
spk_mans_other[type] = nullptr;
3169+
}
3170+
31623171
NotifyCanGetAddressesChanged();
31633172
}
31643173

0 commit comments

Comments
 (0)