1use std::collections::HashSet;
2use std::fmt;
3
4use bitcoin::{OutPoint, Txid};
5
6use bitcoin_ext::BlockHeight;
7use crate::primitives::BlockRef;
8
9#[cfg(feature = "utoipa")]
10use utoipa::ToSchema;
11
12#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
13#[cfg_attr(feature = "utoipa", derive(ToSchema))]
14pub struct ExitTx {
15 #[cfg_attr(feature = "utoipa", schema(value_type = String))]
16 pub txid: Txid,
17 pub status: ExitTxStatus,
18}
19
20#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
21#[cfg_attr(feature = "utoipa", derive(ToSchema))]
22#[serde(tag = "type", rename_all = "kebab-case")]
23pub enum ExitTxStatus {
24 #[default]
25 VerifyInputs,
26 AwaitingInputConfirmation {
27 #[cfg_attr(feature = "utoipa", schema(value_type = Vec<String>))]
28 txids: HashSet<Txid>
29 },
30 AwaitingCpfpBroadcast,
31 AwaitingConfirmation {
32 #[cfg_attr(feature = "utoipa", schema(value_type = String))]
33 child_txid: Txid,
34 origin: ExitTxOrigin,
35 },
36 Confirmed {
37 #[cfg_attr(feature = "utoipa", schema(value_type = String))]
38 child_txid: Txid,
39 block: BlockRef,
40 origin: ExitTxOrigin,
41 },
42}
43
44impl fmt::Display for ExitTxStatus {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 fmt::Debug::fmt(self, f)
47 }
48}
49
50impl From<bark::exit::ExitTxStatus> for ExitTxStatus {
51 fn from(v: bark::exit::ExitTxStatus) -> Self {
52 match v {
53 bark::exit::ExitTxStatus::VerifyInputs => {
54 ExitTxStatus::VerifyInputs
55 },
56 bark::exit::ExitTxStatus::AwaitingInputConfirmation { txids } => {
57 ExitTxStatus::AwaitingInputConfirmation { txids }
58 },
59 bark::exit::ExitTxStatus::AwaitingCpfpBroadcast => {
60 ExitTxStatus::AwaitingCpfpBroadcast
61 },
62 bark::exit::ExitTxStatus::AwaitingConfirmation { child_txid, origin } => {
63 ExitTxStatus::AwaitingConfirmation { child_txid, origin: origin.into() }
64 },
65 bark::exit::ExitTxStatus::Confirmed { child_txid, block, origin } => {
66 ExitTxStatus::Confirmed { child_txid, block: block.into(), origin: origin.into() }
67 },
68 }
69 }
70}
71
72#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
73#[cfg_attr(feature = "utoipa", derive(ToSchema))]
74#[serde(tag = "type", rename_all = "kebab-case")]
75pub enum ExitTxOrigin {
76 Wallet {
77 confirmed_in: Option<BlockRef>
78 },
79 Mempool,
80 Block {
81 confirmed_in: BlockRef
82 },
83}
84
85impl fmt::Display for ExitTxOrigin {
86 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87 fmt::Debug::fmt(self, f)
88 }
89}
90
91impl From<bark::exit::ExitTxOrigin> for ExitTxOrigin {
92 fn from(v: bark::exit::ExitTxOrigin) -> Self {
93 match v {
94 bark::exit::ExitTxOrigin::Wallet { confirmed_in } => {
95 ExitTxOrigin::Wallet { confirmed_in: confirmed_in.map(Into::into) }
96 },
97 bark::exit::ExitTxOrigin::Mempool => ExitTxOrigin::Mempool,
98 bark::exit::ExitTxOrigin::Block { confirmed_in } => {
99 ExitTxOrigin::Block { confirmed_in: confirmed_in.into() }
100 },
101 }
102 }
103}
104
105#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
106#[cfg_attr(feature = "utoipa", derive(ToSchema))]
107pub struct ExitStartState {
108 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
109 pub tip_height: BlockHeight,
110}
111
112#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
113#[cfg_attr(feature = "utoipa", derive(ToSchema))]
114pub struct ExitProcessingState {
115 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
116 pub tip_height: BlockHeight,
117 pub transactions: Vec<ExitTx>,
118}
119
120#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
121#[cfg_attr(feature = "utoipa", derive(ToSchema))]
122pub struct ExitAwaitingDeltaState {
123 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
124 pub tip_height: BlockHeight,
125 pub confirmed_block: BlockRef,
126 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
127 pub claimable_height: BlockHeight,
128}
129
130#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
131#[cfg_attr(feature = "utoipa", derive(ToSchema))]
132pub struct ExitClaimableState {
133 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
134 pub tip_height: BlockHeight,
135 pub claimable_since: BlockRef,
136 pub last_scanned_block: Option<BlockRef>,
137}
138
139#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
140#[cfg_attr(feature = "utoipa", derive(ToSchema))]
141pub struct ExitClaimInProgressState {
142 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
143 pub tip_height: BlockHeight,
144 pub claimable_since: BlockRef,
145 #[cfg_attr(feature = "utoipa", schema(value_type = String))]
146 pub claim_txid: Txid,
147}
148
149#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
150#[cfg_attr(feature = "utoipa", derive(ToSchema))]
151pub struct ExitClaimedState {
152 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
153 pub tip_height: BlockHeight,
154 #[cfg_attr(feature = "utoipa", schema(value_type = String))]
155 pub txid: Txid,
156 pub block: BlockRef,
157}
158
159#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
161#[cfg_attr(feature = "utoipa", derive(ToSchema))]
162pub struct ExitVtxoAlreadySpentState {
163 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
164 pub tip_height: BlockHeight,
165}
166
167#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
169#[cfg_attr(feature = "utoipa", derive(ToSchema))]
170pub struct ExitVtxoSweptState {
171 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
172 pub tip_height: BlockHeight,
173 #[cfg_attr(feature = "utoipa", schema(value_type = Vec<String>))]
174 pub spent_inputs: Vec<OutPoint>,
175}
176
177#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
179#[cfg_attr(feature = "utoipa", derive(ToSchema))]
180pub struct ExitCanceledState {
181 #[cfg_attr(feature = "utoipa", schema(value_type = u32))]
182 pub tip_height: BlockHeight,
183}