From 699dfcd8ad9487a4e04c1ffc68211e84e126b3d2 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Fri, 4 Jun 2021 16:40:48 -0400 Subject: [PATCH] Opportunistically use bech32m change addresses if available If a transaction as a segwit output, use a bech32m change address if they are available. If not, fallback to bech32. If bech32 change addresses are unavailable, fallback to the default address type. --- src/wallet/wallet.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index fbda77ed62c..0f693026971 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1909,7 +1909,13 @@ OutputType CWallet::TransactionChangeType(const std::optional& chang int witnessversion = 0; std::vector witnessprogram; if (recipient.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) { - return OutputType::BECH32; + if (GetScriptPubKeyMan(OutputType::BECH32M, true)) { + return OutputType::BECH32M; + } else if (GetScriptPubKeyMan(OutputType::BECH32, true)) { + return OutputType::BECH32; + } else { + return m_default_address_type; + } } }