Skip to content

Commit 70dcdd7

Browse files
committed
Wallet: Avoid using change types newer than user's preferred address type
1 parent bbbf89a commit 70dcdd7

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/wallet/test/util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
2020
{
2121
LOCK2(wallet->cs_wallet, ::cs_main);
2222
wallet->SetLastBlockProcessed(cchain.Height(), cchain.Tip()->GetBlockHash());
23+
wallet->m_default_address_type = OutputType::BECH32M;
2324
}
2425
wallet->LoadWallet();
2526
{

src/wallet/wallet.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,7 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
22672267
}
22682268

22692269
const bool has_bech32m_spkman(GetScriptPubKeyMan(OutputType::BECH32M, /*internal=*/true));
2270-
if (has_bech32m_spkman && any_tr) {
2270+
if (has_bech32m_spkman && any_tr && m_default_address_type == OutputType::BECH32M) {
22712271
// Currently tr is the only type supported by the BECH32M spkman
22722272
return OutputType::BECH32M;
22732273
}
@@ -2287,6 +2287,16 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
22872287
// Currently pkh is the only type supported by the LEGACY spkman
22882288
return OutputType::LEGACY;
22892289
}
2290+
if (!GetScriptPubKeyMan(m_default_address_type, /*internal=*/true)) {
2291+
// Default type not available, so look for anything else to fallback to
2292+
// NOTE: Sane behaviour assumes OUTPUT_TYPES is sorted oldest to newest
2293+
for (const auto& ot : OUTPUT_TYPES) {
2294+
if (GetScriptPubKeyMan(ot, /*internal=*/true)) {
2295+
return ot;
2296+
}
2297+
}
2298+
}
2299+
return m_default_address_type;
22902300

22912301
if (has_bech32m_spkman) {
22922302
return OutputType::BECH32M;

test/functional/wallet_taproot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ def set_test_params(self):
194194
self.num_nodes = 2
195195
self.setup_clean_chain = True
196196
self.extra_args = [['-keypool=100'], ['-keypool=100']]
197+
for ea in self.extra_args:
198+
ea.append('-addresstype=bech32m')
197199
self.supports_cli = False
198200

199201
def skip_test_if_missing_module(self):

0 commit comments

Comments
 (0)