Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2017-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_WALLET_FEEBUMPER_H6#define BITCOIN_WALLET_FEEBUMPER_H8#include <consensus/consensus.h>9#include <script/interpreter.h>10#include <primitives/transaction.h>12class uint256;13enum class FeeEstimateMode;14struct bilingual_str;16namespace wallet {17class CCoinControl;18class CWallet;19class CWalletTx;21namespace feebumper {23enum class Result24{25OK,26INVALID_ADDRESS_OR_KEY,27INVALID_REQUEST,28INVALID_PARAMETER,29WALLET_ERROR,30MISC_ERROR,31};33//! Return whether transaction can be bumped.34bool TransactionCanBeBumped(const CWallet& wallet, const Txid& txid);36/** Create bumpfee transaction based on feerate estimates.37*38* @param[in] wallet The wallet to use for this bumping39* @param[in] txid The txid of the transaction to bump40* @param[in] coin_control A CCoinControl object which provides feerates and other information used for coin selection41* @param[out] errors Errors42* @param[out] old_fee The fee the original transaction pays43* @param[out] new_fee the fee that the bump transaction pays44* @param[out] mtx The bump transaction itself45* @param[in] require_mine Whether the original transaction must consist of inputs that can be spent by the wallet46* @param[in] outputs Vector of new outputs to replace the bumped transaction's outputs47* @param[in] original_change_index The position of the change output to deduct the fee from in the transaction being bumped48*/49Result CreateRateBumpTransaction(CWallet& wallet,50const Txid& txid,51const CCoinControl& coin_control,52std::vector<bilingual_str>& errors,53CAmount& old_fee,54CAmount& new_fee,55CMutableTransaction& mtx,56bool require_mine,57const std::vector<CTxOut>& outputs,58std::optional<uint32_t> original_change_index = std::nullopt);60//! Sign the new transaction,61//! @return false if the tx couldn't be found or if it was62//! impossible to create the signature(s)63bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx);65//! Commit the bumpfee transaction.66//! @return success in case of CWallet::CommitTransaction was successful,67//! but sets errors if the tx could not be added to the mempool (will try later)68//! or if the old transaction could not be marked as replaced.69Result CommitTransaction(CWallet& wallet,70const Txid& txid,71CMutableTransaction&& mtx,72std::vector<bilingual_str>& errors,73Txid& bumped_txid);75struct SignatureWeights76{77private:78int m_sigs_count{0};79int64_t m_sigs_weight{0};81public:82void AddSigWeight(const size_t weight, const SigVersion sigversion)83{84switch (sigversion) {85case SigVersion::BASE:86m_sigs_weight += weight * WITNESS_SCALE_FACTOR;87m_sigs_count += 1 * WITNESS_SCALE_FACTOR;88break;89case SigVersion::WITNESS_V0:90m_sigs_weight += weight;91m_sigs_count++;92break;93case SigVersion::TAPROOT:94case SigVersion::TAPSCRIPT:95assert(false);96}97}99int64_t GetWeightDiffToMax() const100{101// Note: the witness scaling factor is already accounted for because the count is multiplied by it.102return (/* max signature size=*/ 72 * m_sigs_count) - m_sigs_weight;103}104};106class SignatureWeightChecker : public DeferringSignatureChecker107{108private:109SignatureWeights& m_weights;111public:112SignatureWeightChecker(SignatureWeights& weights, const BaseSignatureChecker& checker) : DeferringSignatureChecker(checker), m_weights(weights) {}114bool CheckECDSASignature(const std::vector<unsigned char>& sig, const std::vector<unsigned char>& pubkey, const CScript& script, SigVersion sigversion) const override115{116if (m_checker.CheckECDSASignature(sig, pubkey, script, sigversion)) {117m_weights.AddSigWeight(sig.size(), sigversion);118return true;119}120return false;121}122};124} // namespace feebumper125} // namespace wallet127#endif // BITCOIN_WALLET_FEEBUMPER_H