2020-04-16 13:14:08 -04:00
|
|
|
// Copyright (c) 2017-2020 The Bitcoin Core developers
|
2017-03-03 16:15:47 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_WALLET_FEEBUMPER_H
|
|
|
|
#define BITCOIN_WALLET_FEEBUMPER_H
|
|
|
|
|
2021-10-05 21:41:54 -04:00
|
|
|
#include <consensus/consensus.h>
|
|
|
|
#include <script/interpreter.h>
|
2017-03-03 16:15:47 +01:00
|
|
|
#include <primitives/transaction.h>
|
|
|
|
|
|
|
|
class uint256;
|
2017-06-14 15:15:40 -04:00
|
|
|
enum class FeeEstimateMode;
|
2020-04-18 15:18:17 -04:00
|
|
|
struct bilingual_str;
|
2017-03-03 16:15:47 +01:00
|
|
|
|
2021-11-12 11:13:29 -05:00
|
|
|
namespace wallet {
|
|
|
|
class CCoinControl;
|
|
|
|
class CWallet;
|
|
|
|
class CWalletTx;
|
|
|
|
|
2017-09-20 16:19:30 -04:00
|
|
|
namespace feebumper {
|
|
|
|
|
|
|
|
enum class Result
|
2017-03-03 16:15:47 +01:00
|
|
|
{
|
|
|
|
OK,
|
|
|
|
INVALID_ADDRESS_OR_KEY,
|
|
|
|
INVALID_REQUEST,
|
|
|
|
INVALID_PARAMETER,
|
|
|
|
WALLET_ERROR,
|
|
|
|
MISC_ERROR,
|
|
|
|
};
|
|
|
|
|
2017-06-15 10:34:17 -04:00
|
|
|
//! Return whether transaction can be bumped.
|
2019-10-10 12:12:28 -04:00
|
|
|
bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid);
|
2017-06-15 10:34:17 -04:00
|
|
|
|
2021-10-05 22:06:19 -04:00
|
|
|
/** Create bumpfee transaction based on feerate estimates.
|
|
|
|
*
|
|
|
|
* @param[in] wallet The wallet to use for this bumping
|
|
|
|
* @param[in] txid The txid of the transaction to bump
|
|
|
|
* @param[in] coin_control A CCoinControl object which provides feerates and other information used for coin selection
|
|
|
|
* @param[out] errors Errors
|
|
|
|
* @param[out] old_fee The fee the original transaction pays
|
|
|
|
* @param[out] new_fee the fee that the bump transaction pays
|
|
|
|
* @param[out] mtx The bump transaction itself
|
|
|
|
* @param[in] require_mine Whether the original transaction must consist of inputs that can be spent by the wallet
|
|
|
|
*/
|
2019-10-10 12:12:28 -04:00
|
|
|
Result CreateRateBumpTransaction(CWallet& wallet,
|
2020-04-18 15:18:17 -04:00
|
|
|
const uint256& txid,
|
|
|
|
const CCoinControl& coin_control,
|
|
|
|
std::vector<bilingual_str>& errors,
|
|
|
|
CAmount& old_fee,
|
|
|
|
CAmount& new_fee,
|
2021-10-05 22:06:19 -04:00
|
|
|
CMutableTransaction& mtx,
|
|
|
|
bool require_mine);
|
2019-03-06 16:30:00 -05:00
|
|
|
|
2017-06-15 10:34:17 -04:00
|
|
|
//! Sign the new transaction,
|
|
|
|
//! @return false if the tx couldn't be found or if it was
|
|
|
|
//! impossible to create the signature(s)
|
2019-10-10 12:12:28 -04:00
|
|
|
bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx);
|
2017-06-15 10:34:17 -04:00
|
|
|
|
|
|
|
//! Commit the bumpfee transaction.
|
|
|
|
//! @return success in case of CWallet::CommitTransaction was successful,
|
|
|
|
//! but sets errors if the tx could not be added to the mempool (will try later)
|
|
|
|
//! or if the old transaction could not be marked as replaced.
|
2019-10-10 12:12:28 -04:00
|
|
|
Result CommitTransaction(CWallet& wallet,
|
2020-04-18 15:18:17 -04:00
|
|
|
const uint256& txid,
|
|
|
|
CMutableTransaction&& mtx,
|
|
|
|
std::vector<bilingual_str>& errors,
|
|
|
|
uint256& bumped_txid);
|
2017-03-03 16:15:47 +01:00
|
|
|
|
2021-10-05 21:41:54 -04:00
|
|
|
struct SignatureWeights
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int m_sigs_count{0};
|
|
|
|
int64_t m_sigs_weight{0};
|
|
|
|
|
|
|
|
public:
|
|
|
|
void AddSigWeight(const size_t weight, const SigVersion sigversion)
|
|
|
|
{
|
|
|
|
switch (sigversion) {
|
|
|
|
case SigVersion::BASE:
|
|
|
|
m_sigs_weight += weight * WITNESS_SCALE_FACTOR;
|
|
|
|
m_sigs_count += 1 * WITNESS_SCALE_FACTOR;
|
|
|
|
break;
|
|
|
|
case SigVersion::WITNESS_V0:
|
|
|
|
m_sigs_weight += weight;
|
|
|
|
m_sigs_count++;
|
|
|
|
break;
|
|
|
|
case SigVersion::TAPROOT:
|
|
|
|
case SigVersion::TAPSCRIPT:
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t GetWeightDiffToMax() const
|
|
|
|
{
|
|
|
|
// Note: the witness scaling factor is already accounted for because the count is multiplied by it.
|
|
|
|
return (/* max signature size=*/ 72 * m_sigs_count) - m_sigs_weight;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SignatureWeightChecker : public DeferringSignatureChecker
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SignatureWeights& m_weights;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SignatureWeightChecker(SignatureWeights& weights, const BaseSignatureChecker& checker) : DeferringSignatureChecker(checker), m_weights(weights) {}
|
|
|
|
|
|
|
|
bool CheckECDSASignature(const std::vector<unsigned char>& sig, const std::vector<unsigned char>& pubkey, const CScript& script, SigVersion sigversion) const override
|
|
|
|
{
|
|
|
|
if (m_checker.CheckECDSASignature(sig, pubkey, script, sigversion)) {
|
|
|
|
m_weights.AddSigWeight(sig.size(), sigversion);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-20 16:19:30 -04:00
|
|
|
} // namespace feebumper
|
2021-11-12 11:13:29 -05:00
|
|
|
} // namespace wallet
|
2017-09-20 16:19:30 -04:00
|
|
|
|
2017-03-03 16:15:47 +01:00
|
|
|
#endif // BITCOIN_WALLET_FEEBUMPER_H
|