nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

commit 2924da88bcea4f86a0e7d23fe25f0ff6ef8b9565
parent 3024e9fba468b3e82bac05fe57121317bb9a7e93
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Mon,  3 Jan 2022 22:03:30 -0500

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.

Diffstat:
Mconfig.toml | 5+++++
Msrc/config.rs | 7++++---
Msrc/info.rs | 21++++++++++-----------
Msrc/main.rs | 4++--
4 files changed, 21 insertions(+), 16 deletions(-)

diff --git 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 @@ -11,9 +11,9 @@ lazy_static! { #[derive(Debug, Serialize, Deserialize)] #[allow(unused)] pub struct Info { + pub relay_url: Option<String>, pub name: Option<String>, - #[serde(rename = "description")] - pub descr: Option<String>, + pub description: Option<String>, pub pubkey: Option<String>, pub email: Option<String>, } @@ -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 @@ -1,7 +1,6 @@ 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"); @@ -9,15 +8,17 @@ const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION") #[allow(unused)] pub struct RelayInfo { #[serde(skip_serializing_if = "Option::is_none")] + pub id: Option<String>, + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option<String>, #[serde(skip_serializing_if = "Option::is_none")] - pub descr: Option<String>, + pub description: Option<String>, #[serde(skip_serializing_if = "Option::is_none")] pub pubkey: Option<String>, #[serde(skip_serializing_if = "Option::is_none")] pub email: Option<String>, #[serde(skip_serializing_if = "Option::is_none")] - pub supported_nips: Option<Vec<String>>, + pub supported_nips: Option<Vec<i64>>, #[serde(skip_serializing_if = "Option::is_none")] pub software: Option<String>, #[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<Value> = 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 @@ -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