From 2924da88bcea4f86a0e7d23fe25f0ff6ef8b9565 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Mon, 3 Jan 2022 22:03:30 -0500 Subject: [PATCH] feat: incorporated improvements from NIP-11 discussion Change descr to description. Add `id` for websocket URL. Use integers for supported NIPs instead of strings. Top-level is object, instead of the array before. --- config.toml | 5 +++++ src/config.rs | 7 ++++--- src/info.rs | 21 ++++++++++----------- src/main.rs | 4 ++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/config.toml b/config.toml index 3b55435..280b64d 100644 --- a/config.toml +++ b/config.toml @@ -1,10 +1,15 @@ # Nostr-rs-relay configuration [info] +# The advertised URL for the Nostr websocket. +relay_url = "wss://nostr.example.com/" + # Relay information for clients. Put your unique server name here. name = "nostr-rs-relay" + # Description description = "A newly created nostr-rs-relay.\n\nCustomize this with your own info." + # Administrative contact pubkey #pubkey = "0c2d168a4ae8ca58c9f1ab237b5df682599c6c7ab74307ea8b05684b60405d41" diff --git a/src/config.rs b/src/config.rs index d74fa02..00acd83 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,9 +11,9 @@ lazy_static! { #[derive(Debug, Serialize, Deserialize)] #[allow(unused)] pub struct Info { + pub relay_url: Option, pub name: Option, - #[serde(rename = "description")] - pub descr: Option, + pub description: Option, pub pubkey: Option, pub email: Option, } @@ -101,8 +101,9 @@ impl Default for Settings { fn default() -> Self { Settings { info: Info { + relay_url: None, name: Some("Unnamed nostr-rs-relay".to_owned()), - descr: None, + description: None, pubkey: None, email: None, }, diff --git a/src/info.rs b/src/info.rs index 6e6a0e0..718150b 100644 --- a/src/info.rs +++ b/src/info.rs @@ -1,23 +1,24 @@ use crate::config; /// Relay Info use serde::{Deserialize, Serialize}; -use serde_json::value::Value; const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); #[derive(Debug, Serialize, Deserialize)] #[allow(unused)] pub struct RelayInfo { + #[serde(skip_serializing_if = "Option::is_none")] + pub id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub descr: Option, + pub description: Option, #[serde(skip_serializing_if = "Option::is_none")] pub pubkey: Option, #[serde(skip_serializing_if = "Option::is_none")] pub email: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub supported_nips: Option>, + pub supported_nips: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub software: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -27,11 +28,12 @@ pub struct RelayInfo { impl Default for RelayInfo { fn default() -> Self { RelayInfo { + id: None, name: None, - descr: None, + description: None, pubkey: None, email: None, - supported_nips: Some(vec!["NIP-01".to_owned()]), + supported_nips: Some(vec![1]), software: Some("https://git.sr.ht/~gheartsfield/nostr-rs-relay".to_owned()), version: CARGO_PKG_VERSION.map(|x| x.to_owned()), } @@ -43,8 +45,9 @@ pub fn relay_info_json(info: &config::Info) -> String { // get a default RelayInfo let mut r = RelayInfo::default(); // update fields from Info, if present + r.id = info.relay_url.clone(); r.name = info.name.clone(); - r.descr = info.descr.clone(); + r.description = info.description.clone(); r.pubkey = info.pubkey.clone(); r.email = info.email.clone(); r.to_json() @@ -52,10 +55,6 @@ pub fn relay_info_json(info: &config::Info) -> String { impl RelayInfo { pub fn to_json(self) -> String { - // create the info ARRAY - let mut info_arr: Vec = vec![]; - info_arr.push(Value::String("NOSTR_SERVER_INFO".to_owned())); - info_arr.push(serde_json::to_value(&self).unwrap()); - serde_json::to_string_pretty(&info_arr).unwrap() + serde_json::to_string_pretty(&self).unwrap() } } diff --git a/src/main.rs b/src/main.rs index a2d0252..431764b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,9 +119,9 @@ async fn handle_web_request( } } } - return Ok(Response::new(Body::from( + Ok(Response::new(Body::from( "Please use a Nostr client to connect.", - ))); + ))) } (_, _) => { //handle any other url