LCOV - code coverage report
Current view: top level - src/wallet/rpc - spend.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 36.6 % 1130 414
Test Date: 2026-11-07 06:08:25 Functions: 66.7 % 33 22
Branches: 24.5 % 4727 1160

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

Generated by: LCOV version 2.0-1