xmr-btc-swap/swap/src/libp2p_ext.rs
Thomas Eizinger ec4234fbb9
Merge --seller-addr and --seller-peer-id into --seller parameter
This simplifies the CLI's interface.
2021-07-06 14:51:08 +10:00

16 lines
385 B
Rust

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,
}
}
}