Bitcoin Core  24.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 
48  const uint256& txid,
49  const CCoinControl& coin_control,
50  std::vector<bilingual_str>& errors,
51  CAmount& old_fee,
52  CAmount& new_fee,
54  bool require_mine,
55  const std::vector<CTxOut>& outputs);
56 
61 
67  const uint256& txid,
68  CMutableTransaction&& mtx,
69  std::vector<bilingual_str>& errors,
70  uint256& bumped_txid);
71 
73 {
74 private:
75  int m_sigs_count{0};
76  int64_t m_sigs_weight{0};
77 
78 public:
79  void AddSigWeight(const size_t weight, const SigVersion sigversion)
80  {
81  switch (sigversion) {
82  case SigVersion::BASE:
85  break;
87  m_sigs_weight += weight;
88  m_sigs_count++;
89  break;
92  assert(false);
93  }
94  }
95 
96  int64_t GetWeightDiffToMax() const
97  {
98  // Note: the witness scaling factor is already accounted for because the count is multiplied by it.
99  return (/* max signature size=*/ 72 * m_sigs_count) - m_sigs_weight;
100  }
101 };
102 
104 {
105 private:
107 
108 public:
110 
111  bool CheckECDSASignature(const std::vector<unsigned char>& sig, const std::vector<unsigned char>& pubkey, const CScript& script, SigVersion sigversion) const override
112  {
113  if (m_checker.CheckECDSASignature(sig, pubkey, script, sigversion)) {
114  m_weights.AddSigWeight(sig.size(), sigversion);
115  return true;
116  }
117  return false;
118  }
119 };
120 
121 } // namespace feebumper
122 } // namespace wallet
123 
124 #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:246
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:411
const BaseSignatureChecker & m_checker
Definition: interpreter.h:310
256-bit opaque blob.
Definition: uint256.h:105
Coin Control Features.
Definition: coincontrol.h:30
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:237
bool CheckECDSASignature(const std::vector< unsigned char > &sig, const std::vector< unsigned char > &pubkey, const CScript &script, SigVersion sigversion) const override
Definition: feebumper.h:111
SignatureWeightChecker(SignatureWeights &weights, const BaseSignatureChecker &checker)
Definition: feebumper.h:109
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
FeeEstimateMode
Definition: feerate.h:21
SigVersion
Definition: interpreter.h:189
@ 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 CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:319
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Definition: feebumper.cpp:299
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:146
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)
Create bumpfee transaction based on feerate estimates.
Definition: feebumper.cpp:157
Definition: node.h:39
A mutable version of CTransaction.
Definition: transaction.h:380
Bilingual messages:
Definition: translation.h:18
int64_t GetWeightDiffToMax() const
Definition: feebumper.h:96
void AddSigWeight(const size_t weight, const SigVersion sigversion)
Definition: feebumper.h:79
assert(!tx.IsCoinBase())