use serde::{Deserialize, Serialize};
#[allow(dead_code)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HeartbeatMessage {
#[serde(rename = "type")]
pub msg_type: String,
pub nonce: String,
}
#[allow(dead_code)]
impl HeartbeatMessage {
pub fn ping(nonce: String) -> Self {
Self {
msg_type: "elisym_ping".into(),
nonce,
}
}
pub fn pong(nonce: String) -> Self {
Self {
msg_type: "elisym_pong".into(),
nonce,
}
}
pub fn is_ping(&self) -> bool {
self.msg_type == "elisym_ping"
}
pub fn is_pong(&self) -> bool {
self.msg_type == "elisym_pong"
}
}
#[allow(dead_code)]
pub fn random_nonce() -> String {
let mut buf = [0u8; 16];
getrandom::getrandom(&mut buf).expect("failed to generate random bytes");
bs58::encode(&buf).into_string()
}