Skip to content

Commit 891c5ee

Browse files
committed
Wallet: Refactor FundTransaction to accept parameters via CCoinControl
1 parent 578ec80 commit 891c5ee

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "timedata.h"
2222
#include "util.h"
2323
#include "utilmoneystr.h"
24+
#include "wallet/coincontrol.h"
2425
#include "wallet/feebumper.h"
2526
#include "wallet/wallet.h"
2627
#include "wallet/walletdb.h"
@@ -2678,20 +2679,21 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
26782679

26792680
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR));
26802681

2681-
CTxDestination changeAddress = CNoDestination();
2682+
CCoinControl coinControl;
2683+
coinControl.destChange = CNoDestination();
26822684
int changePosition = -1;
2683-
bool includeWatching = false;
2685+
coinControl.fAllowWatchOnly = false; // include watching
26842686
bool lockUnspents = false;
26852687
bool reserveChangeKey = true;
2686-
CFeeRate feeRate = CFeeRate(0);
2687-
bool overrideEstimatedFeerate = false;
2688+
coinControl.nFeeRate = CFeeRate(0);
2689+
coinControl.fOverrideFeeRate = false;
26882690
UniValue subtractFeeFromOutputs;
26892691
std::set<int> setSubtractFeeFromOutputs;
26902692

26912693
if (request.params.size() > 1) {
26922694
if (request.params[1].type() == UniValue::VBOOL) {
26932695
// backward compatibility bool only fallback
2694-
includeWatching = request.params[1].get_bool();
2696+
coinControl.fAllowWatchOnly = request.params[1].get_bool();
26952697
}
26962698
else {
26972699
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VOBJ));
@@ -2716,14 +2718,14 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
27162718
if (!address.IsValid())
27172719
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "changeAddress must be a valid bitcoin address");
27182720

2719-
changeAddress = address.Get();
2721+
coinControl.destChange = address.Get();
27202722
}
27212723

27222724
if (options.exists("changePosition"))
27232725
changePosition = options["changePosition"].get_int();
27242726

27252727
if (options.exists("includeWatching"))
2726-
includeWatching = options["includeWatching"].get_bool();
2728+
coinControl.fAllowWatchOnly = options["includeWatching"].get_bool();
27272729

27282730
if (options.exists("lockUnspents"))
27292731
lockUnspents = options["lockUnspents"].get_bool();
@@ -2733,8 +2735,8 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
27332735

27342736
if (options.exists("feeRate"))
27352737
{
2736-
feeRate = CFeeRate(AmountFromValue(options["feeRate"]));
2737-
overrideEstimatedFeerate = true;
2738+
coinControl.nFeeRate = CFeeRate(AmountFromValue(options["feeRate"]));
2739+
coinControl.fOverrideFeeRate = true;
27382740
}
27392741

27402742
if (options.exists("subtractFeeFromOutputs"))
@@ -2767,7 +2769,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
27672769
CAmount nFeeOut;
27682770
std::string strFailReason;
27692771

2770-
if (!pwallet->FundTransaction(tx, nFeeOut, overrideEstimatedFeerate, feeRate, changePosition, strFailReason, includeWatching, lockUnspents, setSubtractFeeFromOutputs, reserveChangeKey, changeAddress)) {
2772+
if (!pwallet->FundTransaction(tx, nFeeOut, changePosition, strFailReason, lockUnspents, setSubtractFeeFromOutputs, coinControl, reserveChangeKey)) {
27712773
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
27722774
}
27732775

src/wallet/wallet.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ bool CWallet::SignTransaction(CMutableTransaction &tx)
24142414
return true;
24152415
}
24162416

2417-
bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool overrideEstimatedFeeRate, const CFeeRate& specificFeeRate, int& nChangePosInOut, std::string& strFailReason, bool includeWatching, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, bool keepReserveKey, const CTxDestination& destChange)
2417+
bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl coinControl, bool keepReserveKey)
24182418
{
24192419
std::vector<CRecipient> vecSend;
24202420

@@ -2426,12 +2426,7 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool ov
24262426
vecSend.push_back(recipient);
24272427
}
24282428

2429-
CCoinControl coinControl;
2430-
coinControl.destChange = destChange;
24312429
coinControl.fAllowOtherInputs = true;
2432-
coinControl.fAllowWatchOnly = includeWatching;
2433-
coinControl.fOverrideFeeRate = overrideEstimatedFeeRate;
2434-
coinControl.nFeeRate = specificFeeRate;
24352430

24362431
BOOST_FOREACH(const CTxIn& txin, tx.vin)
24372432
coinControl.Select(txin.prevout);

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
935935
* Insert additional inputs into the transaction by
936936
* calling CreateTransaction();
937937
*/
938-
bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool overrideEstimatedFeeRate, const CFeeRate& specificFeeRate, int& nChangePosInOut, std::string& strFailReason, bool includeWatching, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, bool keepReserveKey = true, const CTxDestination& destChange = CNoDestination());
938+
bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl, bool keepReserveKey = true);
939939
bool SignTransaction(CMutableTransaction& tx);
940940

941941
/**

0 commit comments

Comments
 (0)