use celestia_types::{hash::Hash, state::ErrorCode};
use k256::ecdsa::signature::Error as SignatureError;
use tonic::Status;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
TonicError(Box<Status>),
#[cfg(not(target_arch = "wasm32"))]
#[error("Transport: {0}")]
TransportError(#[from] tonic::transport::Error),
#[error(transparent)]
TendermintError(#[from] tendermint::Error),
#[error(transparent)]
CelestiaTypesError(#[from] celestia_types::Error),
#[error(transparent)]
TendermintProtoError(#[from] tendermint_proto::Error),
#[error("Failed to parse response")]
FailedToParseResponse,
#[error("Unexpected response type")]
UnexpectedResponseType(String),
#[error("Attempted to submit blob transaction with empty blob list")]
TxEmptyBlobList,
#[error("Broadcasting transaction {0} failed; code: {1}, error: {2}")]
TxBroadcastFailed(Hash, ErrorCode, String),
#[error("Transaction {0} execution failed; code: {1}, error: {2}")]
TxExecutionFailed(Hash, ErrorCode, String),
#[error("Transaction {0} was evicted from the mempool")]
TxEvicted(Hash),
#[error("Transaction {0} wasn't found, it was likely rejected")]
TxNotFound(Hash),
#[error("Provided public key differs from one associated with account")]
PublicKeyMismatch,
#[error(transparent)]
SigningError(#[from] SignatureError),
}
impl From<Status> for Error {
fn from(value: Status) -> Self {
Error::TonicError(Box::new(value))
}
}
#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
impl From<Error> for wasm_bindgen::JsValue {
fn from(error: Error) -> wasm_bindgen::JsValue {
error.to_string().into()
}
}