use crate::tx_builder::error::TxBuilderError;
use cosmrs::proto::prost;
use std::num::NonZeroU32;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum CosmosClientError {
#[error("Tendermint Error: {0}")]
Tendermint(#[from] tendermint_rpc::Error),
#[error("Cosmrs tendermint Error: {0}")]
Cosmrs(#[from] cosmrs::tendermint::Error),
#[error("Eyre Error: {0}")]
Eyre(#[from] eyre::Report),
#[error("Prost Error: {0}")]
Prost(#[from] prost::DecodeError),
#[error("SerdeJson Error: {0}")]
SerdeJson(#[from] serde_json::Error),
#[error("Tokio Join Error: {0}")]
TokioJoin(#[from] tokio::task::JoinError),
#[error("Cosmwasm Error: {0}")]
CosmwasmError(#[from] cosmwasm_std::StdError),
#[error("TxBuilder Error: {0}")]
TxBuilder(#[from] TxBuilderError),
#[error("Account with address not found: {0}")]
AccountNotFound(String),
#[error("Error while broadcasting transaction: {0}")]
BroadcastTx(String),
#[error("Insufficient gas: GasWanted {0} - GasUsed {1}")]
InsufficientGas(i64, i64),
#[error("Insufficient fee: {0}")]
InsufficientFee(String),
#[error("Failed to find bolt event attribute")]
FailedToFindBoltEventAttribute,
#[error("Failed to parse bold event value")]
FailedToParseBoltEventValue,
#[error("No data from contract query returned. Logs: {0}")]
NoDataFromContractQuery(String),
#[error("No gas info returned from simulation")]
NoGasInfo,
#[error("Unable to connect to Cosmos RPC")]
ConnectionError,
#[error("Gas simulation error with code {code}: {log}")]
GasSimulationError { code: NonZeroU32, log: String },
}
impl CosmosClientError {
pub fn no_data_returned_from_contract(&self) -> bool {
matches!(self, Self::NoDataFromContractQuery(_))
}
}