Bitcoin Core  27.99.0
P2P Digital Currency
feebumper.h
Go to the documentation of this file.
1 // Copyright (c) 2017-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 #ifndef BITCOIN_WALLET_FEEBUMPER_H
6 #define BITCOIN_WALLET_FEEBUMPER_H
7 
8 #include <consensus/consensus.h>
9 #include <script/interpreter.h>
10 #include <primitives/transaction.h>
11 
12 class uint256;
13 enum class FeeEstimateMode;
14 struct bilingual_str;
15 
16 namespace wallet {
17 class CCoinControl;
18 class CWallet;
19 class CWalletTx;
20 
21 namespace feebumper {
22 
23 enum class Result
24 {
25  OK,
30  MISC_ERROR,
31 };
32 
34 bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid);
35 
50  const uint256& txid,
51  const CCoinControl& coin_control,
52  std::vector<bilingual_str>& errors,
53  CAmount& old_fee,
54  CAmount& new_fee,
56  bool require_mine,
57  const std::vector<CTxOut>& outputs,
58  std::optional<uint32_t> original_change_index = std::nullopt);
59 
64 
70  const uint256& txid,
71  CMutableTransaction&& mtx,
72  std::vector<bilingual_str>& errors,
73  uint256& bumped_txid);
74 
76 {
77 private:
78  int m_sigs_count{0};
79  int64_t m_sigs_weight{0};
80 
81 public:
82  void AddSigWeight(const size_t weight, const SigVersion sigversion)
83  {
84  switch (sigversion) {
85  case SigVersion::BASE:
88  break;
90  m_sigs_weight += weight;
91  m_sigs_count++;
92  break;
95  assert(false);
96  }
97  }
98 
99  int64_t GetWeightDiffToMax() const
100  {
101  // Note: the witness scaling factor is already accounted for because the count is multiplied by it.
102  return (/* max signature size=*/ 72 * m_sigs_count) - m_sigs_weight;
103  }
104 };
105 
107 {
108 private:
110 
111 public:
113 
114  bool CheckECDSASignature(const std::vector<unsigned char>& sig, const std::vector<unsigned char>& pubkey, const CScript& script, SigVersion sigversion) const override
115  {
116  if (m_checker.CheckECDSASignature(sig, pubkey, script, sigversion)) {
117  m_weights.AddSigWeight(sig.size(), sigversion);
118  return true;
119  }
120  return false;
121  }
122 };
123 
124 } // namespace feebumper
125 } // namespace wallet
126 
127 #endif // BITCOIN_WALLET_FEEBUMPER_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
virtual bool CheckECDSASignature(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
Definition: interpreter.h:248
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:414
const BaseSignatureChecker & m_checker
Definition: interpreter.h:312
256-bit opaque blob.
Definition: uint256.h:106
Coin Control Features.
Definition: coincontrol.h:81
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:301
bool CheckECDSASignature(const std::vector< unsigned char > &sig, const std::vector< unsigned char > &pubkey, const CScript &script, SigVersion sigversion) const override
Definition: feebumper.h:114
SignatureWeightChecker(SignatureWeights &weights, const BaseSignatureChecker &checker)
Definition: feebumper.h:112
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
FeeEstimateMode
Definition: feerate.h:21
SigVersion
Definition: interpreter.h:191
@ TAPROOT
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, key path spending; see BIP 341.
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ TAPSCRIPT
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, script path spending, leaf version 0xc0; see...
@ WITNESS_V0
Witness v0 (P2WPKH and P2WSH); see BIP 141.
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
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:355
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Definition: feebumper.cpp:335
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:153
A mutable version of CTransaction.
Definition: transaction.h:378
Bilingual messages:
Definition: translation.h:18
int64_t GetWeightDiffToMax() const
Definition: feebumper.h:99
void AddSigWeight(const size_t weight, const SigVersion sigversion)
Definition: feebumper.h:82
assert(!tx.IsCoinBase())