use std::{convert::Infallible, fmt::Display, str::FromStr};
use async_trait::async_trait;
use nanorpc::nanorpc_derive;
use serde::{Deserialize, Serialize};
use smol_str::SmolStr;
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash, Serialize, Deserialize)]
pub struct Address(SmolStr);
impl<T: AsRef<str>> From<T> for Address {
fn from(t: T) -> Self {
Self(t.into())
}
}
impl Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl FromStr for Address {
type Err = Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.into()))
}
}
#[nanorpc_derive]
#[async_trait]
pub trait ControlProtocol {
async fn __mn_get_swarm_id(&self) -> String;
async fn __mn_get_random_peers(&self) -> Vec<Address>;
async fn __mn_advertise_peer(&self, peer: Address) -> bool;
}