Skip to main content

bark_json/exit/
package.rs

1use bitcoin::{Amount, FeeRate};
2#[cfg(feature = "utoipa")]
3use utoipa::ToSchema;
4
5use crate::exit::states::ExitTxOrigin;
6use crate::primitives::TransactionInfo;
7
8#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
9#[cfg_attr(feature = "utoipa", derive(ToSchema))]
10pub struct ExitTransactionPackage {
11	/// The actual unilateral exit transaction containing an anchor output and a spendable amount
12	pub exit: TransactionInfo,
13	/// The child transaction used to spend, and thus confirm, the exit anchor output
14	pub child: Option<ChildTransactionInfo>,
15}
16
17impl From<bark::exit::ExitTransactionPackage> for ExitTransactionPackage {
18	fn from(v: bark::exit::ExitTransactionPackage) -> Self {
19		ExitTransactionPackage {
20			exit: v.exit.into(),
21			child: v.child.map(|x| x.into()),
22		}
23	}
24}
25/// Represents a child transaction for an exit transaction package with information about the origin
26/// of the transaction
27#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
28#[cfg_attr(feature = "utoipa", derive(ToSchema))]
29pub struct ChildTransactionInfo {
30	pub info: TransactionInfo,
31	#[serde(default, skip_serializing_if = "Option::is_none")]
32	pub fee_info: Option<FeeInfo>,
33	pub origin: ExitTxOrigin,
34}
35
36impl From<bark::exit::ChildTransactionInfo> for ChildTransactionInfo {
37	fn from(v: bark::exit::ChildTransactionInfo) -> Self {
38		ChildTransactionInfo {
39			info: v.info.into(),
40			fee_info: v.fee_info.map(Into::into),
41			origin: v.origin.into(),
42		}
43	}
44}
45
46/// Contains the data required to bump the fee for a given transaction (including ancestors).
47#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
48#[cfg_attr(feature = "utoipa", derive(ToSchema))]
49pub struct FeeInfo {
50	/// The effective fee rate of the transaction (including unconfirmed CPFP ancestors), in
51	/// sats per kvB. `kvb` matches the unit used elsewhere in `bark-json`
52	/// (e.g. `offboard_feerate_sat_per_kvb`).
53	#[serde(rename = "fee_rate_sat_per_kvb", with = "crate::serde_utils::fee_rate_sat_per_kvb")]
54	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
55	pub fee_rate: FeeRate,
56	/// Sum of the transaction's own fee plus the fee of each of its unconfirmed ancestors.
57	#[serde(rename = "total_fee_sat", with = "bitcoin::amount::serde::as_sat")]
58	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
59	pub total_fee: Amount,
60}
61
62impl From<bark::exit::FeeInfo> for FeeInfo {
63	fn from(v: bark::exit::FeeInfo) -> Self {
64		FeeInfo { fee_rate: v.fee_rate, total_fee: v.total_fee }
65	}
66}