use arch_program::program_error::ProgramError;
use satellite_bitcoin::generic::fixed_set::FixedSetError;
use satellite_lang::error_code;
#[derive(PartialEq, Eq)]
#[error_code(offset = 300)]
pub enum StateShardError {
#[msg("Not enough rune in shards")]
NotEnoughRuneInShards,
#[msg("Output edict is not in transaction")]
OutputEdictIsNotInTransaction,
#[msg("Math error in btc amount")]
MathErrorInBalanceAmountAcrossShards,
#[msg("Too many runes in utxo")]
TooManyRunesInUtxo,
#[msg("Rune amount addition overflow")]
RuneAmountAdditionOverflow,
#[msg("Shards are full of btc utxos")]
ShardsAreFullOfBtcUtxos,
#[msg("Removing more runes than are present in the shards")]
RemovingMoreRunesThanPresentInShards,
#[msg("Missing pointer in runestone")]
MissingPointerInRunestone,
#[msg("Runestone pointer is not in transaction")]
RunestonePointerIsNotInTransaction,
#[msg("Duplicate shard index in selection")]
DuplicateShardSelection,
#[msg("Shard index out of bounds")]
OutOfBounds,
#[msg("Too many shards selected")]
TooManyShardsSelected,
#[msg("Too many rune UTXOs for the selected shards")]
ExcessRuneUtxos,
#[msg("Not enough rune UTXOs for the selected shards")]
NotEnoughRuneUtxos,
}
impl From<FixedSetError> for StateShardError {
fn from(error: FixedSetError) -> Self {
match error {
FixedSetError::Full => StateShardError::TooManyRunesInUtxo,
FixedSetError::Duplicate => {
panic!("unreachable. we couldn't have a duplicate rune input")
}
}
}
}
impl From<StateShardError> for ProgramError {
fn from(e: StateShardError) -> Self {
satellite_lang::error::Error::from(e).into()
}
}
pub type Result<T> = core::result::Result<T, StateShardError>;