Skip to content

Commit 18be394

Browse files
author
João Barbosa
committed
Add lockUnspents option to fundrawtransaction
1 parent db992ea commit 18be394

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
24572457
" \"changeAddress\" (string, optional, default pool address) The bitcoin address to receive the change\n"
24582458
" \"changePosition\" (numeric, optional, default random) The index of the change output\n"
24592459
" \"includeWatching\" (boolean, optional, default false) Also select inputs which are watch only\n"
2460+
" \"lockUnspents\" (boolean, optional, default false) Lock selected unspent outputs\n"
24602461
" }\n"
24612462
" for backward compatibility: passing in a true instzead of an object will result in {\"includeWatching\":true}\n"
24622463
"\nResult:\n"
@@ -2482,6 +2483,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
24822483
CTxDestination changeAddress = CNoDestination();
24832484
int changePosition = -1;
24842485
bool includeWatching = false;
2486+
bool lockUnspents = false;
24852487

24862488
if (params.size() > 1) {
24872489
if (params[1].type() == UniValue::VBOOL) {
@@ -2493,7 +2495,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
24932495

24942496
UniValue options = params[1];
24952497

2496-
RPCTypeCheckObj(options, boost::assign::map_list_of("changeAddress", UniValue::VSTR)("changePosition", UniValue::VNUM)("includeWatching", UniValue::VBOOL), true, true);
2498+
RPCTypeCheckObj(options, boost::assign::map_list_of("changeAddress", UniValue::VSTR)("changePosition", UniValue::VNUM)("includeWatching", UniValue::VBOOL)("lockUnspents", UniValue::VBOOL), true, true);
24972499

24982500
if (options.exists("changeAddress")) {
24992501
CBitcoinAddress address(options["changeAddress"].get_str());
@@ -2509,6 +2511,9 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
25092511

25102512
if (options.exists("includeWatching"))
25112513
includeWatching = options["includeWatching"].get_bool();
2514+
2515+
if (options.exists("lockUnspents"))
2516+
lockUnspents = options["lockUnspents"].get_bool();
25122517
}
25132518
}
25142519

@@ -2527,7 +2532,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
25272532
CAmount nFee;
25282533
string strFailReason;
25292534

2530-
if(!pwalletMain->FundTransaction(tx, nFee, changePosition, strFailReason, includeWatching, changeAddress))
2535+
if(!pwalletMain->FundTransaction(tx, nFee, changePosition, strFailReason, includeWatching, lockUnspents, changeAddress))
25312536
throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason);
25322537

25332538
UniValue result(UniValue::VOBJ);

src/wallet/wallet.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ bool CWallet::SelectCoins(const vector<COutput>& vAvailableCoins, const CAmount&
19321932
return res;
19331933
}
19341934

1935-
bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool includeWatching, const CTxDestination& destChange)
1935+
bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool includeWatching, bool lockUnspents, const CTxDestination& destChange)
19361936
{
19371937
vector<CRecipient> vecSend;
19381938

@@ -1962,7 +1962,15 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
19621962
BOOST_FOREACH(const CTxIn& txin, wtx.vin)
19631963
{
19641964
if (!coinControl.IsSelected(txin.prevout))
1965+
{
19651966
tx.vin.push_back(txin);
1967+
1968+
if (lockUnspents)
1969+
{
1970+
LOCK2(cs_main, cs_wallet);
1971+
LockCoin(txin.prevout);
1972+
}
1973+
}
19661974
}
19671975

19681976
return true;

src/wallet/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
667667
bool IsSpent(const uint256& hash, unsigned int n) const;
668668

669669
bool IsLockedCoin(uint256 hash, unsigned int n) const;
670-
void LockCoin(COutPoint& output);
671-
void UnlockCoin(COutPoint& output);
670+
void LockCoin(const COutPoint& output);
671+
void UnlockCoin(const COutPoint& output);
672672
void UnlockAllCoins();
673673
void ListLockedCoins(std::vector<COutPoint>& vOutpts);
674674

@@ -739,7 +739,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
739739
* Insert additional inputs into the transaction by
740740
* calling CreateTransaction();
741741
*/
742-
bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool includeWatching, const CTxDestination& destChange = CNoDestination());
742+
bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool includeWatching, bool lockUnspents, const CTxDestination& destChange = CNoDestination());
743743

744744
/**
745745
* Create a new transaction paying the recipients with a set of coins

0 commit comments

Comments
 (0)