2022-02-12 10:29:31 -05:00
|
|
|
//! Relay metadata using NIP-11
|
2022-01-03 18:42:24 -05:00
|
|
|
/// Relay Info
|
2022-02-12 10:29:31 -05:00
|
|
|
use crate::config;
|
2022-01-03 18:42:24 -05:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-02-12 10:29:25 -05:00
|
|
|
pub const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
2022-01-03 18:42:24 -05:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
#[allow(unused)]
|
|
|
|
pub struct RelayInfo {
|
2022-01-03 22:03:30 -05:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub id: Option<String>,
|
2022-01-03 18:42:24 -05:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub name: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2022-01-03 22:03:30 -05:00
|
|
|
pub description: Option<String>,
|
2022-01-03 18:42:24 -05:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub pubkey: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2022-01-16 09:34:19 -05:00
|
|
|
pub contact: Option<String>,
|
2022-01-03 18:42:24 -05:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2022-01-03 22:03:30 -05:00
|
|
|
pub supported_nips: Option<Vec<i64>>,
|
2022-01-03 18:42:24 -05:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub software: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub version: Option<String>,
|
|
|
|
}
|
|
|
|
|
2022-01-05 10:10:44 -05:00
|
|
|
/// Convert an Info configuration into public Relay Info
|
|
|
|
impl From<config::Info> for RelayInfo {
|
|
|
|
fn from(i: config::Info) -> Self {
|
2022-01-03 18:42:24 -05:00
|
|
|
RelayInfo {
|
2022-01-05 10:10:44 -05:00
|
|
|
id: i.relay_url,
|
|
|
|
name: i.name,
|
|
|
|
description: i.description,
|
|
|
|
pubkey: i.pubkey,
|
2022-01-16 09:34:19 -05:00
|
|
|
contact: i.contact,
|
2023-02-01 19:09:27 -05:00
|
|
|
supported_nips: Some(vec![1, 2, 9, 11, 12, 15, 16, 20, 22, 33]),
|
2022-01-03 18:42:24 -05:00
|
|
|
software: Some("https://git.sr.ht/~gheartsfield/nostr-rs-relay".to_owned()),
|
2023-01-22 10:49:49 -05:00
|
|
|
version: CARGO_PKG_VERSION.map(std::borrow::ToOwned::to_owned),
|
2022-01-03 18:42:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|