From 37fd22772f3fcc9b606782ac1083551bdd184e40 Mon Sep 17 00:00:00 2001 From: Chris Moore Date: Sat, 1 Feb 2014 08:06:22 -0800 Subject: [PATCH 1/5] Allow a fixed list of change addresses. Conflicts: src/wallet.cpp --- src/wallet.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wallet.cpp b/src/wallet.cpp index fb9c61f7c..bd9d901cc 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1397,6 +1397,20 @@ 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 + else if (mapArgs.count("-change") && mapMultiArgs["-change"].size() > 0) + { + CBitcoinAddress address(mapMultiArgs["-change"][GetRandInt(mapMultiArgs["-change"].size())]); + + CKeyID keyID; + if (!address.GetKeyID(keyID)) { + strFailReason = _("Bad change address"); + return false; + } + + scriptChange.SetDestination(keyID); + } // no coin control: send change to newly generated address else From fa3a670560550ab04e4b888009a7a732304679ff Mon Sep 17 00:00:00 2001 From: Chris Moore Date: Thu, 6 Feb 2014 12:11:42 -0800 Subject: [PATCH 2/5] Document the -change option. Conflicts: src/init.cpp --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index cf66ce1f0..f005e87d8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -207,6 +207,7 @@ std::string HelpMessage(HelpMessageMode hmm) strUsage += " -maxconnections= " + _("Maintain at most connections to peers (default: 125)") + "\n"; strUsage += " -addnode= " + _("Add a node to connect to and attempt to keep the connection open") + "\n"; strUsage += " -connect= " + _("Connect only to the specified node(s)") + "\n"; + strUsage += " -change=
" + _("Send change only to the specified address(es)") + "\n" + strUsage += " -seednode= " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n"; strUsage += " -externalip= " + _("Specify your own public address") + "\n"; strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Tor)") + "\n"; From 0f1f94b08ee95d5e005e5dce0226e33ccad258fd Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 6 Apr 2014 11:37:20 +0100 Subject: [PATCH 3/5] Reworked fixed change address handling to parse addresses on init and store in a vector within the wallet code. --- src/init.cpp | 21 +++++++++++++++++++-- src/wallet.cpp | 22 ++++++++++++---------- src/wallet.h | 3 +++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index f005e87d8..78245f9d7 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" @@ -207,7 +210,6 @@ std::string HelpMessage(HelpMessageMode hmm) strUsage += " -maxconnections= " + _("Maintain at most connections to peers (default: 125)") + "\n"; strUsage += " -addnode= " + _("Add a node to connect to and attempt to keep the connection open") + "\n"; strUsage += " -connect= " + _("Connect only to the specified node(s)") + "\n"; - strUsage += " -change=
" + _("Send change only to the specified address(es)") + "\n" + strUsage += " -seednode= " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n"; strUsage += " -externalip= " + _("Specify your own public address") + "\n"; strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Tor)") + "\n"; @@ -220,7 +222,7 @@ std::string HelpMessage(HelpMessageMode hmm) strUsage += " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n"; strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; - strUsage += " -bloomfilters " + _("Allow peers to set bloom filters (default: 1)") + "\n" + + strUsage += " -bloomfilters " + _("Allow peers to set bloom filters (default: 1)") + "\n" + #ifdef USE_UPNP #if USE_UPNP strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n"; @@ -278,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"; @@ -559,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 bd9d901cc..87b5d457e 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -18,6 +18,7 @@ using namespace std; // Settings int64_t nTransactionFee = 0; bool bSpendZeroConfChange = true; +static std::vector vChangeAddresses; ////////////////////////////////////////////////////////////////////////////// // @@ -1398,17 +1399,10 @@ bool CWallet::CreateTransaction(const vector >& vecSend, if (coinControl && !boost::get(&coinControl->destChange)) scriptChange.SetDestination(coinControl->destChange); - // send change to one of the specified change addresses - else if (mapArgs.count("-change") && mapMultiArgs["-change"].size() > 0) + // send change to one of the specified change addresses, if specified at init + else if (vChangeAddresses.size()) { - CBitcoinAddress address(mapMultiArgs["-change"][GetRandInt(mapMultiArgs["-change"].size())]); - - CKeyID keyID; - if (!address.GetKeyID(keyID)) { - strFailReason = _("Bad change address"); - return false; - } - + CKeyID keyID = vChangeAddresses[GetRandInt(vChangeAddresses.size())]; scriptChange.SetDestination(keyID); } @@ -2197,3 +2191,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); +} \ No newline at end of file diff --git a/src/wallet.h b/src/wallet.h index 6af0f8f7e..dec3ed22d 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -53,6 +53,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 { From 7b9fd3c0250d7f8d7ebf465b55940cbfc9892442 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 6 Apr 2014 11:50:02 +0100 Subject: [PATCH 4/5] Reverted accidental change to indentation. --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 78245f9d7..c8d243dd8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -222,7 +222,7 @@ std::string HelpMessage(HelpMessageMode hmm) strUsage += " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n"; strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; - strUsage += " -bloomfilters " + _("Allow peers to set bloom filters (default: 1)") + "\n" + + strUsage += " -bloomfilters " + _("Allow peers to set bloom filters (default: 1)") + "\n" + #ifdef USE_UPNP #if USE_UPNP strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n"; From 0282a9e112e0d5c124ff25ae3bc0c58cbf4438c5 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 6 Apr 2014 11:59:00 +0100 Subject: [PATCH 5/5] Added Dogecoin copyright notice to wallet.cpp and wallet.h as modified files. Removed comment about coin control from wallet.cpp as out of date. --- src/wallet.cpp | 5 +++-- src/wallet.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index 87b5d457e..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. @@ -1406,7 +1407,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, 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. @@ -2198,4 +2199,4 @@ bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, st void AddFixedChangeAddress(const CKeyID &changeAddress) { vChangeAddresses.push_back(changeAddress); -} \ No newline at end of file +} diff --git a/src/wallet.h b/src/wallet.h index dec3ed22d..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