Merge pull request #420 from rnicoll/1.7-dev-change
Add support for sending change to a list of address(es)
This commit is contained in:
commit
1d7e75ed08
18
src/init.cpp
18
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=<file> " + _("Specify wallet file (within data directory)") + "\n";
|
||||
strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n";
|
||||
strUsage += " -change=<address> " + _("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");
|
||||
|
|
|
@ -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<CKeyID> vChangeAddresses;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
@ -1397,8 +1399,15 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
|||
// coin control: send change to custom address
|
||||
if (coinControl && !boost::get<CNoDestination>(&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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue