diff --git a/substrate/client/network/types/src/rec.rs b/substrate/client/network/types/src/rec.rs index 7d9db3ffeabd..5e8685c88c21 100644 --- a/substrate/client/network/types/src/rec.rs +++ b/substrate/client/network/types/src/rec.rs @@ -18,6 +18,8 @@ use std::{ borrow::Borrow, + error::Error, + fmt, time:: Instant, }; use bytes::Bytes; @@ -138,5 +140,43 @@ impl From for PeerRecord { PeerRecord {peer, record} + } +} + +/// An error during signing of a message. +#[derive(Debug)] +pub struct SigningError { + msg: String, + source: Option>, +} + +/// An error during encoding of key material. +impl SigningError { + #[cfg(all(not(target_arch = "wasm32")))] + pub(crate) fn new(msg: S) -> Self { + Self { + msg: msg.to_string(), + source: None, + } + } + + #[cfg(all(not(target_arch = "wasm32")))] + pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self { + Self { + source: Some(Box::new(source)), + ..self + } + } +} + +impl fmt::Display for SigningError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Key signing error: {}", self.msg) + } +} + +impl Error for SigningError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + self.source.as_ref().map(|s| &**s as &dyn Error) } } \ No newline at end of file