use sp_core::ed25519::Public;
use sp_version::RuntimeVersion;
use std::error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("State unavailable at block {0}")]
StateUnavailable(String),
#[error("I/O terminated unexpectedly.")]
IoTerminated,
#[error("Missing intermediate.")]
NoIntermediate,
#[error("Invalid intermediate.")]
InvalidIntermediate,
#[error("Timer error: {0}")]
FaultyTimer(#[from] std::io::Error),
#[error("InherentData error: {0}")]
InherentData(#[from] sp_inherents::Error),
#[error("Unable to create block proposal.")]
CannotPropose,
#[error("Message signature {0:?} by {1:?} is invalid.")]
InvalidSignature(Vec<u8>, Vec<u8>),
#[error("Current state of blockchain has invalid authorities set")]
InvalidAuthoritiesSet,
#[error("Message sender {0:?} is not a valid authority")]
InvalidAuthority(Public),
#[error(
"Authoring for current \
runtime is not supported. Native ({native}) cannot author for on-chain ({on_chain})."
)]
IncompatibleAuthoringRuntime { native: RuntimeVersion, on_chain: RuntimeVersion },
#[error("Authoring for current runtime is not supported since it has no version.")]
RuntimeVersionMissing,
#[error("Authoring in current build is not supported since it has no runtime.")]
NativeRuntimeMissing,
#[error("Invalid justification.")]
InvalidJustification,
#[error(transparent)]
Other(#[from] Box<dyn error::Error + Sync + Send + 'static>),
#[error("Import failed: {0}")]
ClientImport(String),
#[error("Chain lookup failed: {0}")]
ChainLookup(String),
#[error("Failed to sign using key: {0:?}. Reason: {1}")]
CannotSign(Vec<u8>, String),
}
impl From<Public> for Error {
fn from(p: Public) -> Self {
Self::InvalidAuthority(p)
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Self::StateUnavailable(s)
}
}