Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 451 Lines • ▼ Show 20 Lines | static void SendMoney(CWallet *const pwallet, const CTxDestination &address, | ||||
CReserveKey reservekey(pwallet); | CReserveKey reservekey(pwallet); | ||||
Amount nFeeRequired; | Amount nFeeRequired; | ||||
std::string strError; | std::string strError; | ||||
std::vector<CRecipient> vecSend; | std::vector<CRecipient> vecSend; | ||||
int nChangePosRet = -1; | int nChangePosRet = -1; | ||||
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; | CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; | ||||
vecSend.push_back(recipient); | vecSend.push_back(recipient); | ||||
CCoinControl coinControl; | |||||
if (!pwallet->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, | if (!pwallet->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, | ||||
nChangePosRet, strError)) { | nChangePosRet, strError, coinControl)) { | ||||
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | ||||
strError = strprintf("Error: This transaction requires a " | strError = strprintf("Error: This transaction requires a " | ||||
"transaction fee of at least %s", | "transaction fee of at least %s", | ||||
FormatMoney(nFeeRequired)); | FormatMoney(nFeeRequired)); | ||||
} | } | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strError); | throw JSONRPCError(RPC_WALLET_ERROR, strError); | ||||
} | } | ||||
CValidationState state; | CValidationState state; | ||||
▲ Show 20 Lines • Show All 856 Lines • ▼ Show 20 Lines | if (totalAmount > nBalance) { | ||||
"Account has insufficient funds"); | "Account has insufficient funds"); | ||||
} | } | ||||
// Send | // Send | ||||
CReserveKey keyChange(pwallet); | CReserveKey keyChange(pwallet); | ||||
Amount nFeeRequired = Amount::zero(); | Amount nFeeRequired = Amount::zero(); | ||||
int nChangePosRet = -1; | int nChangePosRet = -1; | ||||
std::string strFailReason; | std::string strFailReason; | ||||
bool fCreated = pwallet->CreateTransaction( | CCoinControl coinControl; | ||||
vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason); | bool fCreated = | ||||
pwallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, | |||||
nChangePosRet, strFailReason, coinControl); | |||||
if (!fCreated) { | if (!fCreated) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); | ||||
} | } | ||||
CValidationState state; | CValidationState state; | ||||
if (!pwallet->CommitTransaction(wtx, keyChange, g_connman.get(), state)) { | if (!pwallet->CommitTransaction(wtx, keyChange, g_connman.get(), state)) { | ||||
strFailReason = strprintf("Transaction commit failed:: %s", | strFailReason = strprintf("Transaction commit failed:: %s", | ||||
state.GetRejectReason()); | state.GetRejectReason()); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | ||||
▲ Show 20 Lines • Show All 2,139 Lines • ▼ Show 20 Lines | static UniValue fundrawtransaction(const Config &config, | ||||
CCoinControl coinControl; | CCoinControl coinControl; | ||||
coinControl.destChange = CNoDestination(); | coinControl.destChange = CNoDestination(); | ||||
int changePosition = -1; | int changePosition = -1; | ||||
// include watching | // include watching | ||||
coinControl.fAllowWatchOnly = false; | coinControl.fAllowWatchOnly = false; | ||||
bool lockUnspents = false; | bool lockUnspents = false; | ||||
bool reserveChangeKey = true; | bool reserveChangeKey = true; | ||||
coinControl.nFeeRate = CFeeRate(Amount::zero()); | coinControl.m_feerate = CFeeRate(Amount::zero()); | ||||
coinControl.fOverrideFeeRate = false; | coinControl.fOverrideFeeRate = false; | ||||
UniValue subtractFeeFromOutputs; | UniValue subtractFeeFromOutputs; | ||||
std::set<int> setSubtractFeeFromOutputs; | std::set<int> setSubtractFeeFromOutputs; | ||||
if (request.params.size() > 1) { | if (request.params.size() > 1) { | ||||
if (request.params[1].type() == UniValue::VBOOL) { | if (request.params[1].type() == UniValue::VBOOL) { | ||||
// backward compatibility bool only fallback | // backward compatibility bool only fallback | ||||
coinControl.fAllowWatchOnly = request.params[1].get_bool(); | coinControl.fAllowWatchOnly = request.params[1].get_bool(); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (request.params.size() > 1) { | ||||
lockUnspents = options["lockUnspents"].get_bool(); | lockUnspents = options["lockUnspents"].get_bool(); | ||||
} | } | ||||
if (options.exists("reserveChangeKey")) { | if (options.exists("reserveChangeKey")) { | ||||
reserveChangeKey = options["reserveChangeKey"].get_bool(); | reserveChangeKey = options["reserveChangeKey"].get_bool(); | ||||
} | } | ||||
if (options.exists("feeRate")) { | if (options.exists("feeRate")) { | ||||
coinControl.nFeeRate = | coinControl.m_feerate = | ||||
CFeeRate(AmountFromValue(options["feeRate"])); | CFeeRate(AmountFromValue(options["feeRate"])); | ||||
coinControl.fOverrideFeeRate = true; | coinControl.fOverrideFeeRate = true; | ||||
} | } | ||||
if (options.exists("subtractFeeFromOutputs")) { | if (options.exists("subtractFeeFromOutputs")) { | ||||
subtractFeeFromOutputs = | subtractFeeFromOutputs = | ||||
options["subtractFeeFromOutputs"].get_array(); | options["subtractFeeFromOutputs"].get_array(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 341 Lines • Show Last 20 Lines |