Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,459 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
" \"changeAddress\" (string, optional, default pool " | " \"changeAddress\" (string, optional, default pool " | ||||
"address) The bitcoin address to receive the change\n" | "address) The bitcoin address to receive the change\n" | ||||
" \"changePosition\" (numeric, optional, default " | " \"changePosition\" (numeric, optional, default " | ||||
"random) The index of the change output\n" | "random) The index of the change output\n" | ||||
" \"includeWatching\" (boolean, optional, default " | " \"includeWatching\" (boolean, optional, default " | ||||
"false) Also select inputs which are watch only\n" | "false) Also select inputs which are watch only\n" | ||||
" \"lockUnspents\" (boolean, optional, default " | " \"lockUnspents\" (boolean, optional, default " | ||||
"false) Lock selected unspent outputs\n" | "false) Lock selected unspent outputs\n" | ||||
" \"reserveChangeKey\" (boolean, optional, default true) " | |||||
jasonbcox: This deserves a mention in release notes | |||||
"Reserves the change output key from the keypool\n" | |||||
" \"feeRate\" (numeric, optional, default not " | " \"feeRate\" (numeric, optional, default not " | ||||
"set: makes wallet determine the fee) Set a specific feerate (" + | "set: makes wallet determine the fee) Set a specific feerate (" + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" per KB)\n" | " per KB)\n" | ||||
" \"subtractFeeFromOutputs\" (array, optional) A json array of " | " \"subtractFeeFromOutputs\" (array, optional) A json array of " | ||||
"integers.\n" | "integers.\n" | ||||
" The fee will be equally deducted " | " The fee will be equally deducted " | ||||
"from the amount of each specified output.\n" | "from the amount of each specified output.\n" | ||||
Show All 34 Lines | static UniValue fundrawtransaction(const Config &config, | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
CCoinControl coinControl; | CCoinControl coinControl; | ||||
int changePosition = -1; | int changePosition = -1; | ||||
bool lockUnspents = false; | bool lockUnspents = false; | ||||
bool reserveChangeKey = true; | |||||
UniValue subtractFeeFromOutputs; | UniValue subtractFeeFromOutputs; | ||||
std::set<int> setSubtractFeeFromOutputs; | std::set<int> setSubtractFeeFromOutputs; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
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(); | ||||
} else { | } else { | ||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ}); | RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ}); | ||||
UniValue options = request.params[1]; | UniValue options = request.params[1]; | ||||
RPCTypeCheckObj( | RPCTypeCheckObj( | ||||
options, | options, | ||||
{ | { | ||||
{"changeAddress", UniValueType(UniValue::VSTR)}, | {"changeAddress", UniValueType(UniValue::VSTR)}, | ||||
{"changePosition", UniValueType(UniValue::VNUM)}, | {"changePosition", UniValueType(UniValue::VNUM)}, | ||||
{"includeWatching", UniValueType(UniValue::VBOOL)}, | {"includeWatching", UniValueType(UniValue::VBOOL)}, | ||||
{"lockUnspents", UniValueType(UniValue::VBOOL)}, | {"lockUnspents", UniValueType(UniValue::VBOOL)}, | ||||
// DEPRECATED (and ignored), should be removed in 0.16 or | |||||
jasonbcoxUnsubmitted Done Inline ActionsVersion number needs to be next major version for ABC jasonbcox: Version number needs to be next major version for ABC | |||||
// so. | |||||
{"reserveChangeKey", UniValueType(UniValue::VBOOL)}, | {"reserveChangeKey", UniValueType(UniValue::VBOOL)}, | ||||
// will be checked below | // will be checked below | ||||
{"feeRate", UniValueType()}, | {"feeRate", UniValueType()}, | ||||
{"subtractFeeFromOutputs", UniValueType(UniValue::VARR)}, | {"subtractFeeFromOutputs", UniValueType(UniValue::VARR)}, | ||||
}, | }, | ||||
true, true); | true, true); | ||||
if (options.exists("changeAddress")) { | if (options.exists("changeAddress")) { | ||||
Show All 18 Lines | if (!request.params[1].isNull()) { | ||||
coinControl.fAllowWatchOnly = | coinControl.fAllowWatchOnly = | ||||
options["includeWatching"].get_bool(); | options["includeWatching"].get_bool(); | ||||
} | } | ||||
if (options.exists("lockUnspents")) { | if (options.exists("lockUnspents")) { | ||||
lockUnspents = options["lockUnspents"].get_bool(); | lockUnspents = options["lockUnspents"].get_bool(); | ||||
} | } | ||||
if (options.exists("reserveChangeKey")) { | |||||
reserveChangeKey = options["reserveChangeKey"].get_bool(); | |||||
} | |||||
if (options.exists("feeRate")) { | if (options.exists("feeRate")) { | ||||
coinControl.m_feerate = | 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 = | ||||
Show All 39 Lines | for (size_t idx = 0; idx < subtractFeeFromOutputs.size(); idx++) { | ||||
setSubtractFeeFromOutputs.insert(pos); | setSubtractFeeFromOutputs.insert(pos); | ||||
} | } | ||||
Amount nFeeOut; | Amount nFeeOut; | ||||
std::string strFailReason; | std::string strFailReason; | ||||
if (!pwallet->FundTransaction(tx, nFeeOut, changePosition, strFailReason, | if (!pwallet->FundTransaction(tx, nFeeOut, changePosition, strFailReason, | ||||
lockUnspents, setSubtractFeeFromOutputs, | lockUnspents, setSubtractFeeFromOutputs, | ||||
coinControl, reserveChangeKey)) { | coinControl)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | ||||
} | } | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("hex", EncodeHexTx(CTransaction(tx))); | result.pushKV("hex", EncodeHexTx(CTransaction(tx))); | ||||
result.pushKV("changepos", changePosition); | result.pushKV("changepos", changePosition); | ||||
result.pushKV("fee", ValueFromAmount(nFeeOut)); | result.pushKV("fee", ValueFromAmount(nFeeOut)); | ||||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |
This deserves a mention in release notes