bark/exit/models/
error.rs

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