Skip to main content

bark/exit/models/
error.rs

1use bitcoin::{Amount, Txid};
2use bitcoin::address::FromScriptError;
3use thiserror::Error;
4
5use ark::VtxoId;
6use ark::vtxo::VtxoStandardnessError;
7use bitcoin_ext::BlockHeight;
8
9use crate::chain::BroadcastError;
10use crate::exit::models::ExitStateKind;
11use crate::exit::models::states::ExitTxStatus;
12
13#[derive(Clone, Debug, Error, PartialEq, Eq)]
14pub enum ExitError {
15	#[error("Transaction Retrieval Failure: Unable to retrieve ancestral data for TX {txid}: {error}")]
16	AncestorRetrievalFailure {
17		txid: Txid,
18		error: String
19	},
20
21	#[error("Block Retrieval Failure: Unable to retrieve a block at height {height}: {error}")]
22	BlockRetrievalFailure { height: BlockHeight, error: String },
23
24	#[error("Cannot Cancel Exit: The exit for VTXO {vtxo} can no longer be canceled (state: {state})")]
25	CannotCancelExit { vtxo: VtxoId, state: ExitStateKind },
26
27	#[error("Claim Missing Inputs: No inputs given to claim")]
28	ClaimMissingInputs,
29
30	#[error("Claim Fee Exceeds Output: Cost to claim exits was {needed}, but the total output was {output}")]
31	ClaimFeeExceedsOutput {
32		needed: Amount,
33		output: Amount,
34	},
35
36	#[error("Claim Missing Signable Clause: Couldn't find a signable clause for VTXO {vtxo}")]
37	ClaimMissingSignableClause { vtxo: VtxoId },
38
39	#[error("Claim Signing Error: Unable to sign claim: {error}")]
40	ClaimSigningError { error: String },
41
42	#[error("Cyclic Exit Transactions Error: The exit transactions for VTXO {vtxo} are cyclic")]
43	CyclicExitTransactions {
44		vtxo: VtxoId
45	},
46
47	#[error("Database Store Failure: Unable to update exit VTXO {vtxo_id} in the database: {error}")]
48	DatabaseVtxoStoreFailure {
49		vtxo_id: VtxoId,
50		error: String
51	},
52
53	#[error("Database Retrieval Failure: Unable to get child tx: {error}")]
54	DatabaseChildRetrievalFailure { error: String },
55
56	#[error("Database Store Failure: Unable to store child tx: {error}")]
57	DatabaseChildStoreFailure { error: String },
58
59	#[error("Dust Limit Error: The dust limit for a VTXO is {dust} but vtxo {vtxo} is only {amount}")]
60	DustLimit {
61		vtxo: VtxoId,
62		amount: Amount,
63		dust: Amount
64	},
65
66	#[error("Exit Package Broadcast Failure: Unable to broadcast exit transaction package {txid}: {error}")]
67	ExitPackageBroadcastFailure {
68		txid: Txid,
69		error: BroadcastError,
70	},
71
72	#[error("Exit Package Finalize Failure: Unable to create exit transaction package: {error}")]
73	ExitPackageFinalizeFailure { error: String },
74
75	#[error("Exit Package Store Failure: Unable to store exit transaction package {txid}: {error}")]
76	ExitPackageStoreFailure {
77		txid: Txid,
78		error: String
79	},
80
81	#[error("Exit Tx Already Broadcast: Cannot cancel the exit for VTXO {vtxo}, its final exit tx {txid} has already been broadcast")]
82	ExitTxAlreadyBroadcast { vtxo: VtxoId, txid: Txid },
83
84	#[error("Insufficient Confirmed Funds: {needed} is needed but only {available} is available")]
85	InsufficientConfirmedFunds {
86		needed: Amount,
87		available: Amount
88	},
89
90	#[error("Internal Error: An unexpected problem occurred, {error}")]
91	InternalError { error: String },
92
93	#[error("Invalid Exit Transaction Status: Exit tx {txid} has an invalid status ({status}): {error}")]
94	InvalidExitTransactionStatus {
95		txid: Txid,
96		status: ExitTxStatus,
97		error: String
98	},
99
100	#[error("Invalid Locktime ({tip}): {error}")]
101	InvalidLocktime { tip: BlockHeight, error: String },
102
103	#[error("Invalid Wallet State: {error}")]
104	InvalidWalletState { error: String },
105
106	#[error("Missing Anchor Output: Malformed exit tx {txid}")]
107	MissingAnchorOutput { txid: Txid },
108
109	#[error("Missing VTXO Transaction: Couldn't find exit tx {txid}")]
110	MissingExitTransaction { txid: Txid },
111
112	#[error("Non-Standard VTXO {vtxo}: exit chain is not relayable: {error}")]
113	NonStandardVtxo {
114		vtxo: VtxoId,
115		error: VtxoStandardnessError,
116	},
117
118	#[error("Movement Registration Failure: {error}")]
119	MovementRegistrationFailure { error: String },
120
121	#[error("Not Exiting: VTXO {vtxo} has no unilateral exit")]
122	NotExiting { vtxo: VtxoId },
123
124	#[error("Tip Retrieval Failure: Unable to retrieve the blockchain tip height: {error}")]
125	TipRetrievalFailure { error: String },
126
127	#[error("Transaction Retrieval Failure: Unable to check the status of TX {txid}: {error}")]
128	TransactionRetrievalFailure { txid: Txid, error: String },
129
130	#[error("VTXO Not Spendable Error: Attempted to claim a VTXO which is not in a spendable state: {vtxo}")]
131	VtxoNotClaimable { vtxo: VtxoId },
132
133	#[error("Unknown VTXO: {vtxo} is not known to this wallet")]
134	UnknownVtxo { vtxo: VtxoId },
135
136	#[error("VTXO Already Exited: {vtxo} has already completed its unilateral exit")]
137	VtxoAlreadyExited { vtxo: VtxoId },
138
139	#[error("VTXO Already Spent: {vtxo} has already been spent and can no longer be exited")]
140	VtxoAlreadySpent { vtxo: VtxoId },
141
142	#[error("VTXO ScriptPubKey Invalid: {error}")]
143	VtxoScriptPubKeyInvalid { error: String },
144}
145
146impl From<FromScriptError> for ExitError {
147	fn from(e: FromScriptError) -> Self {
148		ExitError::VtxoScriptPubKeyInvalid { error: e.to_string() }
149	}
150}