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.
This commit is contained in:
Greg Heartsfield 2022-01-03 22:03:30 -05:00
parent 3024e9fba4
commit 2924da88bc
4 changed files with 21 additions and 16 deletions

View File

@ -1,10 +1,15 @@
# Nostr-rs-relay configuration # Nostr-rs-relay configuration
[info] [info]
# The advertised URL for the Nostr websocket.
relay_url = "wss://nostr.example.com/"
# Relay information for clients. Put your unique server name here. # Relay information for clients. Put your unique server name here.
name = "nostr-rs-relay" name = "nostr-rs-relay"
# Description # Description
description = "A newly created nostr-rs-relay.\n\nCustomize this with your own info." description = "A newly created nostr-rs-relay.\n\nCustomize this with your own info."
# Administrative contact pubkey # Administrative contact pubkey
#pubkey = "0c2d168a4ae8ca58c9f1ab237b5df682599c6c7ab74307ea8b05684b60405d41" #pubkey = "0c2d168a4ae8ca58c9f1ab237b5df682599c6c7ab74307ea8b05684b60405d41"

View File

@ -11,9 +11,9 @@ lazy_static! {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[allow(unused)] #[allow(unused)]
pub struct Info { pub struct Info {
pub relay_url: Option<String>,
pub name: Option<String>, pub name: Option<String>,
#[serde(rename = "description")] pub description: Option<String>,
pub descr: Option<String>,
pub pubkey: Option<String>, pub pubkey: Option<String>,
pub email: Option<String>, pub email: Option<String>,
} }
@ -101,8 +101,9 @@ impl Default for Settings {
fn default() -> Self { fn default() -> Self {
Settings { Settings {
info: Info { info: Info {
relay_url: None,
name: Some("Unnamed nostr-rs-relay".to_owned()), name: Some("Unnamed nostr-rs-relay".to_owned()),
descr: None, description: None,
pubkey: None, pubkey: None,
email: None, email: None,
}, },

View File

@ -1,23 +1,24 @@
use crate::config; use crate::config;
/// Relay Info /// Relay Info
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::value::Value;
const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[allow(unused)] #[allow(unused)]
pub struct RelayInfo { pub struct RelayInfo {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>, pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub descr: Option<String>, pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub pubkey: Option<String>, pub pubkey: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>, pub email: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[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")] #[serde(skip_serializing_if = "Option::is_none")]
pub software: Option<String>, pub software: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -27,11 +28,12 @@ pub struct RelayInfo {
impl Default for RelayInfo { impl Default for RelayInfo {
fn default() -> Self { fn default() -> Self {
RelayInfo { RelayInfo {
id: None,
name: None, name: None,
descr: None, description: None,
pubkey: None, pubkey: None,
email: 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()), software: Some("https://git.sr.ht/~gheartsfield/nostr-rs-relay".to_owned()),
version: CARGO_PKG_VERSION.map(|x| x.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 // get a default RelayInfo
let mut r = RelayInfo::default(); let mut r = RelayInfo::default();
// update fields from Info, if present // update fields from Info, if present
r.id = info.relay_url.clone();
r.name = info.name.clone(); r.name = info.name.clone();
r.descr = info.descr.clone(); r.description = info.description.clone();
r.pubkey = info.pubkey.clone(); r.pubkey = info.pubkey.clone();
r.email = info.email.clone(); r.email = info.email.clone();
r.to_json() r.to_json()
@ -52,10 +55,6 @@ pub fn relay_info_json(info: &config::Info) -> String {
impl RelayInfo { impl RelayInfo {
pub fn to_json(self) -> String { pub fn to_json(self) -> String {
// create the info ARRAY serde_json::to_string_pretty(&self).unwrap()
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()
} }
} }

View File

@ -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.", "Please use a Nostr client to connect.",
))); )))
} }
(_, _) => { (_, _) => {
//handle any other url //handle any other url