use pallet_contracts::ContractExecResult;
use std::fmt;
#[derive(Debug, thiserror::Error)]
pub enum Error<DispatchError: fmt::Debug + fmt::Display> {
#[error("Contract not found: {0}")]
ContractNotFound(String),
#[error("Instantiate dry-run error: {0}")]
InstantiateDryRun(DryRunError<DispatchError>),
#[error("Instantiate extrinsic error: {0}")]
InstantiateExtrinsic(DispatchError),
#[error("Upload dry-run error: {0}")]
UploadDryRun(DispatchError),
#[error("Upload extrinsic error: {0}")]
UploadExtrinsic(DispatchError),
#[error("Call dry-run error: {0}")]
CallDryRun(DryRunError<DispatchError>),
#[error("Call extrinsic error: {0}")]
CallExtrinsic(DispatchError),
#[error("Remove code extrinsic error: {0}")]
RemoveCodeExtrinsic(DispatchError),
#[error("Fetching account Balance error: {0}")]
Balance(String),
#[error("Decoding failed: {0}")]
Decoding(String),
}
#[derive(Debug)]
pub struct DryRunError<DispatchError: fmt::Display + fmt::Debug> {
pub debug_message: String,
pub error: DispatchError,
}
impl<DispatchError> fmt::Display for DryRunError<DispatchError>
where
DispatchError: fmt::Display + fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
<Self as fmt::Debug>::fmt(self, f)
}
}
#[derive(Debug, thiserror::Error)]
pub struct SandboxErr {
msg: String,
}
impl SandboxErr {
#[allow(dead_code)]
pub fn new(msg: String) -> Self {
Self { msg }
}
}
impl From<String> for SandboxErr {
fn from(msg: String) -> Self {
Self { msg }
}
}
impl fmt::Display for SandboxErr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SandboxErr: {}", self.msg)
}
}
impl<Balance> From<ContractExecResult<Balance, ()>> for SandboxErr {
fn from(_value: ContractExecResult<Balance, ()>) -> Self {
Self {
msg: "ContractExecResult".to_string(),
}
}
}