diff --git a/src/init.cpp b/src/init.cpp index cf66ce1f0..c8d243dd8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2,6 +2,7 @@ // Copyright (c) 2009-2014 The Bitcoin developers // Copyright (c) 2011-2013 The Litecoin developers // Copyright (c) 2014 The Inutoshi developers +// Copyright (c) 2014 The Dogecoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -12,7 +13,9 @@ #include "init.h" #include "addrman.h" +#include "base58.h" #include "checkpoints.h" +#include "key.h" #include "main.h" #include "miner.h" #include "net.h" @@ -277,6 +280,7 @@ std::string HelpMessage(HelpMessageMode hmm) strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + "\n"; strUsage += " -wallet= " + _("Specify wallet file (within data directory)") + "\n"; strUsage += " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; + strUsage += " -change=
" + _("Send change only to the specified address(es)") + "\n" + strUsage += " -spendzeroconfchange " + _("Spend unconfirmed change when sending transactions (default: 1)") + "\n"; #endif strUsage += "\n" + _("Block creation options:") + "\n"; @@ -558,6 +562,20 @@ bool AppInit2(boost::thread_group& threadGroup) if (nTransactionFee > 25 * COIN) InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction.")); } + + if (mapArgs.count("-change")) + { + BOOST_FOREACH(std::string strChange, mapMultiArgs["-change"]) { + CBitcoinAddress address(strChange); + CKeyID keyID; + + if (!address.GetKeyID(keyID)) { + return InitError(strprintf(_("Bad -change address: '%s'"), strChange)); + } + AddFixedChangeAddress(keyID); + } + } + bSpendZeroConfChange = GetArg("-spendzeroconfchange", true); strWalletFile = GetArg("-wallet", "wallet.dat"); diff --git a/src/wallet.cpp b/src/wallet.cpp index fb9c61f7c..c6bb835e5 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers +// Copyright (c) 2014 The Dogecoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -18,6 +19,7 @@ using namespace std; // Settings int64_t nTransactionFee = 0; bool bSpendZeroConfChange = true; +static std::vector vChangeAddresses; ////////////////////////////////////////////////////////////////////////////// // @@ -1397,8 +1399,15 @@ bool CWallet::CreateTransaction(const vector >& vecSend, // coin control: send change to custom address if (coinControl && !boost::get(&coinControl->destChange)) scriptChange.SetDestination(coinControl->destChange); + + // send change to one of the specified change addresses, if specified at init + else if (vChangeAddresses.size()) + { + CKeyID keyID = vChangeAddresses[GetRandInt(vChangeAddresses.size())]; + scriptChange.SetDestination(keyID); + } - // no coin control: send change to newly generated address + // send change to newly generated address else { // Note: We use a new key here to keep it from being obvious which side is the change. @@ -2183,3 +2192,11 @@ bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, st } return false; } + +// Add an address to the list of fixed change addresses to use. Fixed +// addresses can be used to reduce the pace at which wallets expand +// due to number of change addresses +void AddFixedChangeAddress(const CKeyID &changeAddress) +{ + vChangeAddresses.push_back(changeAddress); +} diff --git a/src/wallet.h b/src/wallet.h index 6af0f8f7e..a9fa811e3 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2014 The Dogecoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_WALLET_H @@ -53,6 +54,9 @@ static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) mapValue["n"] = i64tostr(nOrderPos); } +// Add an address to the list of fixed change addresses to use. +void AddFixedChangeAddress(const CKeyID &changeAddress); + /** (client) version numbers for particular wallet features */ enum WalletFeature {