Bitcoin Core  26.1.0
P2P Digital Currency
feebumper.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2022 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/system.h>
6 #include <consensus/validation.h>
7 #include <interfaces/chain.h>
8 #include <policy/fees.h>
9 #include <policy/policy.h>
10 #include <util/moneystr.h>
11 #include <util/rbf.h>
12 #include <util/translation.h>
13 #include <wallet/coincontrol.h>
14 #include <wallet/feebumper.h>
15 #include <wallet/fees.h>
16 #include <wallet/receive.h>
17 #include <wallet/spend.h>
18 #include <wallet/wallet.h>
19 
20 namespace wallet {
23 static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWalletTx& wtx, bool require_mine, std::vector<bilingual_str>& errors) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
24 {
25  if (wallet.HasWalletSpend(wtx.tx)) {
26  errors.push_back(Untranslated("Transaction has descendants in the wallet"));
28  }
29 
30  {
31  if (wallet.chain().hasDescendantsInMempool(wtx.GetHash())) {
32  errors.push_back(Untranslated("Transaction has descendants in the mempool"));
34  }
35  }
36 
37  if (wallet.GetTxDepthInMainChain(wtx) != 0) {
38  errors.push_back(Untranslated("Transaction has been mined, or is conflicted with a mined transaction"));
40  }
41 
42  if (!SignalsOptInRBF(*wtx.tx)) {
43  errors.push_back(Untranslated("Transaction is not BIP 125 replaceable"));
45  }
46 
47  if (wtx.mapValue.count("replaced_by_txid")) {
48  errors.push_back(strprintf(Untranslated("Cannot bump transaction %s which was already bumped by transaction %s"), wtx.GetHash().ToString(), wtx.mapValue.at("replaced_by_txid")));
50  }
51 
52  if (require_mine) {
53  // check that original tx consists entirely of our inputs
54  // if not, we can't bump the fee, because the wallet has no way of knowing the value of the other inputs (thus the fee)
55  isminefilter filter = wallet.GetLegacyScriptPubKeyMan() && wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;
56  if (!AllInputsMine(wallet, *wtx.tx, filter)) {
57  errors.push_back(Untranslated("Transaction contains inputs that don't belong to this wallet"));
59  }
60  }
61 
62  return feebumper::Result::OK;
63 }
64 
66 static feebumper::Result CheckFeeRate(const CWallet& wallet, const CMutableTransaction& mtx, const CFeeRate& newFeerate, const int64_t maxTxSize, CAmount old_fee, std::vector<bilingual_str>& errors)
67 {
68  // check that fee rate is higher than mempool's minimum fee
69  // (no point in bumping fee if we know that the new tx won't be accepted to the mempool)
70  // This may occur if the user set fee_rate or paytxfee too low, if fallbackfee is too low, or, perhaps,
71  // in a rare situation where the mempool minimum fee increased significantly since the fee estimation just a
72  // moment earlier. In this case, we report an error to the user, who may adjust the fee.
73  CFeeRate minMempoolFeeRate = wallet.chain().mempoolMinFee();
74 
75  if (newFeerate.GetFeePerK() < minMempoolFeeRate.GetFeePerK()) {
76  errors.push_back(strprintf(
77  Untranslated("New fee rate (%s) is lower than the minimum fee rate (%s) to get into the mempool -- "),
78  FormatMoney(newFeerate.GetFeePerK()),
79  FormatMoney(minMempoolFeeRate.GetFeePerK())));
81  }
82 
83  std::vector<COutPoint> reused_inputs;
84  reused_inputs.reserve(mtx.vin.size());
85  for (const CTxIn& txin : mtx.vin) {
86  reused_inputs.push_back(txin.prevout);
87  }
88 
89  std::optional<CAmount> combined_bump_fee = wallet.chain().CalculateCombinedBumpFee(reused_inputs, newFeerate);
90  if (!combined_bump_fee.has_value()) {
91  errors.push_back(strprintf(Untranslated("Failed to calculate bump fees, because unconfirmed UTXOs depend on enormous cluster of unconfirmed transactions.")));
92  }
93  CAmount new_total_fee = newFeerate.GetFee(maxTxSize) + combined_bump_fee.value();
94 
95  CFeeRate incrementalRelayFee = std::max(wallet.chain().relayIncrementalFee(), CFeeRate(WALLET_INCREMENTAL_RELAY_FEE));
96 
97  // Min total fee is old fee + relay fee
98  CAmount minTotalFee = old_fee + incrementalRelayFee.GetFee(maxTxSize);
99 
100  if (new_total_fee < minTotalFee) {
101  errors.push_back(strprintf(Untranslated("Insufficient total fee %s, must be at least %s (oldFee %s + incrementalFee %s)"),
102  FormatMoney(new_total_fee), FormatMoney(minTotalFee), FormatMoney(old_fee), FormatMoney(incrementalRelayFee.GetFee(maxTxSize))));
104  }
105 
106  CAmount requiredFee = GetRequiredFee(wallet, maxTxSize);
107  if (new_total_fee < requiredFee) {
108  errors.push_back(strprintf(Untranslated("Insufficient total fee (cannot be less than required fee %s)"),
109  FormatMoney(requiredFee)));
111  }
112 
113  // Check that in all cases the new fee doesn't violate maxTxFee
114  const CAmount max_tx_fee = wallet.m_default_max_tx_fee;
115  if (new_total_fee > max_tx_fee) {
116  errors.push_back(strprintf(Untranslated("Specified or calculated fee %s is too high (cannot be higher than -maxtxfee %s)"),
117  FormatMoney(new_total_fee), FormatMoney(max_tx_fee)));
119  }
120 
121  return feebumper::Result::OK;
122 }
123 
124 static CFeeRate EstimateFeeRate(const CWallet& wallet, const CWalletTx& wtx, const CAmount old_fee, const CCoinControl& coin_control)
125 {
126  // Get the fee rate of the original transaction. This is calculated from
127  // the tx fee/vsize, so it may have been rounded down. Add 1 satoshi to the
128  // result.
129  int64_t txSize = GetVirtualTransactionSize(*(wtx.tx));
130  CFeeRate feerate(old_fee, txSize);
131  feerate += CFeeRate(1);
132 
133  // The node has a configurable incremental relay fee. Increment the fee by
134  // the minimum of that and the wallet's conservative
135  // WALLET_INCREMENTAL_RELAY_FEE value to future proof against changes to
136  // network wide policy for incremental relay fee that our node may not be
137  // aware of. This ensures we're over the required relay fee rate
138  // (Rule 4). The replacement tx will be at least as large as the
139  // original tx, so the total fee will be greater (Rule 3)
140  CFeeRate node_incremental_relay_fee = wallet.chain().relayIncrementalFee();
141  CFeeRate wallet_incremental_relay_fee = CFeeRate(WALLET_INCREMENTAL_RELAY_FEE);
142  feerate += std::max(node_incremental_relay_fee, wallet_incremental_relay_fee);
143 
144  // Fee rate must also be at least the wallet's GetMinimumFeeRate
145  CFeeRate min_feerate(GetMinimumFeeRate(wallet, coin_control, /*feeCalc=*/nullptr));
146 
147  // Set the required fee rate for the replacement transaction in coin control.
148  return std::max(feerate, min_feerate);
149 }
150 
151 namespace feebumper {
152 
153 bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid)
154 {
155  LOCK(wallet.cs_wallet);
156  const CWalletTx* wtx = wallet.GetWalletTx(txid);
157  if (wtx == nullptr) return false;
158 
159  std::vector<bilingual_str> errors_dummy;
160  feebumper::Result res = PreconditionChecks(wallet, *wtx, /* require_mine=*/ true, errors_dummy);
161  return res == feebumper::Result::OK;
162 }
163 
164 Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCoinControl& coin_control, std::vector<bilingual_str>& errors,
165  CAmount& old_fee, CAmount& new_fee, CMutableTransaction& mtx, bool require_mine, const std::vector<CTxOut>& outputs, std::optional<uint32_t> original_change_index)
166 {
167  // For now, cannot specify both new outputs to use and an output index to send change
168  if (!outputs.empty() && original_change_index.has_value()) {
169  errors.push_back(Untranslated("The options 'outputs' and 'original_change_index' are incompatible. You can only either specify a new set of outputs, or designate a change output to be recycled."));
171  }
172 
173  // We are going to modify coin control later, copy to re-use
174  CCoinControl new_coin_control(coin_control);
175 
176  LOCK(wallet.cs_wallet);
177  errors.clear();
178  auto it = wallet.mapWallet.find(txid);
179  if (it == wallet.mapWallet.end()) {
180  errors.push_back(Untranslated("Invalid or non-wallet transaction id"));
182  }
183  const CWalletTx& wtx = it->second;
184 
185  // Make sure that original_change_index is valid
186  if (original_change_index.has_value() && original_change_index.value() >= wtx.tx->vout.size()) {
187  errors.push_back(Untranslated("Change position is out of range"));
189  }
190 
191  // Retrieve all of the UTXOs and add them to coin control
192  // While we're here, calculate the input amount
193  std::map<COutPoint, Coin> coins;
194  CAmount input_value = 0;
195  std::vector<CTxOut> spent_outputs;
196  for (const CTxIn& txin : wtx.tx->vin) {
197  coins[txin.prevout]; // Create empty map entry keyed by prevout.
198  }
199  wallet.chain().findCoins(coins);
200  for (const CTxIn& txin : wtx.tx->vin) {
201  const Coin& coin = coins.at(txin.prevout);
202  if (coin.out.IsNull()) {
203  errors.push_back(Untranslated(strprintf("%s:%u is already spent", txin.prevout.hash.GetHex(), txin.prevout.n)));
204  return Result::MISC_ERROR;
205  }
206  if (wallet.IsMine(txin.prevout)) {
207  new_coin_control.Select(txin.prevout);
208  } else {
209  new_coin_control.SelectExternal(txin.prevout, coin.out);
210  }
211  input_value += coin.out.nValue;
212  spent_outputs.push_back(coin.out);
213  }
214 
215  // Figure out if we need to compute the input weight, and do so if necessary
217  txdata.Init(*wtx.tx, std::move(spent_outputs), /* force=*/ true);
218  for (unsigned int i = 0; i < wtx.tx->vin.size(); ++i) {
219  const CTxIn& txin = wtx.tx->vin.at(i);
220  const Coin& coin = coins.at(txin.prevout);
221 
222  if (new_coin_control.IsExternalSelected(txin.prevout)) {
223  // For external inputs, we estimate the size using the size of this input
224  int64_t input_weight = GetTransactionInputWeight(txin);
225  // Because signatures can have different sizes, we need to figure out all of the
226  // signature sizes and replace them with the max sized signature.
227  // In order to do this, we verify the script with a special SignatureChecker which
228  // will observe the signatures verified and record their sizes.
229  SignatureWeights weights;
230  TransactionSignatureChecker tx_checker(wtx.tx.get(), i, coin.out.nValue, txdata, MissingDataBehavior::FAIL);
231  SignatureWeightChecker size_checker(weights, tx_checker);
233  // Add the difference between max and current to input_weight so that it represents the largest the input could be
234  input_weight += weights.GetWeightDiffToMax();
235  new_coin_control.SetInputWeight(txin.prevout, input_weight);
236  }
237  }
238 
239  Result result = PreconditionChecks(wallet, wtx, require_mine, errors);
240  if (result != Result::OK) {
241  return result;
242  }
243 
244  // Calculate the old output amount.
245  CAmount output_value = 0;
246  for (const auto& old_output : wtx.tx->vout) {
247  output_value += old_output.nValue;
248  }
249 
250  old_fee = input_value - output_value;
251 
252  // Fill in recipients (and preserve a single change key if there
253  // is one). If outputs vector is non-empty, replace original
254  // outputs with its contents, otherwise use original outputs.
255  std::vector<CRecipient> recipients;
256  CAmount new_outputs_value = 0;
257  const auto& txouts = outputs.empty() ? wtx.tx->vout : outputs;
258  for (size_t i = 0; i < txouts.size(); ++i) {
259  const CTxOut& output = txouts.at(i);
260  CTxDestination dest;
261  ExtractDestination(output.scriptPubKey, dest);
262  if (original_change_index.has_value() ? original_change_index.value() == i : OutputIsChange(wallet, output)) {
263  new_coin_control.destChange = dest;
264  } else {
265  CRecipient recipient = {dest, output.nValue, false};
266  recipients.push_back(recipient);
267  }
268  new_outputs_value += output.nValue;
269  }
270 
271  // If no recipients, means that we are sending coins to a change address
272  if (recipients.empty()) {
273  // Just as a sanity check, ensure that the change address exist
274  if (std::get_if<CNoDestination>(&new_coin_control.destChange)) {
275  errors.emplace_back(Untranslated("Unable to create transaction. Transaction must have at least one recipient"));
277  }
278 
279  // Add change as recipient with SFFO flag enabled, so fees are deduced from it.
280  // If the output differs from the original tx output (because the user customized it) a new change output will be created.
281  recipients.emplace_back(CRecipient{new_coin_control.destChange, new_outputs_value, /*fSubtractFeeFromAmount=*/true});
282  new_coin_control.destChange = CNoDestination();
283  }
284 
285  if (coin_control.m_feerate) {
286  // The user provided a feeRate argument.
287  // We calculate this here to avoid compiler warning on the cs_wallet lock
288  // We need to make a temporary transaction with no input witnesses as the dummy signer expects them to be empty for external inputs
289  CMutableTransaction temp_mtx{*wtx.tx};
290  for (auto& txin : temp_mtx.vin) {
291  txin.scriptSig.clear();
292  txin.scriptWitness.SetNull();
293  }
294  temp_mtx.vout = txouts;
295  const int64_t maxTxSize{CalculateMaximumSignedTxSize(CTransaction(temp_mtx), &wallet, &new_coin_control).vsize};
296  Result res = CheckFeeRate(wallet, temp_mtx, *new_coin_control.m_feerate, maxTxSize, old_fee, errors);
297  if (res != Result::OK) {
298  return res;
299  }
300  } else {
301  // The user did not provide a feeRate argument
302  new_coin_control.m_feerate = EstimateFeeRate(wallet, wtx, old_fee, new_coin_control);
303  }
304 
305  // Fill in required inputs we are double-spending(all of them)
306  // N.B.: bip125 doesn't require all the inputs in the replaced transaction to be
307  // used in the replacement transaction, but it's very important for wallets to make
308  // sure that happens. If not, it would be possible to bump a transaction A twice to
309  // A2 and A3 where A2 and A3 don't conflict (or alternatively bump A to A2 and A2
310  // to A3 where A and A3 don't conflict). If both later get confirmed then the sender
311  // has accidentally double paid.
312  for (const auto& inputs : wtx.tx->vin) {
313  new_coin_control.Select(COutPoint(inputs.prevout));
314  }
315  new_coin_control.m_allow_other_inputs = true;
316 
317  // We cannot source new unconfirmed inputs(bip125 rule 2)
318  new_coin_control.m_min_depth = 1;
319 
320  constexpr int RANDOM_CHANGE_POSITION = -1;
321  auto res = CreateTransaction(wallet, recipients, RANDOM_CHANGE_POSITION, new_coin_control, false);
322  if (!res) {
323  errors.push_back(Untranslated("Unable to create transaction.") + Untranslated(" ") + util::ErrorString(res));
324  return Result::WALLET_ERROR;
325  }
326 
327  const auto& txr = *res;
328  // Write back new fee if successful
329  new_fee = txr.fee;
330 
331  // Write back transaction
332  mtx = CMutableTransaction(*txr.tx);
333 
334  return Result::OK;
335 }
336 
338  LOCK(wallet.cs_wallet);
339 
340  if (wallet.IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
341  // Make a blank psbt
342  PartiallySignedTransaction psbtx(mtx);
343 
344  // First fill transaction with our data without signing,
345  // so external signers are not asked to sign more than once.
346  bool complete;
347  wallet.FillPSBT(psbtx, complete, SIGHASH_ALL, false /* sign */, true /* bip32derivs */);
348  const TransactionError err = wallet.FillPSBT(psbtx, complete, SIGHASH_ALL, true /* sign */, false /* bip32derivs */);
349  if (err != TransactionError::OK) return false;
350  complete = FinalizeAndExtractPSBT(psbtx, mtx);
351  return complete;
352  } else {
353  return wallet.SignTransaction(mtx);
354  }
355 }
356 
357 Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransaction&& mtx, std::vector<bilingual_str>& errors, uint256& bumped_txid)
358 {
359  LOCK(wallet.cs_wallet);
360  if (!errors.empty()) {
361  return Result::MISC_ERROR;
362  }
363  auto it = txid.IsNull() ? wallet.mapWallet.end() : wallet.mapWallet.find(txid);
364  if (it == wallet.mapWallet.end()) {
365  errors.push_back(Untranslated("Invalid or non-wallet transaction id"));
366  return Result::MISC_ERROR;
367  }
368  const CWalletTx& oldWtx = it->second;
369 
370  // make sure the transaction still has no descendants and hasn't been mined in the meantime
371  Result result = PreconditionChecks(wallet, oldWtx, /* require_mine=*/ false, errors);
372  if (result != Result::OK) {
373  return result;
374  }
375 
376  // commit/broadcast the tx
377  CTransactionRef tx = MakeTransactionRef(std::move(mtx));
378  mapValue_t mapValue = oldWtx.mapValue;
379  mapValue["replaces_txid"] = oldWtx.GetHash().ToString();
380 
381  wallet.CommitTransaction(tx, std::move(mapValue), oldWtx.vOrderForm);
382 
383  // mark the original tx as bumped
384  bumped_txid = tx->GetHash();
385  if (!wallet.MarkReplaced(oldWtx.GetHash(), bumped_txid)) {
386  errors.push_back(Untranslated("Created new bumpfee transaction but could not mark the original transaction as replaced"));
387  }
388  return Result::OK;
389 }
390 
391 } // namespace feebumper
392 } // namespace wallet
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:421
CAmount nValue
Definition: transaction.h:160
static feebumper::Result PreconditionChecks(const CWallet &wallet, const CWalletTx &wtx, bool require_mine, std::vector< bilingual_str > &errors) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
Check whether transaction has descendant in wallet or mempool, or has been mined, or conflicts with a...
Definition: feebumper.cpp:23
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: transaction.h:199
CScript scriptPubKey
Definition: transaction.h:161
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
Definition: receive.cpp:73
A UTXO entry.
Definition: coins.h:31
CTxDestination destChange
Custom change destination, if not set an address is generated.
Definition: coincontrol.h:32
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
std::map< std::string, std::string > mapValue_t
Definition: transaction.h:144
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
std::vector< CTxIn > vin
Definition: transaction.h:381
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:80
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:48
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: transaction.h:200
CTxOut out
unspent transaction output
Definition: coins.h:35
static CFeeRate EstimateFeeRate(const CWallet &wallet, const CWalletTx &wtx, const CAmount old_fee, const CCoinControl &coin_control)
Definition: feebumper.cpp:124
A version of CTransaction with the PSBT format.
Definition: psbt.h:946
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &txid, const CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx, bool require_mine, const std::vector< CTxOut > &outputs, std::optional< uint32_t > original_change_index)
Create bumpfee transaction based on feerate estimates.
Definition: feebumper.cpp:164
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:295
int64_t vsize
Definition: spend.h:23
bool SignalsOptInRBF(const CTransaction &tx)
Check whether the sequence numbers on this transaction are signaling opt-in to replace-by-fee, according to BIP 125.
Definition: rbf.cpp:9
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized...
Definition: psbt.cpp:495
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
Definition: policy.h:103
void SelectExternal(const COutPoint &outpoint, const CTxOut &txout)
Lock-in the given output as an external input for spending because it is not in the wallet...
Definition: coincontrol.cpp:45
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:153
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:357
bool IsNull() const
Definition: transaction.h:178
void Select(const COutPoint &output)
Lock-in the given output for spending.
Definition: coincontrol.cpp:40
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:171
Indicates that the wallet needs an external signer.
Definition: walletutil.h:77
std::underlying_type< isminetype >::type isminefilter
used for bitflags of isminetype
Definition: wallet.h:43
void Init(const T &tx, std::vector< CTxOut > &&spent_outputs, bool force=false)
Initialize this PrecomputedTransactionData with transaction data.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
Definition: addresstype.cpp:49
static const CAmount WALLET_INCREMENTAL_RELAY_FEE
minimum recommended increment for replacement txs
Definition: wallet.h:125
An input of a transaction.
Definition: transaction.h:74
static int64_t GetTransactionInputWeight(const CTxIn &txin)
Definition: validation.h:156
#define LOCK(cs)
Definition: sync.h:258
static feebumper::Result CheckFeeRate(const CWallet &wallet, const CMutableTransaction &mtx, const CFeeRate &newFeerate, const int64_t maxTxSize, CAmount old_fee, std::vector< bilingual_str > &errors)
Check if the user provided a valid feeRate.
Definition: feebumper.cpp:66
int64_t GetWeightDiffToMax() const
Definition: feebumper.h:99
uint32_t n
Definition: transaction.h:39
Just act as if the signature was invalid.
void SetInputWeight(const COutPoint &outpoint, int64_t weight)
Set an input&#39;s weight.
Definition: coincontrol.cpp:66
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:300
bool IsExternalSelected(const COutPoint &output) const
Returns true if the given output is selected as an external input.
Definition: coincontrol.cpp:25
An output of a transaction.
Definition: transaction.h:157
std::string ToString() const
Definition: uint256.cpp:55
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:35
void SetNull()
Definition: script.h:575
constexpr bool IsNull() const
Definition: uint256.h:42
TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector< CTxOut > &txouts, const CCoinControl *coin_control)
Calculate the size of the transaction using CoinControl to determine whether to expect signature grin...
Definition: spend.cpp:132
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
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:422
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Definition: feebumper.cpp:337
CScript scriptSig
Definition: transaction.h:78
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Definition: addresstype.h:129
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:16
256-bit opaque blob.
Definition: uint256.h:106
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
int m_min_depth
Minimum chain depth value for coin availability.
Definition: coincontrol.h:57
const uint256 & GetHash() const
Definition: transaction.h:333
std::string GetHex() const
Definition: uint256.cpp:11
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
Definition: coincontrol.h:39
TransactionError
Definition: error.h:22
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:32
util::Result< CreatedTransactionResult > CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, int change_pos, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: spend.cpp:1278
bilingual_str ErrorString(const Result< T > &result)
Definition: result.h:81
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition: feerate.cpp:23
A mutable version of CTransaction.
Definition: transaction.h:379
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
Definition: fees.cpp:13
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:294
bool AllInputsMine(const CWallet &wallet, const CTransaction &tx, const isminefilter &filter)
Returns whether all of the inputs match the filter.
Definition: receive.cpp:22
COutPoint prevout
Definition: transaction.h:77
std::optional< CFeeRate > m_feerate
Override the wallet&#39;s m_pay_tx_fee if set.
Definition: coincontrol.h:45
void clear()
Definition: script.h:556
CTransactionRef tx
Definition: transaction.h:253
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
Definition: feerate.h:65
Coin Control Features.
Definition: coincontrol.h:28
uint256 hash
Definition: transaction.h:38