diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -305,6 +305,7 @@ libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_wallet_a_SOURCES = \ interfaces/wallet.cpp \ + wallet/coincontrol.cpp \ wallet/crypter.cpp \ wallet/coinselection.cpp \ wallet/db.cpp \ diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(wallet ../interfaces/wallet.cpp + coincontrol.cpp coinselection.cpp crypter.cpp db.cpp diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -26,18 +26,12 @@ boost::optional m_feerate; //! Override the default confirmation target if set boost::optional m_confirm_target; + //! Avoid partial use of funds sent to a given address + bool m_avoid_partial_spends; CCoinControl() { SetNull(); } - void SetNull() { - destChange = CNoDestination(); - fAllowOtherInputs = false; - fAllowWatchOnly = false; - setSelected.clear(); - m_feerate.reset(); - fOverrideFeeRate = false; - m_confirm_target.reset(); - } + void SetNull(); bool HasSelected() const { return (setSelected.size() > 0); } diff --git a/src/wallet/coincontrol.cpp b/src/wallet/coincontrol.cpp new file mode 100644 --- /dev/null +++ b/src/wallet/coincontrol.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + +void CCoinControl::SetNull() { + destChange = CNoDestination(); + fAllowOtherInputs = false; + fAllowWatchOnly = false; + m_avoid_partial_spends = + gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS); + setSelected.clear(); + m_feerate.reset(); + fOverrideFeeRate = false; + m_confirm_target.reset(); +} diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -53,6 +53,17 @@ const WalletInitInterface &g_wallet_init_interface = WalletInit(); void WalletInit::AddWalletOptions() const { + gArgs.AddArg( + "-avoidpartialspends", + strprintf(_("Group outputs by address, selecting all or none, instead " + "of selecting on a per-output basis. Privacy is improved " + "as an address is only used once (unless someone sends to " + "it after spending from it), but may result in slightly " + "higher fees as suboptimal coin selection may result due " + "to the added limitation (default: %u)"), + DEFAULT_AVOIDPARTIALSPENDS), + false, OptionsCategory::WALLET); + gArgs.AddArg("-disablewallet", _("Do not load the wallet and disable wallet RPC calls"), false, OptionsCategory::WALLET); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -47,6 +47,8 @@ static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; //! Default for -walletrejectlongchains static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false; +//! Default for -avoidpartialspends +static const bool DEFAULT_AVOIDPARTIALSPENDS = false; static const bool DEFAULT_WALLETBROADCAST = true; static const bool DEFAULT_DISABLE_WALLET = false;