use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionPriority as Priority, UnknownTransaction,
};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error, strum::AsRefStr)]
#[allow(missing_docs)]
pub enum Error {
#[error("Unknown transaction validity: {0:?}")]
UnknownTransaction(UnknownTransaction),
#[error("Invalid transaction validity: {0:?}")]
InvalidTransaction(InvalidTransaction),
#[error("Transaction does not provide any tags, so the pool can't identify it")]
NoTagsProvided,
#[error("Transaction temporarily Banned")]
TemporarilyBanned,
#[error("[{0:?}] Already imported")]
AlreadyImported(Box<dyn std::any::Any + Send + Sync>),
#[error("Too low priority ({} > {})", old, new)]
TooLowPriority {
old: Priority,
new: Priority,
},
#[error("Transaction with cyclic dependency")]
CycleDetected,
#[error("Transaction couldn't enter the pool because of the limit")]
ImmediatelyDropped,
#[error("Transaction cannot be propagated and the local node does not author blocks")]
Unactionable,
#[error("{0}")]
InvalidBlockId(String),
#[error("The pool is not accepting future transactions")]
RejectedFutureTransaction,
}
impl Error {
pub fn is_retriable(&self) -> bool {
match self {
Error::TemporarilyBanned |
Error::ImmediatelyDropped |
Error::InvalidBlockId(_) |
Error::RejectedFutureTransaction => {
true
}
_ => false
}
}
}
pub trait IntoPoolError: std::error::Error + Send + Sized + Sync {
fn into_pool_error(self) -> std::result::Result<Error, Self> {
Err(self)
}
}
impl IntoPoolError for Error {
fn into_pool_error(self) -> std::result::Result<Error, Self> {
Ok(self)
}
}
pub trait IntoMetricsLabel {
fn label(&self) -> String;
}
impl IntoMetricsLabel for Error {
fn label(&self) -> String {
self.as_ref().to_string()
}
}