Skip to content

Commit faddad7

Browse files
author
MarcoFalke
committed
Remove confusing OutputType::CHANGE_AUTO
1 parent fa2eb38 commit faddad7

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

src/outputtype.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ enum class OutputType {
1818
LEGACY,
1919
P2SH_SEGWIT,
2020
BECH32,
21-
22-
/**
23-
* Special output type for change outputs only. Automatically choose type
24-
* based on address type setting and the types other of non-change outputs
25-
* (see -changetype option documentation and implementation in
26-
* CWallet::TransactionChangeType for details).
27-
*/
28-
CHANGE_AUTO,
2921
};
3022

3123
extern const std::array<OutputType, 3> OUTPUT_TYPES;

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static UniValue getrawchangeaddress(const JSONRPCRequest& request)
306306
throw JSONRPCError(RPC_WALLET_ERROR, "Error: This wallet has no available keys");
307307
}
308308

309-
OutputType output_type = pwallet->m_default_change_type != OutputType::CHANGE_AUTO ? pwallet->m_default_change_type : pwallet->m_default_address_type;
309+
OutputType output_type = pwallet->m_default_change_type.get_value_or(pwallet->m_default_address_type);
310310
if (!request.params[0].isNull()) {
311311
if (!ParseOutputType(request.params[0].get_str(), output_type)) {
312312
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str()));
@@ -2993,10 +2993,11 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
29932993
if (options.exists("changeAddress")) {
29942994
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both changeAddress and address_type options");
29952995
}
2996-
coinControl.m_change_type = pwallet->m_default_change_type;
2997-
if (!ParseOutputType(options["change_type"].get_str(), *coinControl.m_change_type)) {
2996+
OutputType out_type;
2997+
if (!ParseOutputType(options["change_type"].get_str(), out_type)) {
29982998
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown change type '%s'", options["change_type"].get_str()));
29992999
}
3000+
coinControl.m_change_type.emplace(out_type);
30003001
}
30013002

30023003
coinControl.fAllowWatchOnly = ParseIncludeWatchonly(options["includeWatching"], *pwallet);

src/wallet/wallet.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,11 +2653,11 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uin
26532653
return locktime;
26542654
}
26552655

2656-
OutputType CWallet::TransactionChangeType(OutputType change_type, const std::vector<CRecipient>& vecSend)
2656+
OutputType CWallet::TransactionChangeType(const Optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend)
26572657
{
26582658
// If -changetype is specified, always use that change type.
2659-
if (change_type != OutputType::CHANGE_AUTO) {
2660-
return change_type;
2659+
if (change_type) {
2660+
return *change_type;
26612661
}
26622662

26632663
// if m_default_address_type is legacy, use legacy address as change (even
@@ -3826,14 +3826,20 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
38263826
}
38273827
}
38283828

3829-
if (!gArgs.GetArg("-addresstype", "").empty() && !ParseOutputType(gArgs.GetArg("-addresstype", ""), walletInstance->m_default_address_type)) {
3830-
error = strprintf(_("Unknown address type '%s'"), gArgs.GetArg("-addresstype", ""));
3831-
return nullptr;
3829+
if (!gArgs.GetArg("-addresstype", "").empty()) {
3830+
if (!ParseOutputType(gArgs.GetArg("-addresstype", ""), walletInstance->m_default_address_type)) {
3831+
error = strprintf(_("Unknown address type '%s'"), gArgs.GetArg("-addresstype", ""));
3832+
return nullptr;
3833+
}
38323834
}
38333835

3834-
if (!gArgs.GetArg("-changetype", "").empty() && !ParseOutputType(gArgs.GetArg("-changetype", ""), walletInstance->m_default_change_type)) {
3835-
error = strprintf(_("Unknown change type '%s'"), gArgs.GetArg("-changetype", ""));
3836-
return nullptr;
3836+
if (!gArgs.GetArg("-changetype", "").empty()) {
3837+
OutputType out_type;
3838+
if (!ParseOutputType(gArgs.GetArg("-changetype", ""), out_type)) {
3839+
error = strprintf(_("Unknown change type '%s'"), gArgs.GetArg("-changetype", ""));
3840+
return nullptr;
3841+
}
3842+
walletInstance->m_default_change_type = out_type;
38373843
}
38383844

38393845
if (gArgs.IsArgSet("-mintxfee")) {

src/wallet/wallet.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ class ReserveDestination;
105105
//! Default for -addresstype
106106
constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::BECH32};
107107

108-
//! Default for -changetype
109-
constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO};
110-
111108
static constexpr uint64_t KNOWN_WALLET_FLAGS =
112109
WALLET_FLAG_AVOID_REUSE
113110
| WALLET_FLAG_BLANK_WALLET
@@ -934,7 +931,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
934931
Balance GetBalance(int min_depth = 0, bool avoid_reuse = true) const;
935932
CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;
936933

937-
OutputType TransactionChangeType(OutputType change_type, const std::vector<CRecipient>& vecSend);
934+
OutputType TransactionChangeType(const Optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend);
938935

939936
/**
940937
* Insert additional inputs into the transaction by
@@ -1012,7 +1009,13 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
10121009
CFeeRate m_fallback_fee{DEFAULT_FALLBACK_FEE};
10131010
CFeeRate m_discard_rate{DEFAULT_DISCARD_FEE};
10141011
OutputType m_default_address_type{DEFAULT_ADDRESS_TYPE};
1015-
OutputType m_default_change_type{DEFAULT_CHANGE_TYPE};
1012+
/**
1013+
* Default output type for change outputs. When unset, automatically choose type
1014+
* based on address type setting and the types other of non-change outputs
1015+
* (see -changetype option documentation and implementation in
1016+
* CWallet::TransactionChangeType for details).
1017+
*/
1018+
Optional<OutputType> m_default_change_type{};
10161019
/** Absolute maximum transaction fee (in satoshis) used by default for the wallet */
10171020
CAmount m_default_max_tx_fee{DEFAULT_TRANSACTION_MAXFEE};
10181021

0 commit comments

Comments
 (0)