Bitcoin Core  22.99.0
P2P Digital Currency
spend.cpp
Go to the documentation of this file.
1 // Copyright (c) 2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <consensus/amount.h>
6 #include <consensus/validation.h>
7 #include <interfaces/chain.h>
8 #include <policy/policy.h>
10 #include <util/check.h>
11 #include <util/fees.h>
12 #include <util/moneystr.h>
13 #include <util/rbf.h>
14 #include <util/translation.h>
15 #include <wallet/coincontrol.h>
16 #include <wallet/fees.h>
17 #include <wallet/receive.h>
18 #include <wallet/spend.h>
19 #include <wallet/transaction.h>
20 #include <wallet/wallet.h>
21 
23 
24 namespace wallet {
25 static constexpr size_t OUTPUT_GROUP_MAX_ENTRIES{100};
26 
27 int GetTxSpendSize(const CWallet& wallet, const CWalletTx& wtx, unsigned int out, bool use_max_sig)
28 {
29  return CalculateMaximumSignedInputSize(wtx.tx->vout[out], &wallet, use_max_sig);
30 }
31 
32 std::string COutput::ToString() const
33 {
34  return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth, FormatMoney(tx->tx->vout[i].nValue));
35 }
36 
37 int CalculateMaximumSignedInputSize(const CTxOut& txout, const SigningProvider* provider, bool use_max_sig)
38 {
40  txn.vin.push_back(CTxIn(COutPoint()));
41  if (!provider || !DummySignInput(*provider, txn.vin[0], txout, use_max_sig)) {
42  return -1;
43  }
44  return GetVirtualTransactionInputSize(txn.vin[0]);
45 }
46 
47 int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* wallet, bool use_max_sig)
48 {
49  const std::unique_ptr<SigningProvider> provider = wallet->GetSolvingProvider(txout.scriptPubKey);
50  return CalculateMaximumSignedInputSize(txout, provider.get(), use_max_sig);
51 }
52 
53 // txouts needs to be in the order of tx.vin
54 TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, const CCoinControl* coin_control)
55 {
56  CMutableTransaction txNew(tx);
57  if (!wallet->DummySignTx(txNew, txouts, coin_control)) {
58  return TxSize{-1, -1};
59  }
60  CTransaction ctx(txNew);
61  int64_t vsize = GetVirtualTransactionSize(ctx);
62  int64_t weight = GetTransactionWeight(ctx);
63  return TxSize{vsize, weight};
64 }
65 
67 {
68  std::vector<CTxOut> txouts;
69  // Look up the inputs. The inputs are either in the wallet, or in coin_control.
70  for (const CTxIn& input : tx.vin) {
71  const auto mi = wallet->mapWallet.find(input.prevout.hash);
72  // Can not estimate size without knowing the input details
73  if (mi != wallet->mapWallet.end()) {
74  assert(input.prevout.n < mi->second.tx->vout.size());
75  txouts.emplace_back(mi->second.tx->vout.at(input.prevout.n));
76  } else if (coin_control) {
77  CTxOut txout;
78  if (!coin_control->GetExternalOutput(input.prevout, txout)) {
79  return TxSize{-1, -1};
80  }
81  txouts.emplace_back(txout);
82  } else {
83  return TxSize{-1, -1};
84  }
85  }
86  return CalculateMaximumSignedTxSize(tx, wallet, txouts, coin_control);
87 }
88 
89 void AvailableCoins(const CWallet& wallet, std::vector<COutput>& vCoins, const CCoinControl* coinControl, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount& nMinimumSumAmount, const uint64_t nMaximumCount)
90 {
91  AssertLockHeld(wallet.cs_wallet);
92 
93  vCoins.clear();
94  CAmount nTotal = 0;
95  // Either the WALLET_FLAG_AVOID_REUSE flag is not set (in which case we always allow), or we default to avoiding, and only in the case where
96  // a coin control object is provided, and has the avoid address reuse flag set to false, do we allow already used addresses
97  bool allow_used_addresses = !wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE) || (coinControl && !coinControl->m_avoid_address_reuse);
98  const int min_depth = {coinControl ? coinControl->m_min_depth : DEFAULT_MIN_DEPTH};
99  const int max_depth = {coinControl ? coinControl->m_max_depth : DEFAULT_MAX_DEPTH};
100  const bool only_safe = {coinControl ? !coinControl->m_include_unsafe_inputs : true};
101 
102  std::set<uint256> trusted_parents;
103  for (const auto& entry : wallet.mapWallet)
104  {
105  const uint256& wtxid = entry.first;
106  const CWalletTx& wtx = entry.second;
107 
108  if (wallet.IsTxImmatureCoinBase(wtx))
109  continue;
110 
111  int nDepth = wallet.GetTxDepthInMainChain(wtx);
112  if (nDepth < 0)
113  continue;
114 
115  // We should not consider coins which aren't at least in our mempool
116  // It's possible for these to be conflicted via ancestors which we may never be able to detect
117  if (nDepth == 0 && !wtx.InMempool())
118  continue;
119 
120  bool safeTx = CachedTxIsTrusted(wallet, wtx, trusted_parents);
121 
122  // We should not consider coins from transactions that are replacing
123  // other transactions.
124  //
125  // Example: There is a transaction A which is replaced by bumpfee
126  // transaction B. In this case, we want to prevent creation of
127  // a transaction B' which spends an output of B.
128  //
129  // Reason: If transaction A were initially confirmed, transactions B
130  // and B' would no longer be valid, so the user would have to create
131  // a new transaction C to replace B'. However, in the case of a
132  // one-block reorg, transactions B' and C might BOTH be accepted,
133  // when the user only wanted one of them. Specifically, there could
134  // be a 1-block reorg away from the chain where transactions A and C
135  // were accepted to another chain where B, B', and C were all
136  // accepted.
137  if (nDepth == 0 && wtx.mapValue.count("replaces_txid")) {
138  safeTx = false;
139  }
140 
141  // Similarly, we should not consider coins from transactions that
142  // have been replaced. In the example above, we would want to prevent
143  // creation of a transaction A' spending an output of A, because if
144  // transaction B were initially confirmed, conflicting with A and
145  // A', we wouldn't want to the user to create a transaction D
146  // intending to replace A', but potentially resulting in a scenario
147  // where A, A', and D could all be accepted (instead of just B and
148  // D, or just A and A' like the user would want).
149  if (nDepth == 0 && wtx.mapValue.count("replaced_by_txid")) {
150  safeTx = false;
151  }
152 
153  if (only_safe && !safeTx) {
154  continue;
155  }
156 
157  if (nDepth < min_depth || nDepth > max_depth) {
158  continue;
159  }
160 
161  for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) {
162  // Only consider selected coins if add_inputs is false
163  if (coinControl && !coinControl->m_add_inputs && !coinControl->IsSelected(COutPoint(entry.first, i))) {
164  continue;
165  }
166 
167  if (wtx.tx->vout[i].nValue < nMinimumAmount || wtx.tx->vout[i].nValue > nMaximumAmount)
168  continue;
169 
170  if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(COutPoint(entry.first, i)))
171  continue;
172 
173  if (wallet.IsLockedCoin(entry.first, i))
174  continue;
175 
176  if (wallet.IsSpent(wtxid, i))
177  continue;
178 
179  isminetype mine = wallet.IsMine(wtx.tx->vout[i]);
180 
181  if (mine == ISMINE_NO) {
182  continue;
183  }
184 
185  if (!allow_used_addresses && wallet.IsSpentKey(wtxid, i)) {
186  continue;
187  }
188 
189  std::unique_ptr<SigningProvider> provider = wallet.GetSolvingProvider(wtx.tx->vout[i].scriptPubKey);
190 
191  bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false;
192  bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
193 
194  vCoins.push_back(COutput(wallet, wtx, i, nDepth, spendable, solvable, safeTx, (coinControl && coinControl->fAllowWatchOnly)));
195 
196  // Checks the sum amount of all UTXO's.
197  if (nMinimumSumAmount != MAX_MONEY) {
198  nTotal += wtx.tx->vout[i].nValue;
199 
200  if (nTotal >= nMinimumSumAmount) {
201  return;
202  }
203  }
204 
205  // Checks the maximum number of UTXO's.
206  if (nMaximumCount > 0 && vCoins.size() >= nMaximumCount) {
207  return;
208  }
209  }
210  }
211 }
212 
214 {
215  LOCK(wallet.cs_wallet);
216 
217  CAmount balance = 0;
218  std::vector<COutput> vCoins;
219  AvailableCoins(wallet, vCoins, coinControl);
220  for (const COutput& out : vCoins) {
221  if (out.fSpendable) {
222  balance += out.tx->tx->vout[out.i].nValue;
223  }
224  }
225  return balance;
226 }
227 
228 const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output)
229 {
230  AssertLockHeld(wallet.cs_wallet);
231  const CTransaction* ptx = &tx;
232  int n = output;
233  while (OutputIsChange(wallet, ptx->vout[n]) && ptx->vin.size() > 0) {
234  const COutPoint& prevout = ptx->vin[0].prevout;
235  auto it = wallet.mapWallet.find(prevout.hash);
236  if (it == wallet.mapWallet.end() || it->second.tx->vout.size() <= prevout.n ||
237  !wallet.IsMine(it->second.tx->vout[prevout.n])) {
238  break;
239  }
240  ptx = it->second.tx.get();
241  n = prevout.n;
242  }
243  return ptx->vout[n];
244 }
245 
246 std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
247 {
248  AssertLockHeld(wallet.cs_wallet);
249 
250  std::map<CTxDestination, std::vector<COutput>> result;
251  std::vector<COutput> availableCoins;
252 
253  AvailableCoins(wallet, availableCoins);
254 
255  for (const COutput& coin : availableCoins) {
256  CTxDestination address;
257  if ((coin.fSpendable || (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.fSolvable)) &&
258  ExtractDestination(FindNonChangeParentOutput(wallet, *coin.tx->tx, coin.i).scriptPubKey, address)) {
259  result[address].emplace_back(std::move(coin));
260  }
261  }
262 
263  std::vector<COutPoint> lockedCoins;
264  wallet.ListLockedCoins(lockedCoins);
265  // Include watch-only for LegacyScriptPubKeyMan wallets without private keys
266  const bool include_watch_only = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
267  const isminetype is_mine_filter = include_watch_only ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;
268  for (const COutPoint& output : lockedCoins) {
269  auto it = wallet.mapWallet.find(output.hash);
270  if (it != wallet.mapWallet.end()) {
271  int depth = wallet.GetTxDepthInMainChain(it->second);
272  if (depth >= 0 && output.n < it->second.tx->vout.size() &&
273  wallet.IsMine(it->second.tx->vout[output.n]) == is_mine_filter
274  ) {
275  CTxDestination address;
276  if (ExtractDestination(FindNonChangeParentOutput(wallet, *it->second.tx, output.n).scriptPubKey, address)) {
277  result[address].emplace_back(
278  wallet, it->second, output.n, depth, true /* spendable */, true /* solvable */, false /* safe */);
279  }
280  }
281  }
282  }
283 
284  return result;
285 }
286 
287 std::vector<OutputGroup> GroupOutputs(const CWallet& wallet, const std::vector<COutput>& outputs, const CoinSelectionParams& coin_sel_params, const CoinEligibilityFilter& filter, bool positive_only)
288 {
289  std::vector<OutputGroup> groups_out;
290 
291  if (!coin_sel_params.m_avoid_partial_spends) {
292  // Allowing partial spends means no grouping. Each COutput gets its own OutputGroup.
293  for (const COutput& output : outputs) {
294  // Skip outputs we cannot spend
295  if (!output.fSpendable) continue;
296 
297  size_t ancestors, descendants;
298  wallet.chain().getTransactionAncestry(output.tx->GetHash(), ancestors, descendants);
299  CInputCoin input_coin = output.GetInputCoin();
300 
301  // Make an OutputGroup containing just this output
302  OutputGroup group{coin_sel_params};
303  group.Insert(input_coin, output.nDepth, CachedTxIsFromMe(wallet, *output.tx, ISMINE_ALL), ancestors, descendants, positive_only);
304 
305  // Check the OutputGroup's eligibility. Only add the eligible ones.
306  if (positive_only && group.GetSelectionAmount() <= 0) continue;
307  if (group.m_outputs.size() > 0 && group.EligibleForSpending(filter)) groups_out.push_back(group);
308  }
309  return groups_out;
310  }
311 
312  // We want to combine COutputs that have the same scriptPubKey into single OutputGroups
313  // except when there are more than OUTPUT_GROUP_MAX_ENTRIES COutputs grouped in an OutputGroup.
314  // To do this, we maintain a map where the key is the scriptPubKey and the value is a vector of OutputGroups.
315  // For each COutput, we check if the scriptPubKey is in the map, and if it is, the COutput's CInputCoin is added
316  // to the last OutputGroup in the vector for the scriptPubKey. When the last OutputGroup has
317  // OUTPUT_GROUP_MAX_ENTRIES CInputCoins, a new OutputGroup is added to the end of the vector.
318  std::map<CScript, std::vector<OutputGroup>> spk_to_groups_map;
319  for (const auto& output : outputs) {
320  // Skip outputs we cannot spend
321  if (!output.fSpendable) continue;
322 
323  size_t ancestors, descendants;
324  wallet.chain().getTransactionAncestry(output.tx->GetHash(), ancestors, descendants);
325  CInputCoin input_coin = output.GetInputCoin();
326  CScript spk = input_coin.txout.scriptPubKey;
327 
328  std::vector<OutputGroup>& groups = spk_to_groups_map[spk];
329 
330  if (groups.size() == 0) {
331  // No OutputGroups for this scriptPubKey yet, add one
332  groups.emplace_back(coin_sel_params);
333  }
334 
335  // Get the last OutputGroup in the vector so that we can add the CInputCoin to it
336  // A pointer is used here so that group can be reassigned later if it is full.
337  OutputGroup* group = &groups.back();
338 
339  // Check if this OutputGroup is full. We limit to OUTPUT_GROUP_MAX_ENTRIES when using -avoidpartialspends
340  // to avoid surprising users with very high fees.
341  if (group->m_outputs.size() >= OUTPUT_GROUP_MAX_ENTRIES) {
342  // The last output group is full, add a new group to the vector and use that group for the insertion
343  groups.emplace_back(coin_sel_params);
344  group = &groups.back();
345  }
346 
347  // Add the input_coin to group
348  group->Insert(input_coin, output.nDepth, CachedTxIsFromMe(wallet, *output.tx, ISMINE_ALL), ancestors, descendants, positive_only);
349  }
350 
351  // Now we go through the entire map and pull out the OutputGroups
352  for (const auto& spk_and_groups_pair: spk_to_groups_map) {
353  const std::vector<OutputGroup>& groups_per_spk= spk_and_groups_pair.second;
354 
355  // Go through the vector backwards. This allows for the first item we deal with being the partial group.
356  for (auto group_it = groups_per_spk.rbegin(); group_it != groups_per_spk.rend(); group_it++) {
357  const OutputGroup& group = *group_it;
358 
359  // Don't include partial groups if there are full groups too and we don't want partial groups
360  if (group_it == groups_per_spk.rbegin() && groups_per_spk.size() > 1 && !filter.m_include_partial_groups) {
361  continue;
362  }
363 
364  // Check the OutputGroup's eligibility. Only add the eligible ones.
365  if (positive_only && group.GetSelectionAmount() <= 0) continue;
366  if (group.m_outputs.size() > 0 && group.EligibleForSpending(filter)) groups_out.push_back(group);
367  }
368  }
369 
370  return groups_out;
371 }
372 
373 std::optional<SelectionResult> AttemptSelection(const CWallet& wallet, const CAmount& nTargetValue, const CoinEligibilityFilter& eligibility_filter, std::vector<COutput> coins,
374  const CoinSelectionParams& coin_selection_params)
375 {
376  // Vector of results. We will choose the best one based on waste.
377  std::vector<SelectionResult> results;
378 
379  // Note that unlike KnapsackSolver, we do not include the fee for creating a change output as BnB will not create a change output.
380  std::vector<OutputGroup> positive_groups = GroupOutputs(wallet, coins, coin_selection_params, eligibility_filter, true /* positive_only */);
381  if (auto bnb_result{SelectCoinsBnB(positive_groups, nTargetValue, coin_selection_params.m_cost_of_change)}) {
382  bnb_result->ComputeAndSetWaste(CAmount(0));
383  results.push_back(*bnb_result);
384  }
385 
386  // The knapsack solver has some legacy behavior where it will spend dust outputs. We retain this behavior, so don't filter for positive only here.
387  std::vector<OutputGroup> all_groups = GroupOutputs(wallet, coins, coin_selection_params, eligibility_filter, false /* positive_only */);
388  // While nTargetValue includes the transaction fees for non-input things, it does not include the fee for creating a change output.
389  // So we need to include that for KnapsackSolver as well, as we are expecting to create a change output.
390  if (auto knapsack_result{KnapsackSolver(all_groups, nTargetValue + coin_selection_params.m_change_fee)}) {
391  knapsack_result->ComputeAndSetWaste(coin_selection_params.m_cost_of_change);
392  results.push_back(*knapsack_result);
393  }
394 
395  // We include the minimum final change for SRD as we do want to avoid making really small change.
396  // KnapsackSolver does not need this because it includes MIN_CHANGE internally.
397  const CAmount srd_target = nTargetValue + coin_selection_params.m_change_fee + MIN_FINAL_CHANGE;
398  if (auto srd_result{SelectCoinsSRD(positive_groups, srd_target)}) {
399  srd_result->ComputeAndSetWaste(coin_selection_params.m_cost_of_change);
400  results.push_back(*srd_result);
401  }
402 
403  if (results.size() == 0) {
404  // No solution found
405  return std::nullopt;
406  }
407 
408  // Choose the result with the least waste
409  // If the waste is the same, choose the one which spends more inputs.
410  auto& best_result = *std::min_element(results.begin(), results.end());
411  return best_result;
412 }
413 
414 std::optional<SelectionResult> SelectCoins(const CWallet& wallet, const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, const CCoinControl& coin_control, const CoinSelectionParams& coin_selection_params)
415 {
416  std::vector<COutput> vCoins(vAvailableCoins);
417  CAmount value_to_select = nTargetValue;
418 
419  OutputGroup preset_inputs(coin_selection_params);
420 
421  // coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
422  if (coin_control.HasSelected() && !coin_control.fAllowOtherInputs)
423  {
424  for (const COutput& out : vCoins) {
425  if (!out.fSpendable) continue;
426  /* Set depth, from_me, ancestors, and descendants to 0 or false as these don't matter for preset inputs as no actual selection is being done.
427  * positive_only is set to false because we want to include all preset inputs, even if they are dust.
428  */
429  preset_inputs.Insert(out.GetInputCoin(), 0, false, 0, 0, false);
430  }
431  SelectionResult result(nTargetValue);
432  result.AddInput(preset_inputs);
433  if (result.GetSelectedValue() < nTargetValue) return std::nullopt;
434  return result;
435  }
436 
437  // calculate value from preset inputs and store them
438  std::set<CInputCoin> setPresetCoins;
439 
440  std::vector<COutPoint> vPresetInputs;
441  coin_control.ListSelected(vPresetInputs);
442  for (const COutPoint& outpoint : vPresetInputs) {
443  int input_bytes = -1;
444  CTxOut txout;
445  std::map<uint256, CWalletTx>::const_iterator it = wallet.mapWallet.find(outpoint.hash);
446  if (it != wallet.mapWallet.end()) {
447  const CWalletTx& wtx = it->second;
448  // Clearly invalid input, fail
449  if (wtx.tx->vout.size() <= outpoint.n) {
450  return std::nullopt;
451  }
452  input_bytes = GetTxSpendSize(wallet, wtx, outpoint.n, false);
453  txout = wtx.tx->vout.at(outpoint.n);
454  } else {
455  // The input is external. We did not find the tx in mapWallet.
456  if (!coin_control.GetExternalOutput(outpoint, txout)) {
457  return std::nullopt;
458  }
459  input_bytes = CalculateMaximumSignedInputSize(txout, &coin_control.m_external_provider, /* use_max_sig */ true);
460  }
461  // If available, override calculated size with coin control specified size
462  if (coin_control.HasInputWeight(outpoint)) {
463  input_bytes = GetVirtualTransactionSize(coin_control.GetInputWeight(outpoint), 0, 0);
464  }
465 
466  CInputCoin coin(outpoint, txout, input_bytes);
467  if (coin.m_input_bytes == -1) {
468  return std::nullopt; // Not solvable, can't estimate size for fee
469  }
470  coin.effective_value = coin.txout.nValue - coin_selection_params.m_effective_feerate.GetFee(coin.m_input_bytes);
471  if (coin_selection_params.m_subtract_fee_outputs) {
472  value_to_select -= coin.txout.nValue;
473  } else {
474  value_to_select -= coin.effective_value;
475  }
476  setPresetCoins.insert(coin);
477  /* Set depth, from_me, ancestors, and descendants to 0 or false as don't matter for preset inputs as no actual selection is being done.
478  * positive_only is set to false because we want to include all preset inputs, even if they are dust.
479  */
480  preset_inputs.Insert(coin, 0, false, 0, 0, false);
481  }
482 
483  // remove preset inputs from vCoins so that Coin Selection doesn't pick them.
484  for (std::vector<COutput>::iterator it = vCoins.begin(); it != vCoins.end() && coin_control.HasSelected();)
485  {
486  if (setPresetCoins.count(it->GetInputCoin()))
487  it = vCoins.erase(it);
488  else
489  ++it;
490  }
491 
492  unsigned int limit_ancestor_count = 0;
493  unsigned int limit_descendant_count = 0;
494  wallet.chain().getPackageLimits(limit_ancestor_count, limit_descendant_count);
495  const size_t max_ancestors = (size_t)std::max<int64_t>(1, limit_ancestor_count);
496  const size_t max_descendants = (size_t)std::max<int64_t>(1, limit_descendant_count);
497  const bool fRejectLongChains = gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS);
498 
499  // form groups from remaining coins; note that preset coins will not
500  // automatically have their associated (same address) coins included
501  if (coin_control.m_avoid_partial_spends && vCoins.size() > OUTPUT_GROUP_MAX_ENTRIES) {
502  // Cases where we have 101+ outputs all pointing to the same destination may result in
503  // privacy leaks as they will potentially be deterministically sorted. We solve that by
504  // explicitly shuffling the outputs before processing
505  Shuffle(vCoins.begin(), vCoins.end(), FastRandomContext());
506  }
507 
508  // Coin Selection attempts to select inputs from a pool of eligible UTXOs to fund the
509  // transaction at a target feerate. If an attempt fails, more attempts may be made using a more
510  // permissive CoinEligibilityFilter.
511  std::optional<SelectionResult> res = [&] {
512  // Pre-selected inputs already cover the target amount.
513  if (value_to_select <= 0) return std::make_optional(SelectionResult(nTargetValue));
514 
515  // If possible, fund the transaction with confirmed UTXOs only. Prefer at least six
516  // confirmations on outputs received from other wallets and only spend confirmed change.
517  if (auto r1{AttemptSelection(wallet, value_to_select, CoinEligibilityFilter(1, 6, 0), vCoins, coin_selection_params)}) return r1;
518  if (auto r2{AttemptSelection(wallet, value_to_select, CoinEligibilityFilter(1, 1, 0), vCoins, coin_selection_params)}) return r2;
519 
520  // Fall back to using zero confirmation change (but with as few ancestors in the mempool as
521  // possible) if we cannot fund the transaction otherwise.
522  if (wallet.m_spend_zero_conf_change) {
523  if (auto r3{AttemptSelection(wallet, value_to_select, CoinEligibilityFilter(0, 1, 2), vCoins, coin_selection_params)}) return r3;
524  if (auto r4{AttemptSelection(wallet, value_to_select, CoinEligibilityFilter(0, 1, std::min((size_t)4, max_ancestors/3), std::min((size_t)4, max_descendants/3)),
525  vCoins, coin_selection_params)}) {
526  return r4;
527  }
528  if (auto r5{AttemptSelection(wallet, value_to_select, CoinEligibilityFilter(0, 1, max_ancestors/2, max_descendants/2),
529  vCoins, coin_selection_params)}) {
530  return r5;
531  }
532  // If partial groups are allowed, relax the requirement of spending OutputGroups (groups
533  // of UTXOs sent to the same address, which are obviously controlled by a single wallet)
534  // in their entirety.
535  if (auto r6{AttemptSelection(wallet, value_to_select, CoinEligibilityFilter(0, 1, max_ancestors-1, max_descendants-1, true /* include_partial_groups */),
536  vCoins, coin_selection_params)}) {
537  return r6;
538  }
539  // Try with unsafe inputs if they are allowed. This may spend unconfirmed outputs
540  // received from other wallets.
541  if (coin_control.m_include_unsafe_inputs) {
542  if (auto r7{AttemptSelection(wallet, value_to_select,
543  CoinEligibilityFilter(0 /* conf_mine */, 0 /* conf_theirs */, max_ancestors-1, max_descendants-1, true /* include_partial_groups */),
544  vCoins, coin_selection_params)}) {
545  return r7;
546  }
547  }
548  // Try with unlimited ancestors/descendants. The transaction will still need to meet
549  // mempool ancestor/descendant policy to be accepted to mempool and broadcasted, but
550  // OutputGroups use heuristics that may overestimate ancestor/descendant counts.
551  if (!fRejectLongChains) {
552  if (auto r8{AttemptSelection(wallet, value_to_select,
553  CoinEligibilityFilter(0, 1, std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::max(), true /* include_partial_groups */),
554  vCoins, coin_selection_params)}) {
555  return r8;
556  }
557  }
558  }
559  // Coin Selection failed.
560  return std::optional<SelectionResult>();
561  }();
562 
563  if (!res) return std::nullopt;
564 
565  // Add preset inputs to result
566  res->AddInput(preset_inputs);
567 
568  return res;
569 }
570 
571 static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256& block_hash)
572 {
573  if (chain.isInitialBlockDownload()) {
574  return false;
575  }
576  constexpr int64_t MAX_ANTI_FEE_SNIPING_TIP_AGE = 8 * 60 * 60; // in seconds
577  int64_t block_time;
578  CHECK_NONFATAL(chain.findBlock(block_hash, FoundBlock().time(block_time)));
579  if (block_time < (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
580  return false;
581  }
582  return true;
583 }
584 
589 static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uint256& block_hash, int block_height)
590 {
591  uint32_t locktime;
592  // Discourage fee sniping.
593  //
594  // For a large miner the value of the transactions in the best block and
595  // the mempool can exceed the cost of deliberately attempting to mine two
596  // blocks to orphan the current best block. By setting nLockTime such that
597  // only the next block can include the transaction, we discourage this
598  // practice as the height restricted and limited blocksize gives miners
599  // considering fee sniping fewer options for pulling off this attack.
600  //
601  // A simple way to think about this is from the wallet's point of view we
602  // always want the blockchain to move forward. By setting nLockTime this
603  // way we're basically making the statement that we only want this
604  // transaction to appear in the next block; we don't want to potentially
605  // encourage reorgs by allowing transactions to appear at lower heights
606  // than the next block in forks of the best chain.
607  //
608  // Of course, the subsidy is high enough, and transaction volume low
609  // enough, that fee sniping isn't a problem yet, but by implementing a fix
610  // now we ensure code won't be written that makes assumptions about
611  // nLockTime that preclude a fix later.
612  if (IsCurrentForAntiFeeSniping(chain, block_hash)) {
613  locktime = block_height;
614 
615  // Secondly occasionally randomly pick a nLockTime even further back, so
616  // that transactions that are delayed after signing for whatever reason,
617  // e.g. high-latency mix networks and some CoinJoin implementations, have
618  // better privacy.
619  if (GetRandInt(10) == 0)
620  locktime = std::max(0, (int)locktime - GetRandInt(100));
621  } else {
622  // If our chain is lagging behind, we can't discourage fee sniping nor help
623  // the privacy of high-latency transactions. To avoid leaking a potentially
624  // unique "nLockTime fingerprint", set nLockTime to a constant.
625  locktime = 0;
626  }
627  assert(locktime < LOCKTIME_THRESHOLD);
628  return locktime;
629 }
630 
632  CWallet& wallet,
633  const std::vector<CRecipient>& vecSend,
634  CTransactionRef& tx,
635  CAmount& nFeeRet,
636  int& nChangePosInOut,
638  const CCoinControl& coin_control,
639  FeeCalculation& fee_calc_out,
640  bool sign) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
641 {
642  AssertLockHeld(wallet.cs_wallet);
643 
644  CMutableTransaction txNew; // The resulting transaction that we make
645  txNew.nLockTime = GetLocktimeForNewTransaction(wallet.chain(), wallet.GetLastBlockHash(), wallet.GetLastBlockHeight());
646 
647  CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
648  coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends;
649 
650  // Set the long term feerate estimate to the wallet's consolidate feerate
651  coin_selection_params.m_long_term_feerate = wallet.m_consolidate_feerate;
652 
653  CAmount recipients_sum = 0;
654  const OutputType change_type = wallet.TransactionChangeType(coin_control.m_change_type ? *coin_control.m_change_type : wallet.m_default_change_type, vecSend);
655  ReserveDestination reservedest(&wallet, change_type);
656  unsigned int outputs_to_subtract_fee_from = 0; // The number of outputs which we are subtracting the fee from
657  for (const auto& recipient : vecSend) {
658  recipients_sum += recipient.nAmount;
659 
660  if (recipient.fSubtractFeeFromAmount) {
661  outputs_to_subtract_fee_from++;
662  coin_selection_params.m_subtract_fee_outputs = true;
663  }
664  }
665 
666  // Create change script that will be used if we need change
667  CScript scriptChange;
668 
669  // coin control: send change to custom address
670  if (!std::get_if<CNoDestination>(&coin_control.destChange)) {
671  scriptChange = GetScriptForDestination(coin_control.destChange);
672  } else { // no coin control: send change to newly generated address
673  // Note: We use a new key here to keep it from being obvious which side is the change.
674  // The drawback is that by not reusing a previous key, the change may be lost if a
675  // backup is restored, if the backup doesn't have the new private key for the change.
676  // If we reused the old key, it would be possible to add code to look for and
677  // rediscover unknown transactions that were written with keys of ours to recover
678  // post-backup change.
679 
680  // Reserve a new key pair from key pool. If it fails, provide a dummy
681  // destination in case we don't need change.
682  CTxDestination dest;
683  bilingual_str dest_err;
684  if (!reservedest.GetReservedDestination(dest, true, dest_err)) {
685  error = _("Transaction needs a change address, but we can't generate it.") + Untranslated(" ") + dest_err;
686  }
687  scriptChange = GetScriptForDestination(dest);
688  // A valid destination implies a change script (and
689  // vice-versa). An empty change script will abort later, if the
690  // change keypool ran out, but change is required.
691  CHECK_NONFATAL(IsValidDestination(dest) != scriptChange.empty());
692  }
693  CTxOut change_prototype_txout(0, scriptChange);
694  coin_selection_params.change_output_size = GetSerializeSize(change_prototype_txout);
695 
696  // Get size of spending the change output
697  int change_spend_size = CalculateMaximumSignedInputSize(change_prototype_txout, &wallet);
698  // If the wallet doesn't know how to sign change output, assume p2sh-p2wpkh
699  // as lower-bound to allow BnB to do it's thing
700  if (change_spend_size == -1) {
701  coin_selection_params.change_spend_size = DUMMY_NESTED_P2WPKH_INPUT_SIZE;
702  } else {
703  coin_selection_params.change_spend_size = (size_t)change_spend_size;
704  }
705 
706  // Set discard feerate
707  coin_selection_params.m_discard_feerate = GetDiscardRate(wallet);
708 
709  // Get the fee rate to use effective values in coin selection
710  FeeCalculation feeCalc;
711  coin_selection_params.m_effective_feerate = GetMinimumFeeRate(wallet, coin_control, &feeCalc);
712  // Do not, ever, assume that it's fine to change the fee rate if the user has explicitly
713  // provided one
714  if (coin_control.m_feerate && coin_selection_params.m_effective_feerate > *coin_control.m_feerate) {
715  error = strprintf(_("Fee rate (%s) is lower than the minimum fee rate setting (%s)"), coin_control.m_feerate->ToString(FeeEstimateMode::SAT_VB), coin_selection_params.m_effective_feerate.ToString(FeeEstimateMode::SAT_VB));
716  return false;
717  }
718  if (feeCalc.reason == FeeReason::FALLBACK && !wallet.m_allow_fallback_fee) {
719  // eventually allow a fallback fee
720  error = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.");
721  return false;
722  }
723 
724  // Calculate the cost of change
725  // Cost of change is the cost of creating the change output + cost of spending the change output in the future.
726  // For creating the change output now, we use the effective feerate.
727  // For spending the change output in the future, we use the discard feerate for now.
728  // So cost of change = (change output size * effective feerate) + (size of spending change output * discard feerate)
729  coin_selection_params.m_change_fee = coin_selection_params.m_effective_feerate.GetFee(coin_selection_params.change_output_size);
730  coin_selection_params.m_cost_of_change = coin_selection_params.m_discard_feerate.GetFee(coin_selection_params.change_spend_size) + coin_selection_params.m_change_fee;
731 
732  // vouts to the payees
733  if (!coin_selection_params.m_subtract_fee_outputs) {
734  coin_selection_params.tx_noinputs_size = 11; // Static vsize overhead + outputs vsize. 4 nVersion, 4 nLocktime, 1 input count, 1 output count, 1 witness overhead (dummy, flag, stack size)
735  }
736  for (const auto& recipient : vecSend)
737  {
738  CTxOut txout(recipient.nAmount, recipient.scriptPubKey);
739 
740  // Include the fee cost for outputs.
741  if (!coin_selection_params.m_subtract_fee_outputs) {
742  coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout, PROTOCOL_VERSION);
743  }
744 
745  if (IsDust(txout, wallet.chain().relayDustFee()))
746  {
747  error = _("Transaction amount too small");
748  return false;
749  }
750  txNew.vout.push_back(txout);
751  }
752 
753  // Include the fees for things that aren't inputs, excluding the change output
754  const CAmount not_input_fees = coin_selection_params.m_effective_feerate.GetFee(coin_selection_params.tx_noinputs_size);
755  CAmount selection_target = recipients_sum + not_input_fees;
756 
757  // Get available coins
758  std::vector<COutput> vAvailableCoins;
759  AvailableCoins(wallet, vAvailableCoins, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0);
760 
761  // Choose coins to use
762  std::optional<SelectionResult> result = SelectCoins(wallet, vAvailableCoins, /* nTargetValue */ selection_target, coin_control, coin_selection_params);
763  if (!result) {
764  error = _("Insufficient funds");
765  return false;
766  }
767 
768  // Always make a change output
769  // We will reduce the fee from this change output later, and remove the output if it is too small.
770  const CAmount change_and_fee = result->GetSelectedValue() - recipients_sum;
771  assert(change_and_fee >= 0);
772  CTxOut newTxOut(change_and_fee, scriptChange);
773 
774  if (nChangePosInOut == -1)
775  {
776  // Insert change txn at random position:
777  nChangePosInOut = GetRandInt(txNew.vout.size()+1);
778  }
779  else if ((unsigned int)nChangePosInOut > txNew.vout.size())
780  {
781  error = _("Change index out of range");
782  return false;
783  }
784 
785  assert(nChangePosInOut != -1);
786  auto change_position = txNew.vout.insert(txNew.vout.begin() + nChangePosInOut, newTxOut);
787 
788  // Shuffle selected coins and fill in final vin
789  std::vector<CInputCoin> selected_coins = result->GetShuffledInputVector();
790 
791  // Note how the sequence number is set to non-maxint so that
792  // the nLockTime set above actually works.
793  //
794  // BIP125 defines opt-in RBF as any nSequence < maxint-1, so
795  // we use the highest possible value in that range (maxint-2)
796  // to avoid conflicting with other possible uses of nSequence,
797  // and in the spirit of "smallest possible change from prior
798  // behavior."
799  const uint32_t nSequence{coin_control.m_signal_bip125_rbf.value_or(wallet.m_signal_rbf) ? MAX_BIP125_RBF_SEQUENCE : CTxIn::MAX_SEQUENCE_NONFINAL};
800  for (const auto& coin : selected_coins) {
801  txNew.vin.push_back(CTxIn(coin.outpoint, CScript(), nSequence));
802  }
803 
804  // Calculate the transaction fee
805  TxSize tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), &wallet, &coin_control);
806  int nBytes = tx_sizes.vsize;
807  if (nBytes == -1) {
808  error = _("Missing solving data for estimating transaction size");
809  return false;
810  }
811  nFeeRet = coin_selection_params.m_effective_feerate.GetFee(nBytes);
812 
813  // Subtract fee from the change output if not subtracting it from recipient outputs
814  CAmount fee_needed = nFeeRet;
815  if (!coin_selection_params.m_subtract_fee_outputs) {
816  change_position->nValue -= fee_needed;
817  }
818 
819  // We want to drop the change to fees if:
820  // 1. The change output would be dust
821  // 2. The change is within the (almost) exact match window, i.e. it is less than or equal to the cost of the change output (cost_of_change)
822  CAmount change_amount = change_position->nValue;
823  if (IsDust(*change_position, coin_selection_params.m_discard_feerate) || change_amount <= coin_selection_params.m_cost_of_change)
824  {
825  nChangePosInOut = -1;
826  change_amount = 0;
827  txNew.vout.erase(change_position);
828 
829  // Because we have dropped this change, the tx size and required fee will be different, so let's recalculate those
830  tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), &wallet, &coin_control);
831  nBytes = tx_sizes.vsize;
832  fee_needed = coin_selection_params.m_effective_feerate.GetFee(nBytes);
833  }
834 
835  // The only time that fee_needed should be less than the amount available for fees (in change_and_fee - change_amount) is when
836  // we are subtracting the fee from the outputs. If this occurs at any other time, it is a bug.
837  assert(coin_selection_params.m_subtract_fee_outputs || fee_needed <= change_and_fee - change_amount);
838 
839  // Update nFeeRet in case fee_needed changed due to dropping the change output
840  if (fee_needed <= change_and_fee - change_amount) {
841  nFeeRet = change_and_fee - change_amount;
842  }
843 
844  // Reduce output values for subtractFeeFromAmount
845  if (coin_selection_params.m_subtract_fee_outputs) {
846  CAmount to_reduce = fee_needed + change_amount - change_and_fee;
847  int i = 0;
848  bool fFirst = true;
849  for (const auto& recipient : vecSend)
850  {
851  if (i == nChangePosInOut) {
852  ++i;
853  }
854  CTxOut& txout = txNew.vout[i];
855 
856  if (recipient.fSubtractFeeFromAmount)
857  {
858  txout.nValue -= to_reduce / outputs_to_subtract_fee_from; // Subtract fee equally from each selected recipient
859 
860  if (fFirst) // first receiver pays the remainder not divisible by output count
861  {
862  fFirst = false;
863  txout.nValue -= to_reduce % outputs_to_subtract_fee_from;
864  }
865 
866  // Error if this output is reduced to be below dust
867  if (IsDust(txout, wallet.chain().relayDustFee())) {
868  if (txout.nValue < 0) {
869  error = _("The transaction amount is too small to pay the fee");
870  } else {
871  error = _("The transaction amount is too small to send after the fee has been deducted");
872  }
873  return false;
874  }
875  }
876  ++i;
877  }
878  nFeeRet = fee_needed;
879  }
880 
881  // Give up if change keypool ran out and change is required
882  if (scriptChange.empty() && nChangePosInOut != -1) {
883  return false;
884  }
885 
886  if (sign && !wallet.SignTransaction(txNew)) {
887  error = _("Signing transaction failed");
888  return false;
889  }
890 
891  // Return the constructed transaction data.
892  tx = MakeTransactionRef(std::move(txNew));
893 
894  // Limit size
895  if ((sign && GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT) ||
896  (!sign && tx_sizes.weight > MAX_STANDARD_TX_WEIGHT))
897  {
898  error = _("Transaction too large");
899  return false;
900  }
901 
902  if (nFeeRet > wallet.m_default_max_tx_fee) {
904  return false;
905  }
906 
907  if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
908  // Lastly, ensure this tx will pass the mempool's chain limits
909  if (!wallet.chain().checkChainLimits(tx)) {
910  error = _("Transaction has too long of a mempool chain");
911  return false;
912  }
913  }
914 
915  // Before we return success, we assume any change key will be used to prevent
916  // accidental re-use.
917  reservedest.KeepDestination();
918  fee_calc_out = feeCalc;
919 
920  wallet.WalletLogPrintf("Fee Calculation: Fee:%d Bytes:%u Tgt:%d (requested %d) Reason:\"%s\" Decay %.5f: Estimation: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out) Fail: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out)\n",
921  nFeeRet, nBytes, feeCalc.returnedTarget, feeCalc.desiredTarget, StringForFeeReason(feeCalc.reason), feeCalc.est.decay,
922  feeCalc.est.pass.start, feeCalc.est.pass.end,
923  (feeCalc.est.pass.totalConfirmed + feeCalc.est.pass.inMempool + feeCalc.est.pass.leftMempool) > 0.0 ? 100 * feeCalc.est.pass.withinTarget / (feeCalc.est.pass.totalConfirmed + feeCalc.est.pass.inMempool + feeCalc.est.pass.leftMempool) : 0.0,
924  feeCalc.est.pass.withinTarget, feeCalc.est.pass.totalConfirmed, feeCalc.est.pass.inMempool, feeCalc.est.pass.leftMempool,
925  feeCalc.est.fail.start, feeCalc.est.fail.end,
926  (feeCalc.est.fail.totalConfirmed + feeCalc.est.fail.inMempool + feeCalc.est.fail.leftMempool) > 0.0 ? 100 * feeCalc.est.fail.withinTarget / (feeCalc.est.fail.totalConfirmed + feeCalc.est.fail.inMempool + feeCalc.est.fail.leftMempool) : 0.0,
927  feeCalc.est.fail.withinTarget, feeCalc.est.fail.totalConfirmed, feeCalc.est.fail.inMempool, feeCalc.est.fail.leftMempool);
928  return true;
929 }
930 
932  CWallet& wallet,
933  const std::vector<CRecipient>& vecSend,
934  CTransactionRef& tx,
935  CAmount& nFeeRet,
936  int& nChangePosInOut,
938  const CCoinControl& coin_control,
939  FeeCalculation& fee_calc_out,
940  bool sign)
941 {
942  if (vecSend.empty()) {
943  error = _("Transaction must have at least one recipient");
944  return false;
945  }
946 
947  if (std::any_of(vecSend.cbegin(), vecSend.cend(), [](const auto& recipient){ return recipient.nAmount < 0; })) {
948  error = _("Transaction amounts must not be negative");
949  return false;
950  }
951 
952  LOCK(wallet.cs_wallet);
953 
954  int nChangePosIn = nChangePosInOut;
955  Assert(!tx); // tx is an out-param. TODO change the return type from bool to tx (or nullptr)
956  bool res = CreateTransactionInternal(wallet, vecSend, tx, nFeeRet, nChangePosInOut, error, coin_control, fee_calc_out, sign);
957  // try with avoidpartialspends unless it's enabled already
958  if (res && nFeeRet > 0 /* 0 means non-functional fee rate estimation */ && wallet.m_max_aps_fee > -1 && !coin_control.m_avoid_partial_spends) {
959  CCoinControl tmp_cc = coin_control;
960  tmp_cc.m_avoid_partial_spends = true;
961  CAmount nFeeRet2;
962  CTransactionRef tx2;
963  int nChangePosInOut2 = nChangePosIn;
964  bilingual_str error2; // fired and forgotten; if an error occurs, we discard the results
965  if (CreateTransactionInternal(wallet, vecSend, tx2, nFeeRet2, nChangePosInOut2, error2, tmp_cc, fee_calc_out, sign)) {
966  // if fee of this alternative one is within the range of the max fee, we use this one
967  const bool use_aps = nFeeRet2 <= nFeeRet + wallet.m_max_aps_fee;
968  wallet.WalletLogPrintf("Fee non-grouped = %lld, grouped = %lld, using %s\n", nFeeRet, nFeeRet2, use_aps ? "grouped" : "non-grouped");
969  if (use_aps) {
970  tx = tx2;
971  nFeeRet = nFeeRet2;
972  nChangePosInOut = nChangePosInOut2;
973  }
974  }
975  }
976  return res;
977 }
978 
979 bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, bilingual_str& error, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl coinControl)
980 {
981  std::vector<CRecipient> vecSend;
982 
983  // Turn the txout set into a CRecipient vector.
984  for (size_t idx = 0; idx < tx.vout.size(); idx++) {
985  const CTxOut& txOut = tx.vout[idx];
986  CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
987  vecSend.push_back(recipient);
988  }
989 
990  coinControl.fAllowOtherInputs = true;
991 
992  for (const CTxIn& txin : tx.vin) {
993  coinControl.Select(txin.prevout);
994  }
995 
996  // Acquire the locks to prevent races to the new locked unspents between the
997  // CreateTransaction call and LockCoin calls (when lockUnspents is true).
998  LOCK(wallet.cs_wallet);
999 
1000  CTransactionRef tx_new;
1001  FeeCalculation fee_calc_out;
1002  if (!CreateTransaction(wallet, vecSend, tx_new, nFeeRet, nChangePosInOut, error, coinControl, fee_calc_out, false)) {
1003  return false;
1004  }
1005 
1006  if (nChangePosInOut != -1) {
1007  tx.vout.insert(tx.vout.begin() + nChangePosInOut, tx_new->vout[nChangePosInOut]);
1008  }
1009 
1010  // Copy output sizes from new transaction; they may have had the fee
1011  // subtracted from them.
1012  for (unsigned int idx = 0; idx < tx.vout.size(); idx++) {
1013  tx.vout[idx].nValue = tx_new->vout[idx].nValue;
1014  }
1015 
1016  // Add new txins while keeping original txin scriptSig/order.
1017  for (const CTxIn& txin : tx_new->vin) {
1018  if (!coinControl.IsSelected(txin.prevout)) {
1019  tx.vin.push_back(txin);
1020 
1021  }
1022  if (lockUnspents) {
1023  wallet.LockCoin(txin.prevout);
1024  }
1025 
1026  }
1027 
1028  return true;
1029 }
1030 } // namespace wallet
GetVirtualTransactionInputSize
int64_t GetVirtualTransactionInputSize(const CTxIn &txin, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Definition: policy.cpp:292
GetSerializeSize
size_t GetSerializeSize(const T &t, int nVersion=0)
Definition: serialize.h:1086
CTxIn
An input of a transaction.
Definition: transaction.h:65
wallet::CoinSelectionParams::tx_noinputs_size
size_t tx_noinputs_size
Size of the transaction before coin selection, consisting of the header and recipient output(s),...
Definition: coinselection.h:95
EstimatorBucket::inMempool
double inMempool
Definition: fees.h:62
policy.h
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:366
wallet::SelectCoinsSRD
std::optional< SelectionResult > SelectCoinsSRD(const std::vector< OutputGroup > &utxo_pool, CAmount target_value)
Select coins by Single Random Draw.
Definition: coinselection.cpp:170
wallet::CWalletTx::InMempool
bool InMempool() const
Definition: transaction.cpp:17
CTransaction::vin
const std::vector< CTxIn > vin
Definition: transaction.h:290
wallet::CWalletTx::GetHash
const uint256 & GetHash() const
Definition: transaction.h:298
ArgsManager::GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:600
wallet::OutputGroup::m_outputs
std::vector< CInputCoin > m_outputs
The list of UTXOs contained in this output group.
Definition: coinselection.h:142
EstimatorBucket::start
double start
Definition: fees.h:58
_
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:63
wallet::CCoinControl::m_max_depth
int m_max_depth
Maximum chain depth value for coin availability.
Definition: coincontrol.h:61
OutputType
OutputType
Definition: outputtype.h:18
wallet::isminetype
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
Definition: ismine.h:41
wallet::ISMINE_WATCH_ONLY
@ ISMINE_WATCH_ONLY
Definition: ismine.h:43
assert
assert(!tx.IsCoinBase())
check.h
EstimatorBucket::leftMempool
double leftMempool
Definition: fees.h:63
wallet.h
CHECK_NONFATAL
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
Definition: check.h:32
FeeCalculation::est
EstimationResult est
Definition: fees.h:77
TransactionErrorString
bilingual_str TransactionErrorString(const TransactionError err)
Definition: error.cpp:11
wallet::IsCurrentForAntiFeeSniping
static bool IsCurrentForAntiFeeSniping(interfaces::Chain &chain, const uint256 &block_hash)
Definition: spend.cpp:571
wallet::CCoinControl::fAllowOtherInputs
bool fAllowOtherInputs
If false, allows unselected inputs, but requires all selected inputs be used.
Definition: coincontrol.h:41
wallet::SelectionResult::GetSelectedValue
CAmount GetSelectedValue() const
Get the sum of the input values.
Definition: coinselection.cpp:397
wallet::AttemptSelection
std::optional< SelectionResult > AttemptSelection(const CWallet &wallet, const CAmount &nTargetValue, const CoinEligibilityFilter &eligibility_filter, std::vector< COutput > coins, const CoinSelectionParams &coin_selection_params)
Attempt to find a valid input set that meets the provided eligibility filter and target.
Definition: spend.cpp:373
wallet::CalculateMaximumSignedInputSize
int CalculateMaximumSignedInputSize(const CTxOut &txout, const SigningProvider *provider, bool use_max_sig)
Definition: spend.cpp:37
wallet::GroupOutputs
std::vector< OutputGroup > GroupOutputs(const CWallet &wallet, const std::vector< COutput > &outputs, const CoinSelectionParams &coin_sel_params, const CoinEligibilityFilter &filter, bool positive_only)
Definition: spend.cpp:287
wallet::FindNonChangeParentOutput
const CTxOut & FindNonChangeParentOutput(const CWallet &wallet, const CTransaction &tx, int output)
Find non-change parent output.
Definition: spend.cpp:228
wallet::CoinSelectionParams::m_discard_feerate
CFeeRate m_discard_feerate
If the cost to spend a change output at the discard feerate exceeds its value, drop it to fees.
Definition: coinselection.h:92
moneystr.h
wallet::OUTPUT_GROUP_MAX_ENTRIES
static constexpr size_t OUTPUT_GROUP_MAX_ENTRIES
Definition: spend.cpp:25
FeeCalculation::returnedTarget
int returnedTarget
Definition: fees.h:80
COutPoint::hash
uint256 hash
Definition: transaction.h:29
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:310
bilingual_str
Bilingual messages:
Definition: translation.h:16
interfaces::Chain::isInitialBlockDownload
virtual bool isInitialBlockDownload()=0
Check if in IBD.
wallet::COutput::i
int i
Index in tx->vout.
Definition: spend.h:23
wallet::COutput::tx
const CWalletTx * tx
Definition: spend.h:20
validation.h
wallet::OutputGroup::Insert
void Insert(const CInputCoin &output, int depth, bool from_me, size_t ancestors, size_t descendants, bool positive_only)
Definition: coinselection.cpp:316
wallet::CoinEligibilityFilter::m_include_partial_groups
const bool m_include_partial_groups
When avoid_reuse=true and there are full groups (OUTPUT_GROUP_MAX_ENTRIES), whether or not to use any...
Definition: coinselection.h:131
SigningProvider
An interface to be implemented by keystores that support signing.
Definition: signingprovider.h:17
wallet::CRecipient
Definition: wallet.h:221
GetTime
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
Definition: time.cpp:26
MakeTransactionRef
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:407
CTxIn::MAX_SEQUENCE_NONFINAL
static const uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
Definition: transaction.h:86
wallet::GetAvailableBalance
CAmount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
Definition: spend.cpp:213
wallet::CCoinControl::GetExternalOutput
bool GetExternalOutput(const COutPoint &outpoint, CTxOut &txout) const
Definition: coincontrol.h:82
wallet::CInputCoin::txout
CTxOut txout
Definition: coinselection.h:54
wallet::CCoinControl::HasInputWeight
bool HasInputWeight(const COutPoint &outpoint) const
Definition: coincontrol.h:123
wallet
Definition: node.h:38
wallet::CCoinControl::fAllowWatchOnly
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
Definition: coincontrol.h:43
wallet::CCoinControl::GetInputWeight
int64_t GetInputWeight(const COutPoint &outpoint) const
Definition: coincontrol.h:128
interfaces::Chain::findBlock
virtual bool findBlock(const uint256 &hash, const FoundBlock &block={})=0
Return whether node has the block and optionally return block metadata or contents.
chain.h
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:406
wallet::OutputGroup::GetSelectionAmount
CAmount GetSelectionAmount() const
Definition: coinselection.cpp:355
wallet::KnapsackSolver
std::optional< SelectionResult > KnapsackSolver(std::vector< OutputGroup > &groups, const CAmount &nTargetValue)
Definition: coinselection.cpp:238
wallet::CWalletTx
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:137
wallet::CoinSelectionParams::m_cost_of_change
CAmount m_cost_of_change
Cost of creating the change output + cost of spending the change output in the future.
Definition: coinselection.h:85
Assert
#define Assert(val)
Identity function.
Definition: check.h:57
wallet::CCoinControl::m_add_inputs
bool m_add_inputs
If false, only selected inputs are used.
Definition: coincontrol.h:37
EstimatorBucket::end
double end
Definition: fees.h:59
FeeCalculation::desiredTarget
int desiredTarget
Definition: fees.h:79
wallet::CWalletTx::mapValue
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: transaction.h:165
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:279
rbf.h
AssertLockHeld
AssertLockHeld(pool.cs)
wallet::CoinSelectionParams::m_avoid_partial_spends
bool m_avoid_partial_spends
When true, always spend all (up to OUTPUT_GROUP_MAX_ENTRIES) or none of the outputs associated with t...
Definition: coinselection.h:101
wallet::DUMMY_NESTED_P2WPKH_INPUT_SIZE
static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE
Pre-calculated constants for input size estimation in virtual size
Definition: wallet.h:112
wallet::CachedTxIsTrusted
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
Definition: receive.cpp:279
wallet::CCoinControl::HasSelected
bool HasSelected() const
Definition: coincontrol.h:67
wallet::AvailableCoins
void AvailableCoins(const CWallet &wallet, std::vector< COutput > &vCoins, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount)
populate vCoins with vector of available COutputs.
Definition: spend.cpp:89
CTxOut::nValue
CAmount nValue
Definition: transaction.h:151
FeeCalculation::reason
FeeReason reason
Definition: fees.h:78
signingprovider.h
fees.h
interfaces::Chain
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:94
FeeCalculation
Definition: fees.h:75
CMutableTransaction::nLockTime
uint32_t nLockTime
Definition: transaction.h:369
EstimationResult::decay
double decay
Definition: fees.h:71
GetRandInt
int GetRandInt(int nMax) noexcept
Definition: random.cpp:593
MAX_BIP125_RBF_SEQUENCE
static constexpr uint32_t MAX_BIP125_RBF_SEQUENCE
Definition: rbf.h:12
wallet::CachedTxIsFromMe
bool CachedTxIsFromMe(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Definition: receive.cpp:274
FeeEstimateMode::SAT_VB
@ SAT_VB
Use sat/vB fee rate unit.
CTxDestination
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:157
wallet::CoinSelectionParams::m_effective_feerate
CFeeRate m_effective_feerate
The targeted feerate of the transaction being built.
Definition: coinselection.h:87
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:46
FeeReason::FALLBACK
@ FALLBACK
IsValidDestination
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:332
CTxOut
An output of a transaction.
Definition: transaction.h:148
wallet::CCoinControl::m_external_provider
FlatSigningProvider m_external_provider
SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs.
Definition: coincontrol.h:63
wallet::CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:232
wallet::COutput::nDepth
int nDepth
Depth in block chain.
Definition: spend.h:30
CTransaction::vout
const std::vector< CTxOut > vout
Definition: transaction.h:291
CTxOut::scriptPubKey
CScript scriptPubKey
Definition: transaction.h:152
wallet::CCoinControl::ListSelected
void ListSelected(std::vector< COutPoint > &vOutpoints) const
Definition: coincontrol.h:113
wallet::CCoinControl::m_avoid_address_reuse
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
Definition: coincontrol.h:55
wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:51
prevector::emplace_back
void emplace_back(Args &&... args)
Definition: prevector.h:428
wallet::CCoinControl::m_min_depth
int m_min_depth
Minimum chain depth value for coin availability.
Definition: coincontrol.h:59
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
wallet::CCoinControl::m_avoid_partial_spends
bool m_avoid_partial_spends
Avoid partial use of funds sent to a given address.
Definition: coincontrol.h:53
Shuffle
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
Definition: random.h:243
wallet::DEFAULT_WALLET_REJECT_LONG_CHAINS
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:98
wallet::WALLET_FLAG_AVOID_REUSE
@ WALLET_FLAG_AVOID_REUSE
Definition: walletutil.h:42
wallet::CCoinControl::Select
void Select(const COutPoint &output)
Definition: coincontrol.h:92
interfaces::FoundBlock
Helper for findBlock to selectively return pieces of block data.
Definition: chain.h:43
wallet::FundTransaction
void FundTransaction(CWallet &wallet, CMutableTransaction &tx, CAmount &fee_out, int &change_position, const UniValue &options, CCoinControl &coinControl, bool override_min_fee)
Definition: spend.cpp:390
wallet::OutputGroup
A group of UTXOs paid to the same output script.
Definition: coinselection.h:139
base_blob::ToString
std::string ToString() const
Definition: uint256.cpp:64
uint256
256-bit opaque blob.
Definition: uint256.h:126
CFeeRate::ToString
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:39
wallet::CoinSelectionParams::change_spend_size
size_t change_spend_size
Size of the input to spend a change output in virtual bytes.
Definition: coinselection.h:81
wallet::CreateTransactionInternal
static bool CreateTransactionInternal(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
Definition: spend.cpp:631
wallet::TxSize::weight
int64_t weight
Definition: spend.h:75
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
ExtractDestination
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:213
wallet::CCoinControl::m_include_unsafe_inputs
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
Definition: coincontrol.h:39
wallet::CInputCoin
A UTXO under consideration for use in funding a new transaction.
Definition: coinselection.h:22
wallet::CInputCoin::m_input_bytes
int m_input_bytes
Pre-computed estimated size of this output as a fully-signed input in a transaction.
Definition: coinselection.h:60
gArgs
ArgsManager gArgs
Definition: system.cpp:87
wallet::SelectCoinsBnB
std::optional< SelectionResult > SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change)
Definition: coinselection.cpp:65
LOCKTIME_THRESHOLD
static const unsigned int LOCKTIME_THRESHOLD
Definition: script.h:40
wallet::ISMINE_ALL
@ ISMINE_ALL
Definition: ismine.h:46
wallet::CreateTransaction
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: spend.cpp:931
wallet::ISMINE_SPENDABLE
@ ISMINE_SPENDABLE
Definition: ismine.h:44
wallet::OutputGroup::EligibleForSpending
bool EligibleForSpending(const CoinEligibilityFilter &eligibility_filter) const
Definition: coinselection.cpp:348
transaction.h
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:367
wallet::ReserveDestination::GetReservedDestination
bool GetReservedDestination(CTxDestination &pubkey, bool internal, bilingual_str &error)
Reserve an address.
Definition: wallet.cpp:2339
wallet::CInputCoin::effective_value
CAmount effective_value
Definition: coinselection.h:55
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
wallet::ReserveDestination
A wrapper to reserve an address from a wallet.
Definition: wallet.h:161
wallet::CoinSelectionParams::m_change_fee
CAmount m_change_fee
Cost of creating the change output.
Definition: coinselection.h:83
fees.h
wallet::ReserveDestination::KeepDestination
void KeepDestination()
Keep the address. Do not return it's key to the keypool when this object goes out of scope.
Definition: wallet.cpp:2362
MAX_STANDARD_TX_WEIGHT
static const unsigned int MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
Definition: policy.h:24
GetTransactionWeight
static int64_t GetTransactionWeight(const CTransaction &tx)
Definition: validation.h:147
EstimationResult::fail
EstimatorBucket fail
Definition: fees.h:70
wallet::ListCoins
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
Definition: spend.cpp:246
translation.h
IsSolvable
bool IsSolvable(const SigningProvider &provider, const CScript &script)
Definition: sign.cpp:583
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
COutPoint::n
uint32_t n
Definition: transaction.h:30
wallet::CoinSelectionParams::m_long_term_feerate
CFeeRate m_long_term_feerate
The feerate estimate used to estimate an upper bound on what should be sufficient to spend the change...
Definition: coinselection.h:90
LOCK
#define LOCK(cs)
Definition: sync.h:226
wallet::MIN_FINAL_CHANGE
static const CAmount MIN_FINAL_CHANGE
final minimum change amount after paying for fees
Definition: coinselection.h:19
wallet::CoinSelectionParams
Parameters for one iteration of Coin Selection.
Definition: coinselection.h:76
wallet::COutput
Definition: spend.h:17
wallet::SelectCoins
std::optional< SelectionResult > SelectCoins(const CWallet &wallet, const std::vector< COutput > &vAvailableCoins, const CAmount &nTargetValue, const CCoinControl &coin_control, const CoinSelectionParams &coin_selection_params)
Select a set of coins such that nTargetValue is met and at least all coins from coin_control are sele...
Definition: spend.cpp:414
CTxIn::prevout
COutPoint prevout
Definition: transaction.h:68
wallet::TxSize::vsize
int64_t vsize
Definition: spend.h:74
wallet::ISMINE_NO
@ ISMINE_NO
Definition: ismine.h:42
wallet::CoinSelectionParams::m_subtract_fee_outputs
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
Definition: coinselection.h:97
EstimatorBucket::withinTarget
double withinTarget
Definition: fees.h:60
wallet::SelectionResult::AddInput
void AddInput(const OutputGroup &group)
Definition: coinselection.cpp:408
IsDust
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
Definition: policy.cpp:53
EstimationResult::pass
EstimatorBucket pass
Definition: fees.h:69
prevector::empty
bool empty() const
Definition: prevector.h:286
receive.h
wallet::DEFAULT_MAX_DEPTH
const int DEFAULT_MAX_DEPTH
Definition: coincontrol.h:23
MAX_MONEY
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:26
wallet::GetLocktimeForNewTransaction
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain &chain, const uint256 &block_hash, int block_height)
Return a height-based locktime for new transactions (uses the height of the current chain tip unless ...
Definition: spend.cpp:589
wallet::DEFAULT_MIN_DEPTH
const int DEFAULT_MIN_DEPTH
Definition: coincontrol.h:22
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
wallet::GetTxSpendSize
int GetTxSpendSize(const CWallet &wallet, const CWalletTx &wtx, unsigned int out, bool use_max_sig)
Get the marginal bytes if spending the specified output from this transaction.
Definition: spend.cpp:27
CFeeRate::GetFee
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:23
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
StringForFeeReason
std::string StringForFeeReason(FeeReason reason)
Definition: fees.cpp:17
wallet::CCoinControl::IsSelected
bool IsSelected(const COutPoint &output) const
Definition: coincontrol.h:72
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:364
coincontrol.h
wallet::SelectionResult
Definition: coinselection.h:203
wallet::TxSize
Definition: spend.h:73
amount.h
wallet::CoinEligibilityFilter
Parameters for filtering which OutputGroups we may use in coin selection.
Definition: coinselection.h:119
wallet::CCoinControl
Coin Control Features.
Definition: coincontrol.h:29
GetVirtualTransactionSize
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:282
wallet::OutputIsChange
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
Definition: receive.cpp:88
TransactionError::MAX_FEE_EXCEEDED
@ MAX_FEE_EXCEEDED
spend.h
wallet::GetDiscardRate
CFeeRate GetDiscardRate(const CWallet &wallet)
Return the maximum feerate for discarding change.
Definition: fees.cpp:84
FastRandomContext
Fast randomness source.
Definition: random.h:131
ctx
static secp256k1_context * ctx
Definition: tests.c:32
wallet::CoinSelectionParams::change_output_size
size_t change_output_size
Size of a change output in bytes, determined by the output type.
Definition: coinselection.h:79
wallet::COutput::ToString
std::string ToString() const
Definition: spend.cpp:32
wallet::CWalletTx::tx
CTransactionRef tx
Definition: transaction.h:219
PROTOCOL_VERSION
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12
EstimatorBucket::totalConfirmed
double totalConfirmed
Definition: fees.h:61
wallet::CalculateMaximumSignedTxSize
TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector< CTxOut > &txouts, const CCoinControl *coin_control)
Calculate the size of the transaction assuming all signatures are max size Use DummySignatureCreator,...
Definition: spend.cpp:54
FormatMoney
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:15
wallet::DummySignInput
bool DummySignInput(const SigningProvider &provider, CTxIn &tx_in, const CTxOut &txout, bool use_max_sig)
Definition: wallet.cpp:1495
wallet::GetMinimumFeeRate
CFeeRate GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control, FeeCalculation *feeCalc)
Estimate the minimum fee rate considering user set parameters and the required fee.
Definition: fees.cpp:29