Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,475 Lines • ▼ Show 20 Lines | static UniValue fundrawtransaction(const Config &config, | ||||
ObserveSafeMode(); | ObserveSafeMode(); | ||||
RPCTypeCheck(request.params, {UniValue::VSTR}); | RPCTypeCheck(request.params, {UniValue::VSTR}); | ||||
// 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(); | ||||
CTxDestination changeAddress = CNoDestination(); | CCoinControl coinControl; | ||||
coinControl.destChange = CNoDestination(); | |||||
int changePosition = -1; | int changePosition = -1; | ||||
bool includeWatching = false; | // include watching | ||||
coinControl.fAllowWatchOnly = false; | |||||
bool lockUnspents = false; | bool lockUnspents = false; | ||||
bool reserveChangeKey = true; | bool reserveChangeKey = true; | ||||
CFeeRate feeRate = CFeeRate(Amount::zero()); | coinControl.nFeeRate = CFeeRate(Amount::zero()); | ||||
bool overrideEstimatedFeerate = 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 | ||||
includeWatching = 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, | ||||
{ | { | ||||
Show All 14 Lines | if (request.params.size() > 1) { | ||||
config.GetChainParams()); | config.GetChainParams()); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_ADDRESS_OR_KEY, | RPC_INVALID_ADDRESS_OR_KEY, | ||||
"changeAddress must be a valid bitcoin address"); | "changeAddress must be a valid bitcoin address"); | ||||
} | } | ||||
changeAddress = dest; | coinControl.destChange = dest; | ||||
} | } | ||||
if (options.exists("changePosition")) { | if (options.exists("changePosition")) { | ||||
changePosition = options["changePosition"].get_int(); | changePosition = options["changePosition"].get_int(); | ||||
} | } | ||||
if (options.exists("includeWatching")) { | if (options.exists("includeWatching")) { | ||||
includeWatching = options["includeWatching"].get_bool(); | coinControl.fAllowWatchOnly = | ||||
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")) { | if (options.exists("reserveChangeKey")) { | ||||
reserveChangeKey = options["reserveChangeKey"].get_bool(); | reserveChangeKey = options["reserveChangeKey"].get_bool(); | ||||
} | } | ||||
if (options.exists("feeRate")) { | if (options.exists("feeRate")) { | ||||
feeRate = CFeeRate(AmountFromValue(options["feeRate"])); | coinControl.nFeeRate = | ||||
overrideEstimatedFeerate = true; | CFeeRate(AmountFromValue(options["feeRate"])); | ||||
coinControl.fOverrideFeeRate = true; | |||||
} | } | ||||
if (options.exists("subtractFeeFromOutputs")) { | if (options.exists("subtractFeeFromOutputs")) { | ||||
subtractFeeFromOutputs = | subtractFeeFromOutputs = | ||||
options["subtractFeeFromOutputs"].get_array(); | options["subtractFeeFromOutputs"].get_array(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Show All 33 Lines | for (size_t idx = 0; idx < subtractFeeFromOutputs.size(); idx++) { | ||||
strprintf("Invalid parameter, position too large: %d", pos)); | strprintf("Invalid parameter, position too large: %d", pos)); | ||||
} | } | ||||
setSubtractFeeFromOutputs.insert(pos); | setSubtractFeeFromOutputs.insert(pos); | ||||
} | } | ||||
Amount nFeeOut; | Amount nFeeOut; | ||||
std::string strFailReason; | std::string strFailReason; | ||||
if (!pwallet->FundTransaction( | if (!pwallet->FundTransaction(tx, nFeeOut, changePosition, strFailReason, | ||||
tx, nFeeOut, overrideEstimatedFeerate, feeRate, changePosition, | lockUnspents, setSubtractFeeFromOutputs, | ||||
strFailReason, includeWatching, lockUnspents, | coinControl, reserveChangeKey)) { | ||||
setSubtractFeeFromOutputs, reserveChangeKey, changeAddress)) { | |||||
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 |