You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wow-btc-swap/swap/src/libp2p_ext.rs

16 lines
385 B

use libp2p::multiaddr::Protocol;
use libp2p::{Multiaddr, PeerId};
pub trait MultiAddrExt {
fn extract_peer_id(&self) -> Option<PeerId>;
}
impl MultiAddrExt for Multiaddr {
fn extract_peer_id(&self) -> Option<PeerId> {
match self.iter().last()? {
Protocol::P2p(multihash) => PeerId::from_multihash(multihash).ok(),
_ => None,
}
}
}