diff options
author | Andrew Chow <achow101-github@achow101.com> | 2021-06-04 16:40:48 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2021-06-22 21:53:11 -0400 |
commit | 699dfcd8ad9487a4e04c1ffc68211e84e126b3d2 (patch) | |
tree | 32cb7d69dc0bcbe38064a0a429047960bb5c6b1b | |
parent | 0262536c34567743e527dad46912c9ba493252cd (diff) |
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.
-rw-r--r-- | src/wallet/wallet.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index fbda77ed62..0f69302697 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -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; + } } } |