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

40 lines
1015 B
Rust

use libp2p::rendezvous::Namespace;
use std::fmt;
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum XmrBtcNamespace {
Mainnet,
Testnet,
}
const MAINNET: &str = "xmr-btc-swap-mainnet";
const TESTNET: &str = "xmr-btc-swap-testnet";
impl fmt::Display for XmrBtcNamespace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
XmrBtcNamespace::Mainnet => write!(f, "{}", MAINNET),
XmrBtcNamespace::Testnet => write!(f, "{}", TESTNET),
}
}
}
impl From<XmrBtcNamespace> for Namespace {
fn from(namespace: XmrBtcNamespace) -> Self {
match namespace {
XmrBtcNamespace::Mainnet => Namespace::from_static(MAINNET),
XmrBtcNamespace::Testnet => Namespace::from_static(TESTNET),
}
}
}
impl XmrBtcNamespace {
pub fn from_is_testnet(testnet: bool) -> XmrBtcNamespace {
if testnet {
XmrBtcNamespace::Testnet
} else {
XmrBtcNamespace::Mainnet
}
}
}