Branch data Line data Source code
# 1 : : // Copyright (c) 2011-2021 The Bitcoin Core developers
# 2 : : // Distributed under the MIT software license, see the accompanying
# 3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
# 4 : :
# 5 : : #include <consensus/validation.h>
# 6 : : #include <core_io.h>
# 7 : : #include <key_io.h>
# 8 : : #include <policy/policy.h>
# 9 : : #include <rpc/rawtransaction_util.h>
# 10 : : #include <rpc/util.h>
# 11 : : #include <util/fees.h>
# 12 : : #include <util/rbf.h>
# 13 : : #include <util/translation.h>
# 14 : : #include <util/vector.h>
# 15 : : #include <wallet/coincontrol.h>
# 16 : : #include <wallet/feebumper.h>
# 17 : : #include <wallet/fees.h>
# 18 : : #include <wallet/rpc/util.h>
# 19 : : #include <wallet/spend.h>
# 20 : : #include <wallet/wallet.h>
# 21 : :
# 22 : : #include <univalue.h>
# 23 : :
# 24 : :
# 25 : : namespace wallet {
# 26 : : static void ParseRecipients(const UniValue& address_amounts, const UniValue& subtract_fee_outputs, std::vector<CRecipient>& recipients)
# 27 : 2164 : {
# 28 : 2164 : std::set<CTxDestination> destinations;
# 29 : 2164 : int i = 0;
# 30 [ + + ]: 8588 : for (const std::string& address: address_amounts.getKeys()) {
# 31 : 8588 : CTxDestination dest = DecodeDestination(address);
# 32 [ - + ]: 8588 : if (!IsValidDestination(dest)) {
# 33 : 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ") + address);
# 34 : 0 : }
# 35 : :
# 36 [ - + ]: 8588 : if (destinations.count(dest)) {
# 37 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ") + address);
# 38 : 0 : }
# 39 : 8588 : destinations.insert(dest);
# 40 : :
# 41 : 8588 : CScript script_pub_key = GetScriptForDestination(dest);
# 42 : 8588 : CAmount amount = AmountFromValue(address_amounts[i++]);
# 43 : :
# 44 : 8588 : bool subtract_fee = false;
# 45 [ + + ]: 8816 : for (unsigned int idx = 0; idx < subtract_fee_outputs.size(); idx++) {
# 46 : 228 : const UniValue& addr = subtract_fee_outputs[idx];
# 47 [ + - ]: 228 : if (addr.get_str() == address) {
# 48 : 228 : subtract_fee = true;
# 49 : 228 : }
# 50 : 228 : }
# 51 : :
# 52 : 8588 : CRecipient recipient = {script_pub_key, amount, subtract_fee};
# 53 : 8588 : recipients.push_back(recipient);
# 54 : 8588 : }
# 55 : 2164 : }
# 56 : :
# 57 : : static void InterpretFeeEstimationInstructions(const UniValue& conf_target, const UniValue& estimate_mode, const UniValue& fee_rate, UniValue& options)
# 58 : 301 : {
# 59 [ + + ][ + + ]: 301 : if (options.exists("conf_target") || options.exists("estimate_mode")) {
# [ + + ]
# 60 [ + + ][ - + ]: 48 : if (!conf_target.isNull() || !estimate_mode.isNull()) {
# 61 : 6 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Pass conf_target and estimate_mode either as arguments or in the options object, but not both");
# 62 : 6 : }
# 63 : 253 : } else {
# 64 : 253 : options.pushKV("conf_target", conf_target);
# 65 : 253 : options.pushKV("estimate_mode", estimate_mode);
# 66 : 253 : }
# 67 [ + + ]: 295 : if (options.exists("fee_rate")) {
# 68 [ + + ]: 58 : if (!fee_rate.isNull()) {
# 69 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Pass the fee_rate either as an argument, or in the options object, but not both");
# 70 : 2 : }
# 71 : 237 : } else {
# 72 : 237 : options.pushKV("fee_rate", fee_rate);
# 73 : 237 : }
# 74 [ - + ][ + + ]: 293 : if (!options["conf_target"].isNull() && (options["estimate_mode"].isNull() || (options["estimate_mode"].get_str() == "unset"))) {
# [ - + ][ - + ]
# 75 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Specify estimate_mode");
# 76 : 0 : }
# 77 : 293 : }
# 78 : :
# 79 : : static UniValue FinishTransaction(const std::shared_ptr<CWallet> pwallet, const UniValue& options, const CMutableTransaction& rawTx)
# 80 : 102 : {
# 81 : : // Make a blank psbt
# 82 : 102 : PartiallySignedTransaction psbtx(rawTx);
# 83 : :
# 84 : : // First fill transaction with our data without signing,
# 85 : : // so external signers are not asked sign more than once.
# 86 : 102 : bool complete;
# 87 : 102 : pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, false, true);
# 88 : 102 : const TransactionError err{pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, true, false)};
# 89 [ - + ]: 102 : if (err != TransactionError::OK) {
# 90 : 0 : throw JSONRPCTransactionError(err);
# 91 : 0 : }
# 92 : :
# 93 : 102 : CMutableTransaction mtx;
# 94 : 102 : complete = FinalizeAndExtractPSBT(psbtx, mtx);
# 95 : :
# 96 : 102 : UniValue result(UniValue::VOBJ);
# 97 : :
# 98 [ + + ][ + - ]: 102 : const bool psbt_opt_in{options.exists("psbt") && options["psbt"].get_bool()};
# 99 [ + + ]: 102 : bool add_to_wallet{options.exists("add_to_wallet") ? options["add_to_wallet"].get_bool() : true};
# 100 [ + + ][ + + ]: 102 : if (psbt_opt_in || !complete || !add_to_wallet) {
# [ + + ]
# 101 : : // Serialize the PSBT
# 102 : 51 : CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
# 103 : 51 : ssTx << psbtx;
# 104 : 51 : result.pushKV("psbt", EncodeBase64(ssTx.str()));
# 105 : 51 : }
# 106 : :
# 107 [ + + ]: 102 : if (complete) {
# 108 : 91 : std::string hex{EncodeHexTx(CTransaction(mtx))};
# 109 : 91 : CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
# 110 : 91 : result.pushKV("txid", tx->GetHash().GetHex());
# 111 [ + + ][ + + ]: 91 : if (add_to_wallet && !psbt_opt_in) {
# 112 : 51 : pwallet->CommitTransaction(tx, {}, /*orderForm=*/{});
# 113 : 51 : } else {
# 114 : 40 : result.pushKV("hex", hex);
# 115 : 40 : }
# 116 : 91 : }
# 117 : 102 : result.pushKV("complete", complete);
# 118 : :
# 119 : 102 : return result;
# 120 : 102 : }
# 121 : :
# 122 : : static void PreventOutdatedOptions(const UniValue& options)
# 123 : 293 : {
# 124 [ + + ]: 293 : if (options.exists("feeRate")) {
# 125 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Use fee_rate (" + CURRENCY_ATOM + "/vB) instead of feeRate");
# 126 : 2 : }
# 127 [ - + ]: 291 : if (options.exists("changeAddress")) {
# 128 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Use change_address instead of changeAddress");
# 129 : 0 : }
# 130 [ - + ]: 291 : if (options.exists("changePosition")) {
# 131 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Use change_position instead of changePosition");
# 132 : 0 : }
# 133 [ - + ]: 291 : if (options.exists("includeWatching")) {
# 134 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Use include_watching instead of includeWatching");
# 135 : 0 : }
# 136 [ - + ]: 291 : if (options.exists("lockUnspents")) {
# 137 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Use lock_unspents instead of lockUnspents");
# 138 : 0 : }
# 139 [ - + ]: 291 : if (options.exists("subtractFeeFromOutputs")) {
# 140 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Use subtract_fee_from_outputs instead of subtractFeeFromOutputs");
# 141 : 0 : }
# 142 : 291 : }
# 143 : :
# 144 : : UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vector<CRecipient> &recipients, mapValue_t map_value, bool verbose)
# 145 : 2160 : {
# 146 : 2160 : EnsureWalletIsUnlocked(wallet);
# 147 : :
# 148 : : // This function is only used by sendtoaddress and sendmany.
# 149 : : // This should always try to sign, if we don't have private keys, don't try to do anything here.
# 150 [ + + ]: 2160 : if (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
# 151 : 4 : throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet");
# 152 : 4 : }
# 153 : :
# 154 : : // Shuffle recipient list
# 155 : 2156 : std::shuffle(recipients.begin(), recipients.end(), FastRandomContext());
# 156 : :
# 157 : : // Send
# 158 : 2156 : CAmount nFeeRequired = 0;
# 159 : 2156 : int nChangePosRet = -1;
# 160 : 2156 : bilingual_str error;
# 161 : 2156 : CTransactionRef tx;
# 162 : 2156 : FeeCalculation fee_calc_out;
# 163 : 2156 : const bool fCreated = CreateTransaction(wallet, recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, true);
# 164 [ + + ]: 2156 : if (!fCreated) {
# 165 : 40 : throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original);
# 166 : 40 : }
# 167 : 2116 : wallet.CommitTransaction(tx, std::move(map_value), {} /* orderForm */);
# 168 [ + + ]: 2116 : if (verbose) {
# 169 : 4 : UniValue entry(UniValue::VOBJ);
# 170 : 4 : entry.pushKV("txid", tx->GetHash().GetHex());
# 171 : 4 : entry.pushKV("fee_reason", StringForFeeReason(fee_calc_out.reason));
# 172 : 4 : return entry;
# 173 : 4 : }
# 174 : 2112 : return tx->GetHash().GetHex();
# 175 : 2116 : }
# 176 : :
# 177 : :
# 178 : : /**
# 179 : : * Update coin control with fee estimation based on the given parameters
# 180 : : *
# 181 : : * @param[in] wallet Wallet reference
# 182 : : * @param[in,out] cc Coin control to be updated
# 183 : : * @param[in] conf_target UniValue integer; confirmation target in blocks, values between 1 and 1008 are valid per policy/fees.h;
# 184 : : * @param[in] estimate_mode UniValue string; fee estimation mode, valid values are "unset", "economical" or "conservative";
# 185 : : * @param[in] fee_rate UniValue real; fee rate in sat/vB;
# 186 : : * if present, both conf_target and estimate_mode must either be null, or "unset"
# 187 : : * @param[in] override_min_fee bool; whether to set fOverrideFeeRate to true to disable minimum fee rate checks and instead
# 188 : : * verify only that fee_rate is greater than 0
# 189 : : * @throws a JSONRPCError if conf_target, estimate_mode, or fee_rate contain invalid values or are in conflict
# 190 : : */
# 191 : : static void SetFeeEstimateMode(const CWallet& wallet, CCoinControl& cc, const UniValue& conf_target, const UniValue& estimate_mode, const UniValue& fee_rate, bool override_min_fee)
# 192 : 3028 : {
# 193 [ + + ]: 3028 : if (!fee_rate.isNull()) {
# 194 [ + + ]: 520 : if (!conf_target.isNull()) {
# 195 : 6 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both conf_target and fee_rate. Please provide either a confirmation target in blocks for automatic fee estimation, or an explicit fee rate.");
# 196 : 6 : }
# 197 [ + + ][ + + ]: 514 : if (!estimate_mode.isNull() && estimate_mode.get_str() != "unset") {
# 198 : 6 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both estimate_mode and fee_rate");
# 199 : 6 : }
# 200 : : // Fee rates in sat/vB cannot represent more than 3 significant digits.
# 201 : 508 : cc.m_feerate = CFeeRate{AmountFromValue(fee_rate, /*decimals=*/3)};
# 202 [ + + ]: 508 : if (override_min_fee) cc.fOverrideFeeRate = true;
# 203 : : // Default RBF to true for explicit fee_rate, if unset.
# 204 [ + + ]: 508 : if (!cc.m_signal_bip125_rbf) cc.m_signal_bip125_rbf = true;
# 205 : 508 : return;
# 206 : 514 : }
# 207 [ + + ][ + + ]: 2508 : if (!estimate_mode.isNull() && !FeeModeFromString(estimate_mode.get_str(), cc.m_fee_mode)) {
# 208 : 58 : throw JSONRPCError(RPC_INVALID_PARAMETER, InvalidEstimateModeErrorMessage());
# 209 : 58 : }
# 210 [ + + ]: 2450 : if (!conf_target.isNull()) {
# 211 : 70 : cc.m_confirm_target = ParseConfirmTarget(conf_target, wallet.chain().estimateMaxBlocks());
# 212 : 70 : }
# 213 : 2450 : }
# 214 : :
# 215 : : RPCHelpMan sendtoaddress()
# 216 : 3676 : {
# 217 : 3676 : return RPCHelpMan{"sendtoaddress",
# 218 : 3676 : "\nSend an amount to a given address." +
# 219 : 3676 : HELP_REQUIRING_PASSPHRASE,
# 220 : 3676 : {
# 221 : 3676 : {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to send to."},
# 222 : 3676 : {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The amount in " + CURRENCY_UNIT + " to send. eg 0.1"},
# 223 : 3676 : {"comment", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "A comment used to store what the transaction is for.\n"
# 224 : 3676 : "This is not part of the transaction, just kept in your wallet."},
# 225 : 3676 : {"comment_to", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "A comment to store the name of the person or organization\n"
# 226 : 3676 : "to which you're sending the transaction. This is not part of the \n"
# 227 : 3676 : "transaction, just kept in your wallet."},
# 228 : 3676 : {"subtractfeefromamount", RPCArg::Type::BOOL, RPCArg::Default{false}, "The fee will be deducted from the amount being sent.\n"
# 229 : 3676 : "The recipient will receive less bitcoins than you enter in the amount field."},
# 230 : 3676 : {"replaceable", RPCArg::Type::BOOL, RPCArg::DefaultHint{"wallet default"}, "Allow this transaction to be replaced by a transaction with higher fees via BIP 125"},
# 231 : 3676 : {"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks"},
# 232 : 3676 : {"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"unset"}, std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
# 233 : 3676 : " \"" + FeeModes("\"\n\"") + "\""},
# 234 : 3676 : {"avoid_reuse", RPCArg::Type::BOOL, RPCArg::Default{true}, "(only available if avoid_reuse wallet flag is set) Avoid spending from dirty addresses; addresses are considered\n"
# 235 : 3676 : "dirty if they have previously been used in a transaction. If true, this also activates avoidpartialspends, grouping outputs by their addresses."},
# 236 : 3676 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
# 237 : 3676 : {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, return extra information about the transaction."},
# 238 : 3676 : },
# 239 : 3676 : {
# 240 : 3676 : RPCResult{"if verbose is not set or set to false",
# 241 : 3676 : RPCResult::Type::STR_HEX, "txid", "The transaction id."
# 242 : 3676 : },
# 243 : 3676 : RPCResult{"if verbose is set to true",
# 244 : 3676 : RPCResult::Type::OBJ, "", "",
# 245 : 3676 : {
# 246 : 3676 : {RPCResult::Type::STR_HEX, "txid", "The transaction id."},
# 247 : 3676 : {RPCResult::Type::STR, "fee_reason", "The transaction fee reason."}
# 248 : 3676 : },
# 249 : 3676 : },
# 250 : 3676 : },
# 251 : 3676 : RPCExamples{
# 252 : 3676 : "\nSend 0.1 BTC\n"
# 253 : 3676 : + HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1") +
# 254 : 3676 : "\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode using positional arguments\n"
# 255 : 3676 : + HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1 \"donation\" \"sean's outpost\" false true 6 economical") +
# 256 : 3676 : "\nSend 0.1 BTC with a fee rate of 1.1 " + CURRENCY_ATOM + "/vB, subtract fee from amount, BIP125-replaceable, using positional arguments\n"
# 257 : 3676 : + HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1 \"drinks\" \"room77\" true true null \"unset\" null 1.1") +
# 258 : 3676 : "\nSend 0.2 BTC with a confirmation target of 6 blocks in economical fee estimate mode using named arguments\n"
# 259 : 3676 : + HelpExampleCli("-named sendtoaddress", "address=\"" + EXAMPLE_ADDRESS[0] + "\" amount=0.2 conf_target=6 estimate_mode=\"economical\"") +
# 260 : 3676 : "\nSend 0.5 BTC with a fee rate of 25 " + CURRENCY_ATOM + "/vB using named arguments\n"
# 261 : 3676 : + HelpExampleCli("-named sendtoaddress", "address=\"" + EXAMPLE_ADDRESS[0] + "\" amount=0.5 fee_rate=25")
# 262 : 3676 : + HelpExampleCli("-named sendtoaddress", "address=\"" + EXAMPLE_ADDRESS[0] + "\" amount=0.5 fee_rate=25 subtractfeefromamount=false replaceable=true avoid_reuse=true comment=\"2 pizzas\" comment_to=\"jeremy\" verbose=true")
# 263 : 3676 : },
# 264 : 3676 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 265 : 3676 : {
# 266 : 2092 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
# 267 [ - + ]: 2092 : if (!pwallet) return NullUniValue;
# 268 : :
# 269 : : // Make sure the results are valid at least up to the most recent block
# 270 : : // the user could have gotten from another RPC command prior to now
# 271 : 2092 : pwallet->BlockUntilSyncedToCurrentChain();
# 272 : :
# 273 : 2092 : LOCK(pwallet->cs_wallet);
# 274 : :
# 275 : : // Wallet comments
# 276 : 2092 : mapValue_t mapValue;
# 277 [ + + ][ + + ]: 2092 : if (!request.params[2].isNull() && !request.params[2].get_str().empty())
# 278 : 2 : mapValue["comment"] = request.params[2].get_str();
# 279 [ + + ][ + + ]: 2092 : if (!request.params[3].isNull() && !request.params[3].get_str().empty())
# 280 : 2 : mapValue["to"] = request.params[3].get_str();
# 281 : :
# 282 : 2092 : bool fSubtractFeeFromAmount = false;
# 283 [ + + ]: 2092 : if (!request.params[4].isNull()) {
# 284 : 226 : fSubtractFeeFromAmount = request.params[4].get_bool();
# 285 : 226 : }
# 286 : :
# 287 : 2092 : CCoinControl coin_control;
# 288 [ + + ]: 2092 : if (!request.params[5].isNull()) {
# 289 : 2 : coin_control.m_signal_bip125_rbf = request.params[5].get_bool();
# 290 : 2 : }
# 291 : :
# 292 : 2092 : coin_control.m_avoid_address_reuse = GetAvoidReuseFlag(*pwallet, request.params[8]);
# 293 : : // We also enable partial spend avoidance if reuse avoidance is set.
# 294 : 2092 : coin_control.m_avoid_partial_spends |= coin_control.m_avoid_address_reuse;
# 295 : :
# 296 : 2092 : SetFeeEstimateMode(*pwallet, coin_control, /*conf_target=*/request.params[6], /*estimate_mode=*/request.params[7], /*fee_rate=*/request.params[9], /*override_min_fee=*/false);
# 297 : :
# 298 : 2092 : EnsureWalletIsUnlocked(*pwallet);
# 299 : :
# 300 : 2092 : UniValue address_amounts(UniValue::VOBJ);
# 301 : 2092 : const std::string address = request.params[0].get_str();
# 302 : 2092 : address_amounts.pushKV(address, request.params[1]);
# 303 : 2092 : UniValue subtractFeeFromAmount(UniValue::VARR);
# 304 [ + + ]: 2092 : if (fSubtractFeeFromAmount) {
# 305 : 224 : subtractFeeFromAmount.push_back(address);
# 306 : 224 : }
# 307 : :
# 308 : 2092 : std::vector<CRecipient> recipients;
# 309 : 2092 : ParseRecipients(address_amounts, subtractFeeFromAmount, recipients);
# 310 [ + + ]: 2092 : const bool verbose{request.params[10].isNull() ? false : request.params[10].get_bool()};
# 311 : :
# 312 : 2092 : return SendMoney(*pwallet, coin_control, recipients, mapValue, verbose);
# 313 : 2092 : },
# 314 : 3676 : };
# 315 : 3676 : }
# 316 : :
# 317 : : RPCHelpMan sendmany()
# 318 : 1739 : {
# 319 : 1739 : return RPCHelpMan{"sendmany",
# 320 : 1739 : "\nSend multiple times. Amounts are double-precision floating point numbers." +
# 321 : 1739 : HELP_REQUIRING_PASSPHRASE,
# 322 : 1739 : {
# 323 : 1739 : {"dummy", RPCArg::Type::STR, RPCArg::Optional::NO, "Must be set to \"\" for backwards compatibility.", "\"\""},
# 324 : 1739 : {"amounts", RPCArg::Type::OBJ_USER_KEYS, RPCArg::Optional::NO, "The addresses and amounts",
# 325 : 1739 : {
# 326 : 1739 : {"address", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The bitcoin address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value"},
# 327 : 1739 : },
# 328 : 1739 : },
# 329 : 1739 : {"minconf", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "Ignored dummy value"},
# 330 : 1739 : {"comment", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "A comment"},
# 331 : 1739 : {"subtractfeefrom", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "The addresses.\n"
# 332 : 1739 : "The fee will be equally deducted from the amount of each selected address.\n"
# 333 : 1739 : "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
# 334 : 1739 : "If no addresses are specified here, the sender pays the fee.",
# 335 : 1739 : {
# 336 : 1739 : {"address", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Subtract fee from this address"},
# 337 : 1739 : },
# 338 : 1739 : },
# 339 : 1739 : {"replaceable", RPCArg::Type::BOOL, RPCArg::DefaultHint{"wallet default"}, "Allow this transaction to be replaced by a transaction with higher fees via BIP 125"},
# 340 : 1739 : {"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks"},
# 341 : 1739 : {"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"unset"}, std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
# 342 : 1739 : " \"" + FeeModes("\"\n\"") + "\""},
# 343 : 1739 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
# 344 : 1739 : {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, return extra infomration about the transaction."},
# 345 : 1739 : },
# 346 : 1739 : {
# 347 : 1739 : RPCResult{"if verbose is not set or set to false",
# 348 : 1739 : RPCResult::Type::STR_HEX, "txid", "The transaction id for the send. Only 1 transaction is created regardless of\n"
# 349 : 1739 : "the number of addresses."
# 350 : 1739 : },
# 351 : 1739 : RPCResult{"if verbose is set to true",
# 352 : 1739 : RPCResult::Type::OBJ, "", "",
# 353 : 1739 : {
# 354 : 1739 : {RPCResult::Type::STR_HEX, "txid", "The transaction id for the send. Only 1 transaction is created regardless of\n"
# 355 : 1739 : "the number of addresses."},
# 356 : 1739 : {RPCResult::Type::STR, "fee_reason", "The transaction fee reason."}
# 357 : 1739 : },
# 358 : 1739 : },
# 359 : 1739 : },
# 360 : 1739 : RPCExamples{
# 361 : 1739 : "\nSend two amounts to two different addresses:\n"
# 362 : 1739 : + HelpExampleCli("sendmany", "\"\" \"{\\\"" + EXAMPLE_ADDRESS[0] + "\\\":0.01,\\\"" + EXAMPLE_ADDRESS[1] + "\\\":0.02}\"") +
# 363 : 1739 : "\nSend two amounts to two different addresses setting the confirmation and comment:\n"
# 364 : 1739 : + HelpExampleCli("sendmany", "\"\" \"{\\\"" + EXAMPLE_ADDRESS[0] + "\\\":0.01,\\\"" + EXAMPLE_ADDRESS[1] + "\\\":0.02}\" 6 \"testing\"") +
# 365 : 1739 : "\nSend two amounts to two different addresses, subtract fee from amount:\n"
# 366 : 1739 : + HelpExampleCli("sendmany", "\"\" \"{\\\"" + EXAMPLE_ADDRESS[0] + "\\\":0.01,\\\"" + EXAMPLE_ADDRESS[1] + "\\\":0.02}\" 1 \"\" \"[\\\"" + EXAMPLE_ADDRESS[0] + "\\\",\\\"" + EXAMPLE_ADDRESS[1] + "\\\"]\"") +
# 367 : 1739 : "\nAs a JSON-RPC call\n"
# 368 : 1739 : + HelpExampleRpc("sendmany", "\"\", {\"" + EXAMPLE_ADDRESS[0] + "\":0.01,\"" + EXAMPLE_ADDRESS[1] + "\":0.02}, 6, \"testing\"")
# 369 : 1739 : },
# 370 : 1739 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 371 : 1739 : {
# 372 : 155 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
# 373 [ - + ]: 155 : if (!pwallet) return NullUniValue;
# 374 : :
# 375 : : // Make sure the results are valid at least up to the most recent block
# 376 : : // the user could have gotten from another RPC command prior to now
# 377 : 155 : pwallet->BlockUntilSyncedToCurrentChain();
# 378 : :
# 379 : 155 : LOCK(pwallet->cs_wallet);
# 380 : :
# 381 [ + + ][ - + ]: 155 : if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
# 382 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\"");
# 383 : 0 : }
# 384 : 155 : UniValue sendTo = request.params[1].get_obj();
# 385 : :
# 386 : 155 : mapValue_t mapValue;
# 387 [ + + ][ - + ]: 155 : if (!request.params[3].isNull() && !request.params[3].get_str().empty())
# 388 : 0 : mapValue["comment"] = request.params[3].get_str();
# 389 : :
# 390 : 155 : UniValue subtractFeeFromAmount(UniValue::VARR);
# 391 [ + + ]: 155 : if (!request.params[4].isNull())
# 392 : 6 : subtractFeeFromAmount = request.params[4].get_array();
# 393 : :
# 394 : 155 : CCoinControl coin_control;
# 395 [ - + ]: 155 : if (!request.params[5].isNull()) {
# 396 : 0 : coin_control.m_signal_bip125_rbf = request.params[5].get_bool();
# 397 : 0 : }
# 398 : :
# 399 : 155 : SetFeeEstimateMode(*pwallet, coin_control, /*conf_target=*/request.params[6], /*estimate_mode=*/request.params[7], /*fee_rate=*/request.params[8], /*override_min_fee=*/false);
# 400 : :
# 401 : 155 : std::vector<CRecipient> recipients;
# 402 : 155 : ParseRecipients(sendTo, subtractFeeFromAmount, recipients);
# 403 [ + + ]: 155 : const bool verbose{request.params[9].isNull() ? false : request.params[9].get_bool()};
# 404 : :
# 405 : 155 : return SendMoney(*pwallet, coin_control, recipients, std::move(mapValue), verbose);
# 406 : 155 : },
# 407 : 1739 : };
# 408 : 1739 : }
# 409 : :
# 410 : : RPCHelpMan settxfee()
# 411 : 1614 : {
# 412 : 1614 : return RPCHelpMan{"settxfee",
# 413 : 1614 : "\nSet the transaction fee rate in " + CURRENCY_UNIT + "/kvB for this wallet. Overrides the global -paytxfee command line parameter.\n"
# 414 : 1614 : "Can be deactivated by passing 0 as the fee. In that case automatic fee selection will be used by default.\n",
# 415 : 1614 : {
# 416 : 1614 : {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The transaction fee rate in " + CURRENCY_UNIT + "/kvB"},
# 417 : 1614 : },
# 418 : 1614 : RPCResult{
# 419 : 1614 : RPCResult::Type::BOOL, "", "Returns true if successful"
# 420 : 1614 : },
# 421 : 1614 : RPCExamples{
# 422 : 1614 : HelpExampleCli("settxfee", "0.00001")
# 423 : 1614 : + HelpExampleRpc("settxfee", "0.00001")
# 424 : 1614 : },
# 425 : 1614 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 426 : 1614 : {
# 427 : 30 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
# 428 [ - + ]: 30 : if (!pwallet) return NullUniValue;
# 429 : :
# 430 : 30 : LOCK(pwallet->cs_wallet);
# 431 : :
# 432 : 30 : CAmount nAmount = AmountFromValue(request.params[0]);
# 433 : 30 : CFeeRate tx_fee_rate(nAmount, 1000);
# 434 : 30 : CFeeRate max_tx_fee_rate(pwallet->m_default_max_tx_fee, 1000);
# 435 [ + + ]: 30 : if (tx_fee_rate == CFeeRate(0)) {
# 436 : : // automatic selection
# 437 [ + + ]: 26 : } else if (tx_fee_rate < pwallet->chain().relayMinFee()) {
# 438 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than min relay tx fee (%s)", pwallet->chain().relayMinFee().ToString()));
# 439 [ + + ]: 24 : } else if (tx_fee_rate < pwallet->m_min_fee) {
# 440 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than wallet min fee (%s)", pwallet->m_min_fee.ToString()));
# 441 [ + + ]: 22 : } else if (tx_fee_rate > max_tx_fee_rate) {
# 442 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be more than wallet max tx fee (%s)", max_tx_fee_rate.ToString()));
# 443 : 2 : }
# 444 : :
# 445 : 24 : pwallet->m_pay_tx_fee = tx_fee_rate;
# 446 : 24 : return true;
# 447 : 30 : },
# 448 : 1614 : };
# 449 : 1614 : }
# 450 : :
# 451 : :
# 452 : : // Only includes key documentation where the key is snake_case in all RPC methods. MixedCase keys can be added later.
# 453 : : static std::vector<RPCArg> FundTxDoc(bool solving_data = true)
# 454 : 7278 : {
# 455 : 7278 : std::vector<RPCArg> args = {
# 456 : 7278 : {"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks"},
# 457 : 7278 : {"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"unset"}, std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
# 458 : 7278 : " \"" + FeeModes("\"\n\"") + "\""},
# 459 : 7278 : {
# 460 : 7278 : "replaceable", RPCArg::Type::BOOL, RPCArg::DefaultHint{"wallet default"}, "Marks this transaction as BIP125-replaceable.\n"
# 461 : 7278 : "Allows this transaction to be replaced by a transaction with higher fees"
# 462 : 7278 : },
# 463 : 7278 : };
# 464 [ + - ]: 7278 : if (solving_data) {
# 465 : 7278 : args.push_back({"solving_data", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "Keys and scripts needed for producing a final transaction with a dummy signature.\n"
# 466 : 7278 : "Used for fee estimation during coin selection.",
# 467 : 7278 : {
# 468 : 7278 : {
# 469 : 7278 : "pubkeys", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Public keys involved in this transaction.",
# 470 : 7278 : {
# 471 : 7278 : {"pubkey", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A public key"},
# 472 : 7278 : }
# 473 : 7278 : },
# 474 : 7278 : {
# 475 : 7278 : "scripts", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Scripts involved in this transaction.",
# 476 : 7278 : {
# 477 : 7278 : {"script", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A script"},
# 478 : 7278 : }
# 479 : 7278 : },
# 480 : 7278 : {
# 481 : 7278 : "descriptors", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Descriptors that provide solving data for this transaction.",
# 482 : 7278 : {
# 483 : 7278 : {"descriptor", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "A descriptor"},
# 484 : 7278 : }
# 485 : 7278 : },
# 486 : 7278 : }
# 487 : 7278 : });
# 488 : 7278 : }
# 489 : 7278 : return args;
# 490 : 7278 : }
# 491 : :
# 492 : : void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, int& change_position, const UniValue& options, CCoinControl& coinControl, bool override_min_fee)
# 493 : 867 : {
# 494 : : // Make sure the results are valid at least up to the most recent block
# 495 : : // the user could have gotten from another RPC command prior to now
# 496 : 867 : wallet.BlockUntilSyncedToCurrentChain();
# 497 : :
# 498 : 867 : change_position = -1;
# 499 : 867 : bool lockUnspents = false;
# 500 : 867 : UniValue subtractFeeFromOutputs;
# 501 : 867 : std::set<int> setSubtractFeeFromOutputs;
# 502 : :
# 503 [ + + ]: 867 : if (!options.isNull()) {
# 504 [ + + ]: 750 : if (options.type() == UniValue::VBOOL) {
# 505 : : // backward compatibility bool only fallback
# 506 : 2 : coinControl.fAllowWatchOnly = options.get_bool();
# 507 : 2 : }
# 508 : 748 : else {
# 509 : 748 : RPCTypeCheckArgument(options, UniValue::VOBJ);
# 510 : 748 : RPCTypeCheckObj(options,
# 511 : 748 : {
# 512 : 748 : {"add_inputs", UniValueType(UniValue::VBOOL)},
# 513 : 748 : {"include_unsafe", UniValueType(UniValue::VBOOL)},
# 514 : 748 : {"add_to_wallet", UniValueType(UniValue::VBOOL)},
# 515 : 748 : {"changeAddress", UniValueType(UniValue::VSTR)},
# 516 : 748 : {"change_address", UniValueType(UniValue::VSTR)},
# 517 : 748 : {"changePosition", UniValueType(UniValue::VNUM)},
# 518 : 748 : {"change_position", UniValueType(UniValue::VNUM)},
# 519 : 748 : {"change_type", UniValueType(UniValue::VSTR)},
# 520 : 748 : {"includeWatching", UniValueType(UniValue::VBOOL)},
# 521 : 748 : {"include_watching", UniValueType(UniValue::VBOOL)},
# 522 : 748 : {"inputs", UniValueType(UniValue::VARR)},
# 523 : 748 : {"lockUnspents", UniValueType(UniValue::VBOOL)},
# 524 : 748 : {"lock_unspents", UniValueType(UniValue::VBOOL)},
# 525 : 748 : {"locktime", UniValueType(UniValue::VNUM)},
# 526 : 748 : {"fee_rate", UniValueType()}, // will be checked by AmountFromValue() in SetFeeEstimateMode()
# 527 : 748 : {"feeRate", UniValueType()}, // will be checked by AmountFromValue() below
# 528 : 748 : {"psbt", UniValueType(UniValue::VBOOL)},
# 529 : 748 : {"solving_data", UniValueType(UniValue::VOBJ)},
# 530 : 748 : {"subtractFeeFromOutputs", UniValueType(UniValue::VARR)},
# 531 : 748 : {"subtract_fee_from_outputs", UniValueType(UniValue::VARR)},
# 532 : 748 : {"replaceable", UniValueType(UniValue::VBOOL)},
# 533 : 748 : {"conf_target", UniValueType(UniValue::VNUM)},
# 534 : 748 : {"estimate_mode", UniValueType(UniValue::VSTR)},
# 535 : 748 : {"input_weights", UniValueType(UniValue::VARR)},
# 536 : 748 : },
# 537 : 748 : true, true);
# 538 : :
# 539 [ + + ]: 748 : if (options.exists("add_inputs") ) {
# 540 : 264 : coinControl.m_add_inputs = options["add_inputs"].get_bool();
# 541 : 264 : }
# 542 : :
# 543 [ + + ][ + + ]: 748 : if (options.exists("changeAddress") || options.exists("change_address")) {
# [ + + ]
# 544 [ + + ]: 32 : const std::string change_address_str = (options.exists("change_address") ? options["change_address"] : options["changeAddress"]).get_str();
# 545 : 32 : CTxDestination dest = DecodeDestination(change_address_str);
# 546 : :
# 547 [ + + ]: 32 : if (!IsValidDestination(dest)) {
# 548 : 4 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Change address must be a valid bitcoin address");
# 549 : 4 : }
# 550 : :
# 551 : 28 : coinControl.destChange = dest;
# 552 : 28 : }
# 553 : :
# 554 [ + + ][ + + ]: 744 : if (options.exists("changePosition") || options.exists("change_position")) {
# [ + + ]
# 555 [ + + ]: 12 : change_position = (options.exists("change_position") ? options["change_position"] : options["changePosition"]).get_int();
# 556 : 12 : }
# 557 : :
# 558 [ + + ]: 744 : if (options.exists("change_type")) {
# 559 [ + + ][ + + ]: 12 : if (options.exists("changeAddress") || options.exists("change_address")) {
# [ - + ]
# 560 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both change address and address type options");
# 561 : 2 : }
# 562 [ + + ]: 10 : if (std::optional<OutputType> parsed = ParseOutputType(options["change_type"].get_str())) {
# 563 : 6 : coinControl.m_change_type.emplace(parsed.value());
# 564 : 6 : } else {
# 565 : 4 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown change type '%s'", options["change_type"].get_str()));
# 566 : 4 : }
# 567 : 10 : }
# 568 : :
# 569 [ + + ]: 738 : const UniValue include_watching_option = options.exists("include_watching") ? options["include_watching"] : options["includeWatching"];
# 570 : 738 : coinControl.fAllowWatchOnly = ParseIncludeWatchonly(include_watching_option, wallet);
# 571 : :
# 572 [ + + ][ + + ]: 738 : if (options.exists("lockUnspents") || options.exists("lock_unspents")) {
# [ + + ]
# 573 [ + + ]: 8 : lockUnspents = (options.exists("lock_unspents") ? options["lock_unspents"] : options["lockUnspents"]).get_bool();
# 574 : 8 : }
# 575 : :
# 576 [ + + ]: 738 : if (options.exists("include_unsafe")) {
# 577 : 8 : coinControl.m_include_unsafe_inputs = options["include_unsafe"].get_bool();
# 578 : 8 : }
# 579 : :
# 580 [ + + ]: 738 : if (options.exists("feeRate")) {
# 581 [ + + ]: 106 : if (options.exists("fee_rate")) {
# 582 : 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both fee_rate (" + CURRENCY_ATOM + "/vB) and feeRate (" + CURRENCY_UNIT + "/kvB)");
# 583 : 4 : }
# 584 [ + + ]: 102 : if (options.exists("conf_target")) {
# 585 : 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both conf_target and feeRate. Please provide either a confirmation target in blocks for automatic fee estimation, or an explicit fee rate.");
# 586 : 4 : }
# 587 [ + + ]: 98 : if (options.exists("estimate_mode")) {
# 588 : 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both estimate_mode and feeRate");
# 589 : 4 : }
# 590 : 94 : coinControl.m_feerate = CFeeRate(AmountFromValue(options["feeRate"]));
# 591 : 94 : coinControl.fOverrideFeeRate = true;
# 592 : 94 : }
# 593 : :
# 594 [ + + ][ + + ]: 726 : if (options.exists("subtractFeeFromOutputs") || options.exists("subtract_fee_from_outputs") )
# [ + + ]
# 595 [ + + ]: 99 : subtractFeeFromOutputs = (options.exists("subtract_fee_from_outputs") ? options["subtract_fee_from_outputs"] : options["subtractFeeFromOutputs"]).get_array();
# 596 : :
# 597 [ + + ]: 726 : if (options.exists("replaceable")) {
# 598 : 12 : coinControl.m_signal_bip125_rbf = options["replaceable"].get_bool();
# 599 : 12 : }
# 600 : 726 : SetFeeEstimateMode(wallet, coinControl, options["conf_target"], options["estimate_mode"], options["fee_rate"], override_min_fee);
# 601 : 726 : }
# 602 : 750 : } else {
# 603 : : // if options is null and not a bool
# 604 : 117 : coinControl.fAllowWatchOnly = ParseIncludeWatchonly(NullUniValue, wallet);
# 605 : 117 : }
# 606 : :
# 607 [ + + ]: 845 : if (options.exists("solving_data")) {
# 608 : 24 : const UniValue solving_data = options["solving_data"].get_obj();
# 609 [ + + ]: 24 : if (solving_data.exists("pubkeys")) {
# 610 [ + + ]: 10 : for (const UniValue& pk_univ : solving_data["pubkeys"].get_array().getValues()) {
# 611 : 10 : const std::string& pk_str = pk_univ.get_str();
# 612 [ + + ]: 10 : if (!IsHex(pk_str)) {
# 613 : 2 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("'%s' is not hex", pk_str));
# 614 : 2 : }
# 615 : 8 : const std::vector<unsigned char> data(ParseHex(pk_str));
# 616 : 8 : const CPubKey pubkey(data.begin(), data.end());
# 617 [ + + ]: 8 : if (!pubkey.IsFullyValid()) {
# 618 : 2 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("'%s' is not a valid public key", pk_str));
# 619 : 2 : }
# 620 : 6 : coinControl.m_external_provider.pubkeys.emplace(pubkey.GetID(), pubkey);
# 621 : : // Add witness script for pubkeys
# 622 : 6 : const CScript wit_script = GetScriptForDestination(WitnessV0KeyHash(pubkey));
# 623 : 6 : coinControl.m_external_provider.scripts.emplace(CScriptID(wit_script), wit_script);
# 624 : 6 : }
# 625 : 10 : }
# 626 : :
# 627 [ + + ]: 20 : if (solving_data.exists("scripts")) {
# 628 [ + + ]: 8 : for (const UniValue& script_univ : solving_data["scripts"].get_array().getValues()) {
# 629 : 8 : const std::string& script_str = script_univ.get_str();
# 630 [ + + ]: 8 : if (!IsHex(script_str)) {
# 631 : 2 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("'%s' is not hex", script_str));
# 632 : 2 : }
# 633 : 6 : std::vector<unsigned char> script_data(ParseHex(script_str));
# 634 : 6 : const CScript script(script_data.begin(), script_data.end());
# 635 : 6 : coinControl.m_external_provider.scripts.emplace(CScriptID(script), script);
# 636 : 6 : }
# 637 : 8 : }
# 638 : :
# 639 [ + + ]: 18 : if (solving_data.exists("descriptors")) {
# 640 [ + + ]: 12 : for (const UniValue& desc_univ : solving_data["descriptors"].get_array().getValues()) {
# 641 : 12 : const std::string& desc_str = desc_univ.get_str();
# 642 : 12 : FlatSigningProvider desc_out;
# 643 : 12 : std::string error;
# 644 : 12 : std::vector<CScript> scripts_temp;
# 645 : 12 : std::unique_ptr<Descriptor> desc = Parse(desc_str, desc_out, error, true);
# 646 [ + + ]: 12 : if (!desc) {
# 647 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Unable to parse descriptor '%s': %s", desc_str, error));
# 648 : 2 : }
# 649 : 10 : desc->Expand(0, desc_out, scripts_temp, desc_out);
# 650 : 10 : coinControl.m_external_provider = Merge(coinControl.m_external_provider, desc_out);
# 651 : 10 : }
# 652 : 12 : }
# 653 : 18 : }
# 654 : :
# 655 [ + + ]: 837 : if (options.exists("input_weights")) {
# 656 [ + + ]: 120 : for (const UniValue& input : options["input_weights"].get_array().getValues()) {
# 657 : 38 : uint256 txid = ParseHashO(input, "txid");
# 658 : :
# 659 : 38 : const UniValue& vout_v = find_value(input, "vout");
# 660 [ + + ]: 38 : if (!vout_v.isNum()) {
# 661 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
# 662 : 2 : }
# 663 : 36 : int vout = vout_v.get_int();
# 664 [ + + ]: 36 : if (vout < 0) {
# 665 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
# 666 : 2 : }
# 667 : :
# 668 : 34 : const UniValue& weight_v = find_value(input, "weight");
# 669 [ + + ]: 34 : if (!weight_v.isNum()) {
# 670 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing weight key");
# 671 : 2 : }
# 672 : 32 : int64_t weight = weight_v.get_int64();
# 673 : 32 : const int64_t min_input_weight = GetTransactionInputWeight(CTxIn());
# 674 [ - + ]: 32 : CHECK_NONFATAL(min_input_weight == 165);
# 675 [ + + ]: 32 : if (weight < min_input_weight) {
# 676 : 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, weight cannot be less than 165 (41 bytes (size of outpoint + sequence + empty scriptSig) * 4 (witness scaling factor)) + 1 (empty witness)");
# 677 : 4 : }
# 678 [ + + ]: 28 : if (weight > MAX_STANDARD_TX_WEIGHT) {
# 679 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, weight cannot be greater than the maximum standard tx weight of %d", MAX_STANDARD_TX_WEIGHT));
# 680 : 2 : }
# 681 : :
# 682 : 26 : coinControl.SetInputWeight(COutPoint(txid, vout), weight);
# 683 : 26 : }
# 684 : 120 : }
# 685 : :
# 686 [ - + ]: 825 : if (tx.vout.size() == 0)
# 687 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "TX must have at least one output");
# 688 : :
# 689 [ + + ][ - + ]: 825 : if (change_position != -1 && (change_position < 0 || (unsigned int)change_position > tx.vout.size()))
# [ + + ]
# 690 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds");
# 691 : :
# 692 [ + + ]: 922 : for (unsigned int idx = 0; idx < subtractFeeFromOutputs.size(); idx++) {
# 693 : 99 : int pos = subtractFeeFromOutputs[idx].get_int();
# 694 [ - + ]: 99 : if (setSubtractFeeFromOutputs.count(pos))
# 695 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, duplicated position: %d", pos));
# 696 [ - + ]: 99 : if (pos < 0)
# 697 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, negative position: %d", pos));
# 698 [ - + ]: 99 : if (pos >= int(tx.vout.size()))
# 699 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, position too large: %d", pos));
# 700 : 99 : setSubtractFeeFromOutputs.insert(pos);
# 701 : 99 : }
# 702 : :
# 703 : : // Fetch specified UTXOs from the UTXO set to get the scriptPubKeys and values of the outputs being selected
# 704 : : // and to match with the given solving_data. Only used for non-wallet outputs.
# 705 : 823 : std::map<COutPoint, Coin> coins;
# 706 [ + + ]: 823 : for (const CTxIn& txin : tx.vin) {
# 707 : 274 : coins[txin.prevout]; // Create empty map entry keyed by prevout.
# 708 : 274 : }
# 709 : 823 : wallet.chain().findCoins(coins);
# 710 [ + + ]: 823 : for (const auto& coin : coins) {
# 711 [ + + ]: 274 : if (!coin.second.out.IsNull()) {
# 712 : 272 : coinControl.SelectExternal(coin.first, coin.second.out);
# 713 : 272 : }
# 714 : 274 : }
# 715 : :
# 716 : 823 : bilingual_str error;
# 717 : :
# 718 [ + + ]: 823 : if (!FundTransaction(wallet, tx, fee_out, change_position, error, lockUnspents, setSubtractFeeFromOutputs, coinControl)) {
# 719 : 93 : throw JSONRPCError(RPC_WALLET_ERROR, error.original);
# 720 : 93 : }
# 721 : 823 : }
# 722 : :
# 723 : : static void SetOptionsInputWeights(const UniValue& inputs, UniValue& options)
# 724 : 522 : {
# 725 [ + + ]: 522 : if (options.exists("input_weights")) {
# 726 : 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Input weights should be specified in inputs rather than in options.");
# 727 : 4 : }
# 728 [ + + ]: 518 : if (inputs.size() == 0) {
# 729 : 318 : return;
# 730 : 318 : }
# 731 : 200 : UniValue weights(UniValue::VARR);
# 732 [ + + ]: 492 : for (const UniValue& input : inputs.getValues()) {
# 733 [ + + ]: 492 : if (input.exists("weight")) {
# 734 : 12 : weights.push_back(input);
# 735 : 12 : }
# 736 : 492 : }
# 737 : 200 : options.pushKV("input_weights", weights);
# 738 : 200 : }
# 739 : :
# 740 : : RPCHelpMan fundrawtransaction()
# 741 : 1933 : {
# 742 : 1933 : return RPCHelpMan{"fundrawtransaction",
# 743 : 1933 : "\nIf the transaction has no inputs, they will be automatically selected to meet its out value.\n"
# 744 : 1933 : "It will add at most one change output to the outputs.\n"
# 745 : 1933 : "No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n"
# 746 : 1933 : "Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n"
# 747 : 1933 : "The inputs added will not be signed, use signrawtransactionwithkey\n"
# 748 : 1933 : "or signrawtransactionwithwallet for that.\n"
# 749 : 1933 : "All existing inputs must either have their previous output transaction be in the wallet\n"
# 750 : 1933 : "or be in the UTXO set. Solving data must be provided for non-wallet inputs.\n"
# 751 : 1933 : "Note that all inputs selected must be of standard form and P2SH scripts must be\n"
# 752 : 1933 : "in the wallet using importaddress or addmultisigaddress (to calculate fees).\n"
# 753 : 1933 : "You can see whether this is the case by checking the \"solvable\" field in the listunspent output.\n"
# 754 : 1933 : "Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only\n",
# 755 : 1933 : {
# 756 : 1933 : {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
# 757 : 1933 : {"options", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}",
# 758 : 1933 : Cat<std::vector<RPCArg>>(
# 759 : 1933 : {
# 760 : 1933 : {"add_inputs", RPCArg::Type::BOOL, RPCArg::Default{true}, "For a transaction with existing inputs, automatically include more if they are not enough."},
# 761 : 1933 : {"include_unsafe", RPCArg::Type::BOOL, RPCArg::Default{false}, "Include inputs that are not safe to spend (unconfirmed transactions from outside keys and unconfirmed replacement transactions).\n"
# 762 : 1933 : "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
# 763 : 1933 : "If that happens, you will need to fund the transaction with different inputs and republish it."},
# 764 : 1933 : {"changeAddress", RPCArg::Type::STR, RPCArg::DefaultHint{"automatic"}, "The bitcoin address to receive the change"},
# 765 : 1933 : {"changePosition", RPCArg::Type::NUM, RPCArg::DefaultHint{"random"}, "The index of the change output"},
# 766 : 1933 : {"change_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -changetype"}, "The output type to use. Only valid if changeAddress is not specified. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
# 767 : 1933 : {"includeWatching", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also select inputs which are watch only.\n"
# 768 : 1933 : "Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n"
# 769 : 1933 : "e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
# 770 : 1933 : {"lockUnspents", RPCArg::Type::BOOL, RPCArg::Default{false}, "Lock selected unspent outputs"},
# 771 : 1933 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
# 772 : 1933 : {"feeRate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_UNIT + "/kvB."},
# 773 : 1933 : {"subtractFeeFromOutputs", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "The integers.\n"
# 774 : 1933 : "The fee will be equally deducted from the amount of each specified output.\n"
# 775 : 1933 : "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
# 776 : 1933 : "If no outputs are specified here, the sender pays the fee.",
# 777 : 1933 : {
# 778 : 1933 : {"vout_index", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The zero-based output index, before a change output is added."},
# 779 : 1933 : },
# 780 : 1933 : },
# 781 : 1933 : {"input_weights", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "Inputs and their corresponding weights",
# 782 : 1933 : {
# 783 : 1933 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
# 784 : 1933 : {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output index"},
# 785 : 1933 : {"weight", RPCArg::Type::NUM, RPCArg::Optional::NO, "The maximum weight for this input, "
# 786 : 1933 : "including the weight of the outpoint and sequence number. "
# 787 : 1933 : "Note that serialized signature sizes are not guaranteed to be consistent, "
# 788 : 1933 : "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
# 789 : 1933 : "Remember to convert serialized sizes to weight units when necessary."},
# 790 : 1933 : },
# 791 : 1933 : },
# 792 : 1933 : },
# 793 : 1933 : FundTxDoc()),
# 794 : 1933 : "options"},
# 795 : 1933 : {"iswitness", RPCArg::Type::BOOL, RPCArg::DefaultHint{"depends on heuristic tests"}, "Whether the transaction hex is a serialized witness transaction.\n"
# 796 : 1933 : "If iswitness is not present, heuristic tests will be used in decoding.\n"
# 797 : 1933 : "If true, only witness deserialization will be tried.\n"
# 798 : 1933 : "If false, only non-witness deserialization will be tried.\n"
# 799 : 1933 : "This boolean should reflect whether the transaction has inputs\n"
# 800 : 1933 : "(e.g. fully valid, or on-chain transactions), if known by the caller."
# 801 : 1933 : },
# 802 : 1933 : },
# 803 : 1933 : RPCResult{
# 804 : 1933 : RPCResult::Type::OBJ, "", "",
# 805 : 1933 : {
# 806 : 1933 : {RPCResult::Type::STR_HEX, "hex", "The resulting raw transaction (hex-encoded string)"},
# 807 : 1933 : {RPCResult::Type::STR_AMOUNT, "fee", "Fee in " + CURRENCY_UNIT + " the resulting transaction pays"},
# 808 : 1933 : {RPCResult::Type::NUM, "changepos", "The position of the added change output, or -1"},
# 809 : 1933 : }
# 810 : 1933 : },
# 811 : 1933 : RPCExamples{
# 812 : 1933 : "\nCreate a transaction with no inputs\n"
# 813 : 1933 : + HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
# 814 : 1933 : "\nAdd sufficient unsigned inputs to meet the output value\n"
# 815 : 1933 : + HelpExampleCli("fundrawtransaction", "\"rawtransactionhex\"") +
# 816 : 1933 : "\nSign the transaction\n"
# 817 : 1933 : + HelpExampleCli("signrawtransactionwithwallet", "\"fundedtransactionhex\"") +
# 818 : 1933 : "\nSend the transaction\n"
# 819 : 1933 : + HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")
# 820 : 1933 : },
# 821 : 1933 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 822 : 1933 : {
# 823 : 349 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
# 824 [ - + ]: 349 : if (!pwallet) return NullUniValue;
# 825 : :
# 826 : 349 : RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType(), UniValue::VBOOL});
# 827 : :
# 828 : : // parse hex string from parameter
# 829 : 349 : CMutableTransaction tx;
# 830 [ + - ]: 349 : bool try_witness = request.params[2].isNull() ? true : request.params[2].get_bool();
# 831 [ + - ]: 349 : bool try_no_witness = request.params[2].isNull() ? true : !request.params[2].get_bool();
# 832 [ - + ]: 349 : if (!DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
# 833 : 0 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
# 834 : 0 : }
# 835 : :
# 836 : 349 : CAmount fee;
# 837 : 349 : int change_position;
# 838 : 349 : CCoinControl coin_control;
# 839 : : // Automatically select (additional) coins. Can be overridden by options.add_inputs.
# 840 : 349 : coin_control.m_add_inputs = true;
# 841 : 349 : FundTransaction(*pwallet, tx, fee, change_position, request.params[1], coin_control, /*override_min_fee=*/true);
# 842 : :
# 843 : 349 : UniValue result(UniValue::VOBJ);
# 844 : 349 : result.pushKV("hex", EncodeHexTx(CTransaction(tx)));
# 845 : 349 : result.pushKV("fee", ValueFromAmount(fee));
# 846 : 349 : result.pushKV("changepos", change_position);
# 847 : :
# 848 : 349 : return result;
# 849 : 349 : },
# 850 : 1933 : };
# 851 : 1933 : }
# 852 : :
# 853 : : RPCHelpMan signrawtransactionwithwallet()
# 854 : 2661 : {
# 855 : 2661 : return RPCHelpMan{"signrawtransactionwithwallet",
# 856 : 2661 : "\nSign inputs for raw transaction (serialized, hex-encoded).\n"
# 857 : 2661 : "The second optional argument (may be null) is an array of previous transaction outputs that\n"
# 858 : 2661 : "this transaction depends on but may not yet be in the block chain." +
# 859 : 2661 : HELP_REQUIRING_PASSPHRASE,
# 860 : 2661 : {
# 861 : 2661 : {"hexstring", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction hex string"},
# 862 : 2661 : {"prevtxs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "The previous dependent transaction outputs",
# 863 : 2661 : {
# 864 : 2661 : {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
# 865 : 2661 : {
# 866 : 2661 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
# 867 : 2661 : {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
# 868 : 2661 : {"scriptPubKey", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "script key"},
# 869 : 2661 : {"redeemScript", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "(required for P2SH) redeem script"},
# 870 : 2661 : {"witnessScript", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "(required for P2WSH or P2SH-P2WSH) witness script"},
# 871 : 2661 : {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::OMITTED, "(required for Segwit inputs) the amount spent"},
# 872 : 2661 : },
# 873 : 2661 : },
# 874 : 2661 : },
# 875 : 2661 : },
# 876 : 2661 : {"sighashtype", RPCArg::Type::STR, RPCArg::Default{"DEFAULT for Taproot, ALL otherwise"}, "The signature hash type. Must be one of\n"
# 877 : 2661 : " \"DEFAULT\"\n"
# 878 : 2661 : " \"ALL\"\n"
# 879 : 2661 : " \"NONE\"\n"
# 880 : 2661 : " \"SINGLE\"\n"
# 881 : 2661 : " \"ALL|ANYONECANPAY\"\n"
# 882 : 2661 : " \"NONE|ANYONECANPAY\"\n"
# 883 : 2661 : " \"SINGLE|ANYONECANPAY\""},
# 884 : 2661 : },
# 885 : 2661 : RPCResult{
# 886 : 2661 : RPCResult::Type::OBJ, "", "",
# 887 : 2661 : {
# 888 : 2661 : {RPCResult::Type::STR_HEX, "hex", "The hex-encoded raw transaction with signature(s)"},
# 889 : 2661 : {RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},
# 890 : 2661 : {RPCResult::Type::ARR, "errors", /*optional=*/true, "Script verification errors (if there are any)",
# 891 : 2661 : {
# 892 : 2661 : {RPCResult::Type::OBJ, "", "",
# 893 : 2661 : {
# 894 : 2661 : {RPCResult::Type::STR_HEX, "txid", "The hash of the referenced, previous transaction"},
# 895 : 2661 : {RPCResult::Type::NUM, "vout", "The index of the output to spent and used as input"},
# 896 : 2661 : {RPCResult::Type::ARR, "witness", "",
# 897 : 2661 : {
# 898 : 2661 : {RPCResult::Type::STR_HEX, "witness", ""},
# 899 : 2661 : }},
# 900 : 2661 : {RPCResult::Type::STR_HEX, "scriptSig", "The hex-encoded signature script"},
# 901 : 2661 : {RPCResult::Type::NUM, "sequence", "Script sequence number"},
# 902 : 2661 : {RPCResult::Type::STR, "error", "Verification or signing error related to the input"},
# 903 : 2661 : }},
# 904 : 2661 : }},
# 905 : 2661 : }
# 906 : 2661 : },
# 907 : 2661 : RPCExamples{
# 908 : 2661 : HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"")
# 909 : 2661 : + HelpExampleRpc("signrawtransactionwithwallet", "\"myhex\"")
# 910 : 2661 : },
# 911 : 2661 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 912 : 2661 : {
# 913 : 1077 : const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
# 914 [ - + ]: 1077 : if (!pwallet) return NullUniValue;
# 915 : :
# 916 : 1077 : RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true);
# 917 : :
# 918 : 1077 : CMutableTransaction mtx;
# 919 [ - + ]: 1077 : if (!DecodeHexTx(mtx, request.params[0].get_str())) {
# 920 : 0 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
# 921 : 0 : }
# 922 : :
# 923 : : // Sign the transaction
# 924 : 1077 : LOCK(pwallet->cs_wallet);
# 925 : 1077 : EnsureWalletIsUnlocked(*pwallet);
# 926 : :
# 927 : : // Fetch previous transactions (inputs):
# 928 : 1077 : std::map<COutPoint, Coin> coins;
# 929 [ + + ]: 8503 : for (const CTxIn& txin : mtx.vin) {
# 930 : 8503 : coins[txin.prevout]; // Create empty map entry keyed by prevout.
# 931 : 8503 : }
# 932 : 1077 : pwallet->chain().findCoins(coins);
# 933 : :
# 934 : : // Parse the prevtxs array
# 935 : 1077 : ParsePrevouts(request.params[1], nullptr, coins);
# 936 : :
# 937 : 1077 : int nHashType = ParseSighashString(request.params[2]);
# 938 : :
# 939 : : // Script verification errors
# 940 : 1077 : std::map<int, bilingual_str> input_errors;
# 941 : :
# 942 : 1077 : bool complete = pwallet->SignTransaction(mtx, coins, nHashType, input_errors);
# 943 : 1077 : UniValue result(UniValue::VOBJ);
# 944 : 1077 : SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
# 945 : 1077 : return result;
# 946 : 1077 : },
# 947 : 2661 : };
# 948 : 2661 : }
# 949 : :
# 950 : : static RPCHelpMan bumpfee_helper(std::string method_name)
# 951 : 3406 : {
# 952 : 3406 : const bool want_psbt = method_name == "psbtbumpfee";
# 953 : 3406 : const std::string incremental_fee{CFeeRate(DEFAULT_INCREMENTAL_RELAY_FEE).ToString(FeeEstimateMode::SAT_VB)};
# 954 : :
# 955 : 3406 : return RPCHelpMan{method_name,
# 956 : 3406 : "\nBumps the fee of an opt-in-RBF transaction T, replacing it with a new transaction B.\n"
# 957 [ + + ]: 3406 : + std::string(want_psbt ? "Returns a PSBT instead of creating and signing a new transaction.\n" : "") +
# 958 : 3406 : "An opt-in RBF transaction with the given txid must be in the wallet.\n"
# 959 : 3406 : "The command will pay the additional fee by reducing change outputs or adding inputs when necessary.\n"
# 960 : 3406 : "It may add a new change output if one does not already exist.\n"
# 961 : 3406 : "All inputs in the original transaction will be included in the replacement transaction.\n"
# 962 : 3406 : "The command will fail if the wallet or mempool contains a transaction that spends one of T's outputs.\n"
# 963 : 3406 : "By default, the new fee will be calculated automatically using the estimatesmartfee RPC.\n"
# 964 : 3406 : "The user can specify a confirmation target for estimatesmartfee.\n"
# 965 : 3406 : "Alternatively, the user can specify a fee rate in " + CURRENCY_ATOM + "/vB for the new transaction.\n"
# 966 : 3406 : "At a minimum, the new fee rate must be high enough to pay an additional new relay fee (incrementalfee\n"
# 967 : 3406 : "returned by getnetworkinfo) to enter the node's mempool.\n"
# 968 : 3406 : "* WARNING: before version 0.21, fee_rate was in " + CURRENCY_UNIT + "/kvB. As of 0.21, fee_rate is in " + CURRENCY_ATOM + "/vB. *\n",
# 969 : 3406 : {
# 970 : 3406 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The txid to be bumped"},
# 971 : 3406 : {"options", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "",
# 972 : 3406 : {
# 973 : 3406 : {"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks\n"},
# 974 : 3406 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"},
# 975 : 3406 : "\nSpecify a fee rate in " + CURRENCY_ATOM + "/vB instead of relying on the built-in fee estimator.\n"
# 976 : 3406 : "Must be at least " + incremental_fee + " higher than the current transaction fee rate.\n"
# 977 : 3406 : "WARNING: before version 0.21, fee_rate was in " + CURRENCY_UNIT + "/kvB. As of 0.21, fee_rate is in " + CURRENCY_ATOM + "/vB.\n"},
# 978 : 3406 : {"replaceable", RPCArg::Type::BOOL, RPCArg::Default{true}, "Whether the new transaction should still be\n"
# 979 : 3406 : "marked bip-125 replaceable. If true, the sequence numbers in the transaction will\n"
# 980 : 3406 : "be left unchanged from the original. If false, any input sequence numbers in the\n"
# 981 : 3406 : "original transaction that were less than 0xfffffffe will be increased to 0xfffffffe\n"
# 982 : 3406 : "so the new transaction will not be explicitly bip-125 replaceable (though it may\n"
# 983 : 3406 : "still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
# 984 : 3406 : "are replaceable).\n"},
# 985 : 3406 : {"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"unset"}, "The fee estimate mode, must be one of (case insensitive):\n"
# 986 : 3406 : "\"" + FeeModes("\"\n\"") + "\""},
# 987 : 3406 : },
# 988 : 3406 : "options"},
# 989 : 3406 : },
# 990 : 3406 : RPCResult{
# 991 : 3406 : RPCResult::Type::OBJ, "", "", Cat(
# 992 [ + + ]: 3406 : want_psbt ?
# 993 : 1590 : std::vector<RPCResult>{{RPCResult::Type::STR, "psbt", "The base64-encoded unsigned PSBT of the new transaction."}} :
# 994 : 3406 : std::vector<RPCResult>{{RPCResult::Type::STR_HEX, "txid", "The id of the new transaction."}},
# 995 : 3406 : {
# 996 : 3406 : {RPCResult::Type::STR_AMOUNT, "origfee", "The fee of the replaced transaction."},
# 997 : 3406 : {RPCResult::Type::STR_AMOUNT, "fee", "The fee of the new transaction."},
# 998 : 3406 : {RPCResult::Type::ARR, "errors", "Errors encountered during processing (may be empty).",
# 999 : 3406 : {
# 1000 : 3406 : {RPCResult::Type::STR, "", ""},
# 1001 : 3406 : }},
# 1002 : 3406 : })
# 1003 : 3406 : },
# 1004 : 3406 : RPCExamples{
# 1005 [ + + ]: 3406 : "\nBump the fee, get the new transaction\'s " + std::string(want_psbt ? "psbt" : "txid") + "\n" +
# 1006 : 3406 : HelpExampleCli(method_name, "<txid>")
# 1007 : 3406 : },
# 1008 : 3406 : [want_psbt](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 1009 : 3406 : {
# 1010 : 238 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
# 1011 [ - + ]: 238 : if (!pwallet) return NullUniValue;
# 1012 : :
# 1013 [ + + ][ + + ]: 238 : if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !want_psbt) {
# 1014 : 2 : throw JSONRPCError(RPC_WALLET_ERROR, "bumpfee is not available with wallets that have private keys disabled. Use psbtbumpfee instead.");
# 1015 : 2 : }
# 1016 : :
# 1017 : 236 : RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ});
# 1018 : 236 : uint256 hash(ParseHashV(request.params[0], "txid"));
# 1019 : :
# 1020 : 236 : CCoinControl coin_control;
# 1021 : 236 : coin_control.fAllowWatchOnly = pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
# 1022 : : // optional parameters
# 1023 : 236 : coin_control.m_signal_bip125_rbf = true;
# 1024 : :
# 1025 [ + + ]: 236 : if (!request.params[1].isNull()) {
# 1026 : 92 : UniValue options = request.params[1];
# 1027 : 92 : RPCTypeCheckObj(options,
# 1028 : 92 : {
# 1029 : 92 : {"confTarget", UniValueType(UniValue::VNUM)},
# 1030 : 92 : {"conf_target", UniValueType(UniValue::VNUM)},
# 1031 : 92 : {"fee_rate", UniValueType()}, // will be checked by AmountFromValue() in SetFeeEstimateMode()
# 1032 : 92 : {"replaceable", UniValueType(UniValue::VBOOL)},
# 1033 : 92 : {"estimate_mode", UniValueType(UniValue::VSTR)},
# 1034 : 92 : },
# 1035 : 92 : true, true);
# 1036 : :
# 1037 [ + + ][ + + ]: 92 : if (options.exists("confTarget") && options.exists("conf_target")) {
# [ + - ]
# 1038 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "confTarget and conf_target options should not both be set. Use conf_target (confTarget is deprecated).");
# 1039 : 2 : }
# 1040 : :
# 1041 [ - + ]: 90 : auto conf_target = options.exists("confTarget") ? options["confTarget"] : options["conf_target"];
# 1042 : :
# 1043 [ + + ]: 90 : if (options.exists("replaceable")) {
# 1044 : 2 : coin_control.m_signal_bip125_rbf = options["replaceable"].get_bool();
# 1045 : 2 : }
# 1046 : 90 : SetFeeEstimateMode(*pwallet, coin_control, conf_target, options["estimate_mode"], options["fee_rate"], /*override_min_fee=*/false);
# 1047 : 90 : }
# 1048 : :
# 1049 : : // Make sure the results are valid at least up to the most recent block
# 1050 : : // the user could have gotten from another RPC command prior to now
# 1051 : 234 : pwallet->BlockUntilSyncedToCurrentChain();
# 1052 : :
# 1053 : 234 : LOCK(pwallet->cs_wallet);
# 1054 : :
# 1055 : 234 : EnsureWalletIsUnlocked(*pwallet);
# 1056 : :
# 1057 : :
# 1058 : 234 : std::vector<bilingual_str> errors;
# 1059 : 234 : CAmount old_fee;
# 1060 : 234 : CAmount new_fee;
# 1061 : 234 : CMutableTransaction mtx;
# 1062 : 234 : feebumper::Result res;
# 1063 : : // Targeting feerate bump.
# 1064 : 234 : res = feebumper::CreateRateBumpTransaction(*pwallet, hash, coin_control, errors, old_fee, new_fee, mtx);
# 1065 [ + + ]: 234 : if (res != feebumper::Result::OK) {
# 1066 : 32 : switch(res) {
# 1067 [ - + ]: 0 : case feebumper::Result::INVALID_ADDRESS_OR_KEY:
# 1068 : 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, errors[0].original);
# 1069 : 0 : break;
# 1070 [ - + ]: 0 : case feebumper::Result::INVALID_REQUEST:
# 1071 : 0 : throw JSONRPCError(RPC_INVALID_REQUEST, errors[0].original);
# 1072 : 0 : break;
# 1073 [ + + ]: 18 : case feebumper::Result::INVALID_PARAMETER:
# 1074 : 18 : throw JSONRPCError(RPC_INVALID_PARAMETER, errors[0].original);
# 1075 : 0 : break;
# 1076 [ + + ]: 14 : case feebumper::Result::WALLET_ERROR:
# 1077 : 14 : throw JSONRPCError(RPC_WALLET_ERROR, errors[0].original);
# 1078 : 0 : break;
# 1079 [ - + ]: 0 : default:
# 1080 : 0 : throw JSONRPCError(RPC_MISC_ERROR, errors[0].original);
# 1081 : 0 : break;
# 1082 : 32 : }
# 1083 : 32 : }
# 1084 : :
# 1085 : 202 : UniValue result(UniValue::VOBJ);
# 1086 : :
# 1087 : : // For bumpfee, return the new transaction id.
# 1088 : : // For psbtbumpfee, return the base64-encoded unsigned PSBT of the new transaction.
# 1089 [ + + ]: 202 : if (!want_psbt) {
# 1090 [ - + ]: 140 : if (!feebumper::SignTransaction(*pwallet, mtx)) {
# 1091 : 0 : throw JSONRPCError(RPC_WALLET_ERROR, "Can't sign transaction.");
# 1092 : 0 : }
# 1093 : :
# 1094 : 140 : uint256 txid;
# 1095 [ - + ]: 140 : if (feebumper::CommitTransaction(*pwallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) {
# 1096 : 0 : throw JSONRPCError(RPC_WALLET_ERROR, errors[0].original);
# 1097 : 0 : }
# 1098 : :
# 1099 : 140 : result.pushKV("txid", txid.GetHex());
# 1100 : 140 : } else {
# 1101 : 62 : PartiallySignedTransaction psbtx(mtx);
# 1102 : 62 : bool complete = false;
# 1103 : 62 : const TransactionError err = pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, false /* sign */, true /* bip32derivs */);
# 1104 [ - + ]: 62 : CHECK_NONFATAL(err == TransactionError::OK);
# 1105 [ - + ]: 62 : CHECK_NONFATAL(!complete);
# 1106 : 62 : CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
# 1107 : 62 : ssTx << psbtx;
# 1108 : 62 : result.pushKV("psbt", EncodeBase64(ssTx.str()));
# 1109 : 62 : }
# 1110 : :
# 1111 : 202 : result.pushKV("origfee", ValueFromAmount(old_fee));
# 1112 : 202 : result.pushKV("fee", ValueFromAmount(new_fee));
# 1113 : 202 : UniValue result_errors(UniValue::VARR);
# 1114 [ - + ]: 202 : for (const bilingual_str& error : errors) {
# 1115 : 0 : result_errors.push_back(error.original);
# 1116 : 0 : }
# 1117 : 202 : result.pushKV("errors", result_errors);
# 1118 : :
# 1119 : 202 : return result;
# 1120 : 202 : },
# 1121 : 3406 : };
# 1122 : 3406 : }
# 1123 : :
# 1124 : 1816 : RPCHelpMan bumpfee() { return bumpfee_helper("bumpfee"); }
# 1125 : 1590 : RPCHelpMan psbtbumpfee() { return bumpfee_helper("psbtbumpfee"); }
# 1126 : :
# 1127 : : RPCHelpMan send()
# 1128 : 1826 : {
# 1129 : 1826 : return RPCHelpMan{"send",
# 1130 : 1826 : "\nEXPERIMENTAL warning: this call may be changed in future releases.\n"
# 1131 : 1826 : "\nSend a transaction.\n",
# 1132 : 1826 : {
# 1133 : 1826 : {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The outputs (key-value pairs), where none of the keys are duplicated.\n"
# 1134 : 1826 : "That is, each address can only appear once and there can only be one 'data' object.\n"
# 1135 : 1826 : "For convenience, a dictionary, which holds the key-value pairs directly, is also accepted.",
# 1136 : 1826 : {
# 1137 : 1826 : {"", RPCArg::Type::OBJ_USER_KEYS, RPCArg::Optional::OMITTED, "",
# 1138 : 1826 : {
# 1139 : 1826 : {"address", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "A key-value pair. The key (string) is the bitcoin address, the value (float or string) is the amount in " + CURRENCY_UNIT + ""},
# 1140 : 1826 : },
# 1141 : 1826 : },
# 1142 : 1826 : {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
# 1143 : 1826 : {
# 1144 : 1826 : {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data"},
# 1145 : 1826 : },
# 1146 : 1826 : },
# 1147 : 1826 : },
# 1148 : 1826 : },
# 1149 : 1826 : {"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks"},
# 1150 : 1826 : {"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"unset"}, std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
# 1151 : 1826 : " \"" + FeeModes("\"\n\"") + "\""},
# 1152 : 1826 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
# 1153 : 1826 : {"options", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "",
# 1154 : 1826 : Cat<std::vector<RPCArg>>(
# 1155 : 1826 : {
# 1156 : 1826 : {"add_inputs", RPCArg::Type::BOOL, RPCArg::Default{false}, "If inputs are specified, automatically include more if they are not enough."},
# 1157 : 1826 : {"include_unsafe", RPCArg::Type::BOOL, RPCArg::Default{false}, "Include inputs that are not safe to spend (unconfirmed transactions from outside keys and unconfirmed replacement transactions).\n"
# 1158 : 1826 : "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
# 1159 : 1826 : "If that happens, you will need to fund the transaction with different inputs and republish it."},
# 1160 : 1826 : {"add_to_wallet", RPCArg::Type::BOOL, RPCArg::Default{true}, "When false, returns a serialized transaction which will not be added to the wallet or broadcast"},
# 1161 : 1826 : {"change_address", RPCArg::Type::STR, RPCArg::DefaultHint{"automatic"}, "The bitcoin address to receive the change"},
# 1162 : 1826 : {"change_position", RPCArg::Type::NUM, RPCArg::DefaultHint{"random"}, "The index of the change output"},
# 1163 : 1826 : {"change_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -changetype"}, "The output type to use. Only valid if change_address is not specified. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
# 1164 : 1826 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
# 1165 : 1826 : {"include_watching", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also select inputs which are watch only.\n"
# 1166 : 1826 : "Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n"
# 1167 : 1826 : "e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
# 1168 : 1826 : {"inputs", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Specify inputs instead of adding them automatically. A JSON array of JSON objects",
# 1169 : 1826 : {
# 1170 : 1826 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
# 1171 : 1826 : {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
# 1172 : 1826 : {"sequence", RPCArg::Type::NUM, RPCArg::Optional::NO, "The sequence number"},
# 1173 : 1826 : {"weight", RPCArg::Type::NUM, RPCArg::DefaultHint{"Calculated from wallet and solving data"}, "The maximum weight for this input, "
# 1174 : 1826 : "including the weight of the outpoint and sequence number. "
# 1175 : 1826 : "Note that signature sizes are not guaranteed to be consistent, "
# 1176 : 1826 : "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
# 1177 : 1826 : "Remember to convert serialized sizes to weight units when necessary."},
# 1178 : 1826 : },
# 1179 : 1826 : },
# 1180 : 1826 : {"locktime", RPCArg::Type::NUM, RPCArg::Default{0}, "Raw locktime. Non-0 value also locktime-activates inputs"},
# 1181 : 1826 : {"lock_unspents", RPCArg::Type::BOOL, RPCArg::Default{false}, "Lock selected unspent outputs"},
# 1182 : 1826 : {"psbt", RPCArg::Type::BOOL, RPCArg::DefaultHint{"automatic"}, "Always return a PSBT, implies add_to_wallet=false."},
# 1183 : 1826 : {"subtract_fee_from_outputs", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Outputs to subtract the fee from, specified as integer indices.\n"
# 1184 : 1826 : "The fee will be equally deducted from the amount of each specified output.\n"
# 1185 : 1826 : "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
# 1186 : 1826 : "If no outputs are specified here, the sender pays the fee.",
# 1187 : 1826 : {
# 1188 : 1826 : {"vout_index", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The zero-based output index, before a change output is added."},
# 1189 : 1826 : },
# 1190 : 1826 : },
# 1191 : 1826 : },
# 1192 : 1826 : FundTxDoc()),
# 1193 : 1826 : "options"},
# 1194 : 1826 : },
# 1195 : 1826 : RPCResult{
# 1196 : 1826 : RPCResult::Type::OBJ, "", "",
# 1197 : 1826 : {
# 1198 : 1826 : {RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},
# 1199 : 1826 : {RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id for the send. Only 1 transaction is created regardless of the number of addresses."},
# 1200 : 1826 : {RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},
# 1201 : 1826 : {RPCResult::Type::STR, "psbt", /*optional=*/true, "If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed transaction"}
# 1202 : 1826 : }
# 1203 : 1826 : },
# 1204 : 1826 : RPCExamples{""
# 1205 : 1826 : "\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode\n"
# 1206 : 1826 : + HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.1}' 6 economical\n") +
# 1207 : 1826 : "Send 0.2 BTC with a fee rate of 1.1 " + CURRENCY_ATOM + "/vB using positional arguments\n"
# 1208 : 1826 : + HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' null \"unset\" 1.1\n") +
# 1209 : 1826 : "Send 0.2 BTC with a fee rate of 1 " + CURRENCY_ATOM + "/vB using the options argument\n"
# 1210 : 1826 : + HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' null \"unset\" null '{\"fee_rate\": 1}'\n") +
# 1211 : 1826 : "Send 0.3 BTC with a fee rate of 25 " + CURRENCY_ATOM + "/vB using named arguments\n"
# 1212 : 1826 : + HelpExampleCli("-named send", "outputs='{\"" + EXAMPLE_ADDRESS[0] + "\": 0.3}' fee_rate=25\n") +
# 1213 : 1826 : "Create a transaction that should confirm the next block, with a specific input, and return result without adding to wallet or broadcasting to the network\n"
# 1214 : 1826 : + HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.1}' 1 economical '{\"add_to_wallet\": false, \"inputs\": [{\"txid\":\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\", \"vout\":1}]}'")
# 1215 : 1826 : },
# 1216 : 1826 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 1217 : 1826 : {
# 1218 : 242 : RPCTypeCheck(request.params, {
# 1219 : 242 : UniValueType(), // outputs (ARR or OBJ, checked later)
# 1220 : 242 : UniValue::VNUM, // conf_target
# 1221 : 242 : UniValue::VSTR, // estimate_mode
# 1222 : 242 : UniValueType(), // fee_rate, will be checked by AmountFromValue() in SetFeeEstimateMode()
# 1223 : 242 : UniValue::VOBJ, // options
# 1224 : 242 : }, true
# 1225 : 242 : );
# 1226 : :
# 1227 : 242 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
# 1228 [ - + ]: 242 : if (!pwallet) return NullUniValue;
# 1229 : :
# 1230 [ + + ]: 242 : UniValue options{request.params[4].isNull() ? UniValue::VOBJ : request.params[4]};
# 1231 : 242 : InterpretFeeEstimationInstructions(/*conf_target=*/request.params[1], /*estimate_mode=*/request.params[2], /*fee_rate=*/request.params[3], options);
# 1232 : 242 : PreventOutdatedOptions(options);
# 1233 : :
# 1234 : :
# 1235 : 242 : CAmount fee;
# 1236 : 242 : int change_position;
# 1237 [ + + ]: 242 : bool rbf{options.exists("replaceable") ? options["replaceable"].get_bool() : pwallet->m_signal_rbf};
# 1238 : 242 : CMutableTransaction rawTx = ConstructTransaction(options["inputs"], request.params[0], options["locktime"], rbf);
# 1239 : 242 : CCoinControl coin_control;
# 1240 : : // Automatically select coins, unless at least one is manually selected. Can
# 1241 : : // be overridden by options.add_inputs.
# 1242 : 242 : coin_control.m_add_inputs = rawTx.vin.size() == 0;
# 1243 : 242 : SetOptionsInputWeights(options["inputs"], options);
# 1244 : 242 : FundTransaction(*pwallet, rawTx, fee, change_position, options, coin_control, /*override_min_fee=*/false);
# 1245 : :
# 1246 : 242 : return FinishTransaction(pwallet, options, rawTx);
# 1247 : 242 : }
# 1248 : 1826 : };
# 1249 : 1826 : }
# 1250 : :
# 1251 : : RPCHelpMan sendall()
# 1252 : 1643 : {
# 1253 : 1643 : return RPCHelpMan{"sendall",
# 1254 : 1643 : "EXPERIMENTAL warning: this call may be changed in future releases.\n"
# 1255 : 1643 : "\nSpend the value of all (or specific) confirmed UTXOs in the wallet to one or more recipients.\n"
# 1256 : 1643 : "Unconfirmed inbound UTXOs and locked UTXOs will not be spent. Sendall will respect the avoid_reuse wallet flag.\n"
# 1257 : 1643 : "If your wallet contains many small inputs, either because it received tiny payments or as a result of accumulating change, consider using `send_max` to exclude inputs that are worth less than the fees needed to spend them.\n",
# 1258 : 1643 : {
# 1259 : 1643 : {"recipients", RPCArg::Type::ARR, RPCArg::Optional::NO, "The sendall destinations. Each address may only appear once.\n"
# 1260 : 1643 : "Optionally some recipients can be specified with an amount to perform payments, but at least one address must appear without a specified amount.\n",
# 1261 : 1643 : {
# 1262 : 1643 : {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "A bitcoin address which receives an equal share of the unspecified amount."},
# 1263 : 1643 : {"", RPCArg::Type::OBJ_USER_KEYS, RPCArg::Optional::OMITTED, "",
# 1264 : 1643 : {
# 1265 : 1643 : {"address", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "A key-value pair. The key (string) is the bitcoin address, the value (float or string) is the amount in " + CURRENCY_UNIT + ""},
# 1266 : 1643 : },
# 1267 : 1643 : },
# 1268 : 1643 : },
# 1269 : 1643 : },
# 1270 : 1643 : {"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks"},
# 1271 : 1643 : {"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"unset"}, std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
# 1272 : 1643 : " \"" + FeeModes("\"\n\"") + "\""},
# 1273 : 1643 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
# 1274 : 1643 : {
# 1275 : 1643 : "options", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "",
# 1276 : 1643 : Cat<std::vector<RPCArg>>(
# 1277 : 1643 : {
# 1278 : 1643 : {"add_to_wallet", RPCArg::Type::BOOL, RPCArg::Default{true}, "When false, returns the serialized transaction without broadcasting or adding it to the wallet"},
# 1279 : 1643 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
# 1280 : 1643 : {"include_watching", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also select inputs which are watch-only.\n"
# 1281 : 1643 : "Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n"
# 1282 : 1643 : "e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
# 1283 : 1643 : {"inputs", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Use exactly the specified inputs to build the transaction. Specifying inputs is incompatible with send_max. A JSON array of JSON objects",
# 1284 : 1643 : {
# 1285 : 1643 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
# 1286 : 1643 : {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
# 1287 : 1643 : {"sequence", RPCArg::Type::NUM, RPCArg::Optional::NO, "The sequence number"},
# 1288 : 1643 : },
# 1289 : 1643 : },
# 1290 : 1643 : {"locktime", RPCArg::Type::NUM, RPCArg::Default{0}, "Raw locktime. Non-0 value also locktime-activates inputs"},
# 1291 : 1643 : {"lock_unspents", RPCArg::Type::BOOL, RPCArg::Default{false}, "Lock selected unspent outputs"},
# 1292 : 1643 : {"psbt", RPCArg::Type::BOOL, RPCArg::DefaultHint{"automatic"}, "Always return a PSBT, implies add_to_wallet=false."},
# 1293 : 1643 : {"send_max", RPCArg::Type::BOOL, RPCArg::Default{false}, "When true, only use UTXOs that can pay for their own fees to maximize the output amount. When 'false' (default), no UTXO is left behind. send_max is incompatible with providing specific inputs."},
# 1294 : 1643 : },
# 1295 : 1643 : FundTxDoc()
# 1296 : 1643 : ),
# 1297 : 1643 : "options"
# 1298 : 1643 : },
# 1299 : 1643 : },
# 1300 : 1643 : RPCResult{
# 1301 : 1643 : RPCResult::Type::OBJ, "", "",
# 1302 : 1643 : {
# 1303 : 1643 : {RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},
# 1304 : 1643 : {RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id for the send. Only 1 transaction is created regardless of the number of addresses."},
# 1305 : 1643 : {RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},
# 1306 : 1643 : {RPCResult::Type::STR, "psbt", /*optional=*/true, "If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially) signed transaction"}
# 1307 : 1643 : }
# 1308 : 1643 : },
# 1309 : 1643 : RPCExamples{""
# 1310 : 1643 : "\nSpend all UTXOs from the wallet with a fee rate of 1 " + CURRENCY_ATOM + "/vB using named arguments\n"
# 1311 : 1643 : + HelpExampleCli("-named sendall", "recipients='[\"" + EXAMPLE_ADDRESS[0] + "\"]' fee_rate=1\n") +
# 1312 : 1643 : "Spend all UTXOs with a fee rate of 1.1 " + CURRENCY_ATOM + "/vB using positional arguments\n"
# 1313 : 1643 : + HelpExampleCli("sendall", "'[\"" + EXAMPLE_ADDRESS[0] + "\"]' null \"unset\" 1.1\n") +
# 1314 : 1643 : "Spend all UTXOs split into equal amounts to two addresses with a fee rate of 1.5 " + CURRENCY_ATOM + "/vB using the options argument\n"
# 1315 : 1643 : + HelpExampleCli("sendall", "'[\"" + EXAMPLE_ADDRESS[0] + "\", \"" + EXAMPLE_ADDRESS[1] + "\"]' null \"unset\" null '{\"fee_rate\": 1.5}'\n") +
# 1316 : 1643 : "Leave dust UTXOs in wallet, spend only UTXOs with positive effective value with a fee rate of 10 " + CURRENCY_ATOM + "/vB using the options argument\n"
# 1317 : 1643 : + HelpExampleCli("sendall", "'[\"" + EXAMPLE_ADDRESS[0] + "\"]' null \"unset\" null '{\"fee_rate\": 10, \"send_max\": true}'\n") +
# 1318 : 1643 : "Spend all UTXOs with a fee rate of 1.3 " + CURRENCY_ATOM + "/vB using named arguments and sending a 0.25 " + CURRENCY_UNIT + " to another recipient\n"
# 1319 : 1643 : + HelpExampleCli("-named sendall", "recipients='[{\"" + EXAMPLE_ADDRESS[1] + "\": 0.25}, \""+ EXAMPLE_ADDRESS[0] + "\"]' fee_rate=1.3\n")
# 1320 : 1643 : },
# 1321 : 1643 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 1322 : 1643 : {
# 1323 : 59 : RPCTypeCheck(request.params, {
# 1324 : 59 : UniValue::VARR, // recipients
# 1325 : 59 : UniValue::VNUM, // conf_target
# 1326 : 59 : UniValue::VSTR, // estimate_mode
# 1327 : 59 : UniValueType(), // fee_rate, will be checked by AmountFromValue() in SetFeeEstimateMode()
# 1328 : 59 : UniValue::VOBJ, // options
# 1329 : 59 : }, true
# 1330 : 59 : );
# 1331 : :
# 1332 : 59 : std::shared_ptr<CWallet> const pwallet{GetWalletForJSONRPCRequest(request)};
# 1333 [ - + ]: 59 : if (!pwallet) return NullUniValue;
# 1334 : : // Make sure the results are valid at least up to the most recent block
# 1335 : : // the user could have gotten from another RPC command prior to now
# 1336 : 59 : pwallet->BlockUntilSyncedToCurrentChain();
# 1337 : :
# 1338 [ + + ]: 59 : UniValue options{request.params[4].isNull() ? UniValue::VOBJ : request.params[4]};
# 1339 : 59 : InterpretFeeEstimationInstructions(/*conf_target=*/request.params[1], /*estimate_mode=*/request.params[2], /*fee_rate=*/request.params[3], options);
# 1340 : 59 : PreventOutdatedOptions(options);
# 1341 : :
# 1342 : :
# 1343 : 59 : std::set<std::string> addresses_without_amount;
# 1344 : 59 : UniValue recipient_key_value_pairs(UniValue::VARR);
# 1345 : 59 : const UniValue& recipients{request.params[0]};
# 1346 [ + + ]: 135 : for (unsigned int i = 0; i < recipients.size(); ++i) {
# 1347 : 76 : const UniValue& recipient{recipients[i]};
# 1348 [ + + ]: 76 : if (recipient.isStr()) {
# 1349 : 59 : UniValue rkvp(UniValue::VOBJ);
# 1350 : 59 : rkvp.pushKV(recipient.get_str(), 0);
# 1351 : 59 : recipient_key_value_pairs.push_back(rkvp);
# 1352 : 59 : addresses_without_amount.insert(recipient.get_str());
# 1353 : 59 : } else {
# 1354 : 17 : recipient_key_value_pairs.push_back(recipient);
# 1355 : 17 : }
# 1356 : 76 : }
# 1357 : :
# 1358 [ + + ]: 59 : if (addresses_without_amount.size() == 0) {
# 1359 : 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Must provide at least one address without a specified amount");
# 1360 : 4 : }
# 1361 : :
# 1362 : 55 : CCoinControl coin_control;
# 1363 : :
# 1364 : 55 : SetFeeEstimateMode(*pwallet, coin_control, options["conf_target"], options["estimate_mode"], options["fee_rate"], /*override_min_fee=*/false);
# 1365 : :
# 1366 : 55 : coin_control.fAllowWatchOnly = ParseIncludeWatchonly(options["include_watching"], *pwallet);
# 1367 : :
# 1368 [ - + ]: 55 : const bool rbf{options.exists("replaceable") ? options["replaceable"].get_bool() : pwallet->m_signal_rbf};
# 1369 : :
# 1370 : 55 : FeeCalculation fee_calc_out;
# 1371 : 55 : CFeeRate fee_rate{GetMinimumFeeRate(*pwallet, coin_control, &fee_calc_out)};
# 1372 : : // Do not, ever, assume that it's fine to change the fee rate if the user has explicitly
# 1373 : : // provided one
# 1374 [ + + ][ - + ]: 55 : if (coin_control.m_feerate && fee_rate > *coin_control.m_feerate) {
# 1375 : 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Fee rate (%s) is lower than the minimum fee rate setting (%s)", coin_control.m_feerate->ToString(FeeEstimateMode::SAT_VB), fee_rate.ToString(FeeEstimateMode::SAT_VB)));
# 1376 : 0 : }
# 1377 [ + + ][ - + ]: 55 : if (fee_calc_out.reason == FeeReason::FALLBACK && !pwallet->m_allow_fallback_fee) {
# 1378 : : // eventually allow a fallback fee
# 1379 : 0 : throw JSONRPCError(RPC_WALLET_ERROR, "Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.");
# 1380 : 0 : }
# 1381 : :
# 1382 : 55 : CMutableTransaction rawTx{ConstructTransaction(options["inputs"], recipient_key_value_pairs, options["locktime"], rbf)};
# 1383 : 55 : LOCK(pwallet->cs_wallet);
# 1384 : 55 : std::vector<COutput> all_the_utxos;
# 1385 : :
# 1386 : 55 : CAmount total_input_value(0);
# 1387 [ + + ]: 55 : bool send_max{options.exists("send_max") ? options["send_max"].get_bool() : false};
# 1388 [ + + ][ + + ]: 55 : if (options.exists("inputs") && options.exists("send_max")) {
# [ + + ]
# 1389 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot combine send_max with specific inputs.");
# 1390 [ + + ]: 53 : } else if (options.exists("inputs")) {
# 1391 [ + + ]: 8 : for (const CTxIn& input : rawTx.vin) {
# 1392 [ + + ]: 8 : if (pwallet->IsSpent(input.prevout.hash, input.prevout.n)) {
# 1393 : 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Input not available. UTXO (%s:%d) was already spent.", input.prevout.hash.ToString(), input.prevout.n));
# 1394 : 4 : }
# 1395 : 4 : const CWalletTx* tx{pwallet->GetWalletTx(input.prevout.hash)};
# 1396 [ - + ][ + + ]: 4 : if (!tx || pwallet->IsMine(tx->tx->vout[input.prevout.n]) != (coin_control.fAllowWatchOnly ? ISMINE_ALL : ISMINE_SPENDABLE)) {
# [ - + ]
# 1397 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Input not found. UTXO (%s:%d) is not part of wallet.", input.prevout.hash.ToString(), input.prevout.n));
# 1398 : 2 : }
# 1399 : 2 : total_input_value += tx->tx->vout[input.prevout.n].nValue;
# 1400 : 2 : }
# 1401 : 45 : } else {
# 1402 : 45 : AvailableCoins(*pwallet, all_the_utxos, &coin_control, /*nMinimumAmount=*/0);
# 1403 [ + + ]: 97 : for (const COutput& output : all_the_utxos) {
# 1404 [ - + ]: 97 : CHECK_NONFATAL(output.input_bytes > 0);
# 1405 [ + + ][ + + ]: 97 : if (send_max && fee_rate.GetFee(output.input_bytes) > output.txout.nValue) {
# 1406 : 4 : continue;
# 1407 : 4 : }
# 1408 [ - + ]: 93 : CTxIn input(output.outpoint.hash, output.outpoint.n, CScript(), rbf ? MAX_BIP125_RBF_SEQUENCE : CTxIn::SEQUENCE_FINAL);
# 1409 : 93 : rawTx.vin.push_back(input);
# 1410 : 93 : total_input_value += output.txout.nValue;
# 1411 : 93 : }
# 1412 : 45 : }
# 1413 : :
# 1414 : : // estimate final size of tx
# 1415 : 47 : const TxSize tx_size{CalculateMaximumSignedTxSize(CTransaction(rawTx), pwallet.get())};
# 1416 : 47 : const CAmount fee_from_size{fee_rate.GetFee(tx_size.vsize)};
# 1417 : 47 : const CAmount effective_value{total_input_value - fee_from_size};
# 1418 : :
# 1419 [ + + ]: 47 : if (effective_value <= 0) {
# 1420 [ - + ]: 2 : if (send_max) {
# 1421 : 0 : throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Total value of UTXO pool too low to pay for transaction, try using lower feerate.");
# 1422 : 2 : } else {
# 1423 : 2 : throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Total value of UTXO pool too low to pay for transaction. Try using lower feerate or excluding uneconomic UTXOs with 'send_max' option.");
# 1424 : 2 : }
# 1425 : 2 : }
# 1426 : :
# 1427 : 45 : CAmount output_amounts_claimed{0};
# 1428 [ + + ]: 60 : for (CTxOut out : rawTx.vout) {
# 1429 : 60 : output_amounts_claimed += out.nValue;
# 1430 : 60 : }
# 1431 : :
# 1432 [ + + ]: 45 : if (output_amounts_claimed > total_input_value) {
# 1433 : 2 : throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Assigned more value to outputs than available funds.");
# 1434 : 2 : }
# 1435 : :
# 1436 : 43 : const CAmount remainder{effective_value - output_amounts_claimed};
# 1437 [ + + ]: 43 : if (remainder < 0) {
# 1438 : 2 : throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds for fees after creating specified outputs.");
# 1439 : 2 : }
# 1440 : :
# 1441 : 41 : const CAmount per_output_without_amount{remainder / (long)addresses_without_amount.size()};
# 1442 : :
# 1443 : 41 : bool gave_remaining_to_first{false};
# 1444 [ + + ]: 50 : for (CTxOut& out : rawTx.vout) {
# 1445 : 50 : CTxDestination dest;
# 1446 : 50 : ExtractDestination(out.scriptPubKey, dest);
# 1447 : 50 : std::string addr{EncodeDestination(dest)};
# 1448 [ + + ]: 50 : if (addresses_without_amount.count(addr) > 0) {
# 1449 : 39 : out.nValue = per_output_without_amount;
# 1450 [ + + ]: 39 : if (!gave_remaining_to_first) {
# 1451 : 37 : out.nValue += remainder % addresses_without_amount.size();
# 1452 : 37 : gave_remaining_to_first = true;
# 1453 : 37 : }
# 1454 [ + + ]: 39 : if (IsDust(out, pwallet->chain().relayDustFee())) {
# 1455 : : // Dynamically generated output amount is dust
# 1456 : 4 : throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Dynamically assigned remainder results in dust output.");
# 1457 : 4 : }
# 1458 : 39 : } else {
# 1459 [ + + ]: 11 : if (IsDust(out, pwallet->chain().relayDustFee())) {
# 1460 : : // Specified output amount is dust
# 1461 : 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Specified output amount to %s is below dust threshold.", addr));
# 1462 : 2 : }
# 1463 : 11 : }
# 1464 : 50 : }
# 1465 : :
# 1466 [ - + ]: 35 : const bool lock_unspents{options.exists("lock_unspents") ? options["lock_unspents"].get_bool() : false};
# 1467 [ - + ]: 35 : if (lock_unspents) {
# 1468 [ # # ]: 0 : for (const CTxIn& txin : rawTx.vin) {
# 1469 : 0 : pwallet->LockCoin(txin.prevout);
# 1470 : 0 : }
# 1471 : 0 : }
# 1472 : :
# 1473 : 35 : return FinishTransaction(pwallet, options, rawTx);
# 1474 : 41 : }
# 1475 : 1643 : };
# 1476 : 1643 : }
# 1477 : :
# 1478 : : RPCHelpMan walletprocesspsbt()
# 1479 : 1887 : {
# 1480 : 1887 : return RPCHelpMan{"walletprocesspsbt",
# 1481 : 1887 : "\nUpdate a PSBT with input information from our wallet and then sign inputs\n"
# 1482 : 1887 : "that we can sign for." +
# 1483 : 1887 : HELP_REQUIRING_PASSPHRASE,
# 1484 : 1887 : {
# 1485 : 1887 : {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction base64 string"},
# 1486 : 1887 : {"sign", RPCArg::Type::BOOL, RPCArg::Default{true}, "Also sign the transaction when updating (requires wallet to be unlocked)"},
# 1487 : 1887 : {"sighashtype", RPCArg::Type::STR, RPCArg::Default{"DEFAULT for Taproot, ALL otherwise"}, "The signature hash type to sign with if not specified by the PSBT. Must be one of\n"
# 1488 : 1887 : " \"DEFAULT\"\n"
# 1489 : 1887 : " \"ALL\"\n"
# 1490 : 1887 : " \"NONE\"\n"
# 1491 : 1887 : " \"SINGLE\"\n"
# 1492 : 1887 : " \"ALL|ANYONECANPAY\"\n"
# 1493 : 1887 : " \"NONE|ANYONECANPAY\"\n"
# 1494 : 1887 : " \"SINGLE|ANYONECANPAY\""},
# 1495 : 1887 : {"bip32derivs", RPCArg::Type::BOOL, RPCArg::Default{true}, "Include BIP 32 derivation paths for public keys if we know them"},
# 1496 : 1887 : {"finalize", RPCArg::Type::BOOL, RPCArg::Default{true}, "Also finalize inputs if possible"},
# 1497 : 1887 : },
# 1498 : 1887 : RPCResult{
# 1499 : 1887 : RPCResult::Type::OBJ, "", "",
# 1500 : 1887 : {
# 1501 : 1887 : {RPCResult::Type::STR, "psbt", "The base64-encoded partially signed transaction"},
# 1502 : 1887 : {RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},
# 1503 : 1887 : }
# 1504 : 1887 : },
# 1505 : 1887 : RPCExamples{
# 1506 : 1887 : HelpExampleCli("walletprocesspsbt", "\"psbt\"")
# 1507 : 1887 : },
# 1508 : 1887 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 1509 : 1887 : {
# 1510 : 303 : const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
# 1511 [ - + ]: 303 : if (!pwallet) return NullUniValue;
# 1512 : :
# 1513 : 303 : const CWallet& wallet{*pwallet};
# 1514 : : // Make sure the results are valid at least up to the most recent block
# 1515 : : // the user could have gotten from another RPC command prior to now
# 1516 : 303 : wallet.BlockUntilSyncedToCurrentChain();
# 1517 : :
# 1518 : 303 : RPCTypeCheck(request.params, {UniValue::VSTR});
# 1519 : :
# 1520 : : // Unserialize the transaction
# 1521 : 303 : PartiallySignedTransaction psbtx;
# 1522 : 303 : std::string error;
# 1523 [ + + ]: 303 : if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) {
# 1524 : 2 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed %s", error));
# 1525 : 2 : }
# 1526 : :
# 1527 : : // Get the sighash type
# 1528 : 301 : int nHashType = ParseSighashString(request.params[2]);
# 1529 : :
# 1530 : : // Fill transaction with our data and also sign
# 1531 [ + + ]: 301 : bool sign = request.params[1].isNull() ? true : request.params[1].get_bool();
# 1532 [ + + ]: 301 : bool bip32derivs = request.params[3].isNull() ? true : request.params[3].get_bool();
# 1533 [ + + ]: 301 : bool finalize = request.params[4].isNull() ? true : request.params[4].get_bool();
# 1534 : 301 : bool complete = true;
# 1535 : :
# 1536 [ + + ]: 301 : if (sign) EnsureWalletIsUnlocked(*pwallet);
# 1537 : :
# 1538 : 301 : const TransactionError err{wallet.FillPSBT(psbtx, complete, nHashType, sign, bip32derivs, nullptr, finalize)};
# 1539 [ + + ]: 301 : if (err != TransactionError::OK) {
# 1540 : 2 : throw JSONRPCTransactionError(err);
# 1541 : 2 : }
# 1542 : :
# 1543 : 299 : UniValue result(UniValue::VOBJ);
# 1544 : 299 : CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
# 1545 : 299 : ssTx << psbtx;
# 1546 : 299 : result.pushKV("psbt", EncodeBase64(ssTx.str()));
# 1547 : 299 : result.pushKV("complete", complete);
# 1548 : :
# 1549 : 299 : return result;
# 1550 : 301 : },
# 1551 : 1887 : };
# 1552 : 1887 : }
# 1553 : :
# 1554 : : RPCHelpMan walletcreatefundedpsbt()
# 1555 : 1876 : {
# 1556 : 1876 : return RPCHelpMan{"walletcreatefundedpsbt",
# 1557 : 1876 : "\nCreates and funds a transaction in the Partially Signed Transaction format.\n"
# 1558 : 1876 : "Implements the Creator and Updater roles.\n"
# 1559 : 1876 : "All existing inputs must either have their previous output transaction be in the wallet\n"
# 1560 : 1876 : "or be in the UTXO set. Solving data must be provided for non-wallet inputs.\n",
# 1561 : 1876 : {
# 1562 : 1876 : {"inputs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "Leave empty to add inputs automatically. See add_inputs option.",
# 1563 : 1876 : {
# 1564 : 1876 : {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
# 1565 : 1876 : {
# 1566 : 1876 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
# 1567 : 1876 : {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
# 1568 : 1876 : {"sequence", RPCArg::Type::NUM, RPCArg::DefaultHint{"depends on the value of the 'locktime' and 'options.replaceable' arguments"}, "The sequence number"},
# 1569 : 1876 : {"weight", RPCArg::Type::NUM, RPCArg::DefaultHint{"Calculated from wallet and solving data"}, "The maximum weight for this input, "
# 1570 : 1876 : "including the weight of the outpoint and sequence number. "
# 1571 : 1876 : "Note that signature sizes are not guaranteed to be consistent, "
# 1572 : 1876 : "so the maximum DER signatures size of 73 bytes should be used when considering ECDSA signatures."
# 1573 : 1876 : "Remember to convert serialized sizes to weight units when necessary."},
# 1574 : 1876 : },
# 1575 : 1876 : },
# 1576 : 1876 : },
# 1577 : 1876 : },
# 1578 : 1876 : {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The outputs (key-value pairs), where none of the keys are duplicated.\n"
# 1579 : 1876 : "That is, each address can only appear once and there can only be one 'data' object.\n"
# 1580 : 1876 : "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n"
# 1581 : 1876 : "accepted as second parameter.",
# 1582 : 1876 : {
# 1583 : 1876 : {"", RPCArg::Type::OBJ_USER_KEYS, RPCArg::Optional::OMITTED, "",
# 1584 : 1876 : {
# 1585 : 1876 : {"address", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "A key-value pair. The key (string) is the bitcoin address, the value (float or string) is the amount in " + CURRENCY_UNIT + ""},
# 1586 : 1876 : },
# 1587 : 1876 : },
# 1588 : 1876 : {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
# 1589 : 1876 : {
# 1590 : 1876 : {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data"},
# 1591 : 1876 : },
# 1592 : 1876 : },
# 1593 : 1876 : },
# 1594 : 1876 : },
# 1595 : 1876 : {"locktime", RPCArg::Type::NUM, RPCArg::Default{0}, "Raw locktime. Non-0 value also locktime-activates inputs"},
# 1596 : 1876 : {"options", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "",
# 1597 : 1876 : Cat<std::vector<RPCArg>>(
# 1598 : 1876 : {
# 1599 : 1876 : {"add_inputs", RPCArg::Type::BOOL, RPCArg::Default{false}, "If inputs are specified, automatically include more if they are not enough."},
# 1600 : 1876 : {"include_unsafe", RPCArg::Type::BOOL, RPCArg::Default{false}, "Include inputs that are not safe to spend (unconfirmed transactions from outside keys and unconfirmed replacement transactions).\n"
# 1601 : 1876 : "Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
# 1602 : 1876 : "If that happens, you will need to fund the transaction with different inputs and republish it."},
# 1603 : 1876 : {"changeAddress", RPCArg::Type::STR, RPCArg::DefaultHint{"automatic"}, "The bitcoin address to receive the change"},
# 1604 : 1876 : {"changePosition", RPCArg::Type::NUM, RPCArg::DefaultHint{"random"}, "The index of the change output"},
# 1605 : 1876 : {"change_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -changetype"}, "The output type to use. Only valid if changeAddress is not specified. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
# 1606 : 1876 : {"includeWatching", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also select inputs which are watch only"},
# 1607 : 1876 : {"lockUnspents", RPCArg::Type::BOOL, RPCArg::Default{false}, "Lock selected unspent outputs"},
# 1608 : 1876 : {"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
# 1609 : 1876 : {"feeRate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_UNIT + "/kvB."},
# 1610 : 1876 : {"subtractFeeFromOutputs", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "The outputs to subtract the fee from.\n"
# 1611 : 1876 : "The fee will be equally deducted from the amount of each specified output.\n"
# 1612 : 1876 : "Those recipients will receive less bitcoins than you enter in their corresponding amount field.\n"
# 1613 : 1876 : "If no outputs are specified here, the sender pays the fee.",
# 1614 : 1876 : {
# 1615 : 1876 : {"vout_index", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The zero-based output index, before a change output is added."},
# 1616 : 1876 : },
# 1617 : 1876 : },
# 1618 : 1876 : },
# 1619 : 1876 : FundTxDoc()),
# 1620 : 1876 : "options"},
# 1621 : 1876 : {"bip32derivs", RPCArg::Type::BOOL, RPCArg::Default{true}, "Include BIP 32 derivation paths for public keys if we know them"},
# 1622 : 1876 : },
# 1623 : 1876 : RPCResult{
# 1624 : 1876 : RPCResult::Type::OBJ, "", "",
# 1625 : 1876 : {
# 1626 : 1876 : {RPCResult::Type::STR, "psbt", "The resulting raw transaction (base64-encoded string)"},
# 1627 : 1876 : {RPCResult::Type::STR_AMOUNT, "fee", "Fee in " + CURRENCY_UNIT + " the resulting transaction pays"},
# 1628 : 1876 : {RPCResult::Type::NUM, "changepos", "The position of the added change output, or -1"},
# 1629 : 1876 : }
# 1630 : 1876 : },
# 1631 : 1876 : RPCExamples{
# 1632 : 1876 : "\nCreate a transaction with no inputs\n"
# 1633 : 1876 : + HelpExampleCli("walletcreatefundedpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
# 1634 : 1876 : },
# 1635 : 1876 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 1636 : 1876 : {
# 1637 : 292 : std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
# 1638 [ - + ]: 292 : if (!pwallet) return NullUniValue;
# 1639 : :
# 1640 : 292 : CWallet& wallet{*pwallet};
# 1641 : : // Make sure the results are valid at least up to the most recent block
# 1642 : : // the user could have gotten from another RPC command prior to now
# 1643 : 292 : wallet.BlockUntilSyncedToCurrentChain();
# 1644 : :
# 1645 : 292 : RPCTypeCheck(request.params, {
# 1646 : 292 : UniValue::VARR,
# 1647 : 292 : UniValueType(), // ARR or OBJ, checked later
# 1648 : 292 : UniValue::VNUM,
# 1649 : 292 : UniValue::VOBJ,
# 1650 : 292 : UniValue::VBOOL
# 1651 : 292 : }, true
# 1652 : 292 : );
# 1653 : :
# 1654 : 292 : UniValue options = request.params[3];
# 1655 : :
# 1656 : 292 : CAmount fee;
# 1657 : 292 : int change_position;
# 1658 : 292 : bool rbf{wallet.m_signal_rbf};
# 1659 : 292 : const UniValue &replaceable_arg = options["replaceable"];
# 1660 [ + + ]: 292 : if (!replaceable_arg.isNull()) {
# 1661 : 4 : RPCTypeCheckArgument(replaceable_arg, UniValue::VBOOL);
# 1662 : 4 : rbf = replaceable_arg.isTrue();
# 1663 : 4 : }
# 1664 : 292 : CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf);
# 1665 : 292 : CCoinControl coin_control;
# 1666 : : // Automatically select coins, unless at least one is manually selected. Can
# 1667 : : // be overridden by options.add_inputs.
# 1668 : 292 : coin_control.m_add_inputs = rawTx.vin.size() == 0;
# 1669 : 292 : SetOptionsInputWeights(request.params[0], options);
# 1670 : 292 : FundTransaction(wallet, rawTx, fee, change_position, options, coin_control, /*override_min_fee=*/true);
# 1671 : :
# 1672 : : // Make a blank psbt
# 1673 : 292 : PartiallySignedTransaction psbtx(rawTx);
# 1674 : :
# 1675 : : // Fill transaction with out data but don't sign
# 1676 [ + + ]: 292 : bool bip32derivs = request.params[4].isNull() ? true : request.params[4].get_bool();
# 1677 : 292 : bool complete = true;
# 1678 : 292 : const TransactionError err{wallet.FillPSBT(psbtx, complete, 1, false, bip32derivs)};
# 1679 [ - + ]: 292 : if (err != TransactionError::OK) {
# 1680 : 0 : throw JSONRPCTransactionError(err);
# 1681 : 0 : }
# 1682 : :
# 1683 : : // Serialize the PSBT
# 1684 : 292 : CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
# 1685 : 292 : ssTx << psbtx;
# 1686 : :
# 1687 : 292 : UniValue result(UniValue::VOBJ);
# 1688 : 292 : result.pushKV("psbt", EncodeBase64(ssTx.str()));
# 1689 : 292 : result.pushKV("fee", ValueFromAmount(fee));
# 1690 : 292 : result.pushKV("changepos", change_position);
# 1691 : 292 : return result;
# 1692 : 292 : },
# 1693 : 1876 : };
# 1694 : 1876 : }
# 1695 : : } // namespace wallet
|