bitcoin_ext/
cpfp.rs

1use bitcoin::{Amount, FeeRate, Txid};
2
3/// Returned by the bark API when creating a P2A CPFP transaction fails.
4#[derive(Debug, thiserror::Error)]
5pub enum CpfpError {
6	#[error("Unable to create CPFP transaction: {0}")]
7	CreateError(String),
8	#[error("Unable to finalize CPFP transaction: {0}")]
9	FinalizeError(String),
10	#[error("You need more confirmations on your on-chain funds, {available} is available but {needed} is needed.")]
11	InsufficientConfirmedFunds { needed: Amount, available: Amount },
12	#[error("An internal error occurred while creating CPFP: {0}")]
13	InternalError(String),
14	#[error("Transaction has no fee anchor: {0}")]
15	NoFeeAnchor(Txid),
16	#[error("Unable to sign CPFP transaction: {0}")]
17	SigningError(String),
18	#[error("Unable to store CPFP transaction: {0}")]
19	StoreError(String),
20}
21
22/// Indicates how fees should be handled by when creating a CPFP [bitcoin::Transaction].
23#[derive(Copy, Clone, Debug, PartialEq, Eq)]
24pub enum MakeCpfpFees {
25	/// Create a normal transaction with the given effective fee rate. If the new transaction spends
26	/// a P2A (Pay-to-Anchor) output, then this represents the effective fee rate of the package as
27	/// a whole, not just the child transaction.
28	Effective(FeeRate),
29	/// The intent is to replace a transaction already in the mempool so certain fee standards must
30	/// be met.
31	///
32	/// See [BIP125](https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki#implementation-details)
33	/// for more details.
34	Rbf {
35		/// This represents the effective fee rate of the current transaction/package in the
36		/// mempool. This must be exceeded by a new transaction. This also does not include bumping
37		/// fees.
38		min_effective_fee_rate: FeeRate,
39		/// The current fee paid by the transaction/package to be replaced in the mempool. This must
40		/// be exceeded by the new transaction.
41		current_package_fee: Amount,
42	},
43}
44
45impl MakeCpfpFees {
46	pub fn effective(&self) -> FeeRate {
47		match self {
48			MakeCpfpFees::Effective(fr) => *fr,
49			MakeCpfpFees::Rbf { min_effective_fee_rate, .. } => *min_effective_fee_rate,
50		}
51	}
52}