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.
pull/826/head
Andrew Chow 3 years ago
parent 0262536c34
commit 699dfcd8ad

@ -1909,7 +1909,13 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
int witnessversion = 0;
std::vector<unsigned char> 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;
}
}
}

Loading…
Cancel
Save