Skip to content

Commit

Permalink
Removed libp2p from sc-authority-discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Sep 28, 2024
1 parent bc2e56e commit 1efb0b2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions substrate/client/network/types/src/rec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

use std::{
borrow::Borrow,
error::Error,
fmt,
time:: Instant,
};
use bytes::Bytes;
Expand Down Expand Up @@ -138,5 +140,43 @@ impl From<libp2p_kad::PeerRecord> for PeerRecord {
PeerRecord {peer, record}


}
}

/// An error during signing of a message.
#[derive(Debug)]
pub struct SigningError {
msg: String,
source: Option<Box<dyn Error + Send + Sync>>,
}

/// An error during encoding of key material.
impl SigningError {
#[cfg(all(not(target_arch = "wasm32")))]
pub(crate) fn new<S: ToString>(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)
}
}

0 comments on commit 1efb0b2

Please sign in to comment.