Skip to content

Commit 699dfcd

Browse files
committed
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.
1 parent 0262536 commit 699dfcd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,13 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
19091909
int witnessversion = 0;
19101910
std::vector<unsigned char> witnessprogram;
19111911
if (recipient.scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
1912-
return OutputType::BECH32;
1912+
if (GetScriptPubKeyMan(OutputType::BECH32M, true)) {
1913+
return OutputType::BECH32M;
1914+
} else if (GetScriptPubKeyMan(OutputType::BECH32, true)) {
1915+
return OutputType::BECH32;
1916+
} else {
1917+
return m_default_address_type;
1918+
}
19131919
}
19141920
}
19151921

0 commit comments

Comments
 (0)