diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-01 14:31:32 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-01 15:22:38 +0000 |
| commit | d2ac69816567f092fe0d4661723bc43778cb481b (patch) | |
| tree | e8b51b61a6a7b0ab1a214adebe4e237143b01f0b /src/http/nip11.rs | |
| parent | 7a78815e29b01c83f3d0ec195ba717a2eba8cd37 (diff) | |
fix cargo clippy and fmt warnings
Diffstat (limited to 'src/http/nip11.rs')
| -rw-r--r-- | src/http/nip11.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/http/nip11.rs b/src/http/nip11.rs index a93ee5f..593ef9a 100644 --- a/src/http/nip11.rs +++ b/src/http/nip11.rs | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | use crate::config::Config; | ||
| 1 | /// NIP-11 Relay Information Document | 2 | /// NIP-11 Relay Information Document |
| 2 | /// | 3 | /// |
| 3 | /// Implements NIP-11 relay information endpoint with GRASP-01 extensions. | 4 | /// Implements NIP-11 relay information endpoint with GRASP-01 extensions. |
| 4 | /// See: https://github.com/nostr-protocol/nips/blob/master/11.md | 5 | /// See: https://github.com/nostr-protocol/nips/blob/master/11.md |
| 5 | |||
| 6 | use serde::{Deserialize, Serialize}; | 6 | use serde::{Deserialize, Serialize}; |
| 7 | use crate::config::Config; | ||
| 8 | 7 | ||
| 9 | /// NIP-11 Relay Information Document | 8 | /// NIP-11 Relay Information Document |
| 10 | /// | 9 | /// |
| @@ -14,37 +13,36 @@ use crate::config::Config; | |||
| 14 | pub struct RelayInformationDocument { | 13 | pub struct RelayInformationDocument { |
| 15 | /// Relay name | 14 | /// Relay name |
| 16 | pub name: String, | 15 | pub name: String, |
| 17 | 16 | ||
| 18 | /// Relay description | 17 | /// Relay description |
| 19 | pub description: String, | 18 | pub description: String, |
| 20 | 19 | ||
| 21 | /// Relay owner's public key (hex format) | 20 | /// Relay owner's public key (hex format) |
| 22 | #[serde(skip_serializing_if = "Option::is_none")] | 21 | #[serde(skip_serializing_if = "Option::is_none")] |
| 23 | pub pubkey: Option<String>, | 22 | pub pubkey: Option<String>, |
| 24 | 23 | ||
| 25 | /// Contact information for relay admin | 24 | /// Contact information for relay admin |
| 26 | #[serde(skip_serializing_if = "Option::is_none")] | 25 | #[serde(skip_serializing_if = "Option::is_none")] |
| 27 | pub contact: Option<String>, | 26 | pub contact: Option<String>, |
| 28 | 27 | ||
| 29 | /// List of NIPs supported by this relay | 28 | /// List of NIPs supported by this relay |
| 30 | pub supported_nips: Vec<u16>, | 29 | pub supported_nips: Vec<u16>, |
| 31 | 30 | ||
| 32 | /// Relay software identifier | 31 | /// Relay software identifier |
| 33 | pub software: String, | 32 | pub software: String, |
| 34 | 33 | ||
| 35 | /// Software version | 34 | /// Software version |
| 36 | pub version: String, | 35 | pub version: String, |
| 37 | 36 | ||
| 38 | // GRASP-01 Extensions (lines 11-14 of GRASP-01 spec) | 37 | // GRASP-01 Extensions (lines 11-14 of GRASP-01 spec) |
| 39 | |||
| 40 | /// List of supported GRASPs (e.g., ["GRASP-01"]) | 38 | /// List of supported GRASPs (e.g., ["GRASP-01"]) |
| 41 | /// Required by GRASP-01 specification line 12 | 39 | /// Required by GRASP-01 specification line 12 |
| 42 | pub supported_grasps: Vec<String>, | 40 | pub supported_grasps: Vec<String>, |
| 43 | 41 | ||
| 44 | /// Repository acceptance criteria description | 42 | /// Repository acceptance criteria description |
| 45 | /// Required by GRASP-01 specification line 13 | 43 | /// Required by GRASP-01 specification line 13 |
| 46 | pub repo_acceptance_criteria: String, | 44 | pub repo_acceptance_criteria: String, |
| 47 | 45 | ||
| 48 | /// Curation policy (present if curated, absent otherwise) | 46 | /// Curation policy (present if curated, absent otherwise) |
| 49 | /// Optional per GRASP-01 specification line 14 | 47 | /// Optional per GRASP-01 specification line 14 |
| 50 | #[serde(skip_serializing_if = "Option::is_none")] | 48 | #[serde(skip_serializing_if = "Option::is_none")] |
| @@ -66,7 +64,7 @@ impl RelayInformationDocument { | |||
| 66 | ], | 64 | ], |
| 67 | software: env!("CARGO_PKG_NAME").to_string(), | 65 | software: env!("CARGO_PKG_NAME").to_string(), |
| 68 | version: env!("CARGO_PKG_VERSION").to_string(), | 66 | version: env!("CARGO_PKG_VERSION").to_string(), |
| 69 | 67 | ||
| 70 | // GRASP-01 Extensions | 68 | // GRASP-01 Extensions |
| 71 | supported_grasps: vec!["GRASP-01".to_string()], | 69 | supported_grasps: vec!["GRASP-01".to_string()], |
| 72 | repo_acceptance_criteria: format!( | 70 | repo_acceptance_criteria: format!( |
| @@ -77,7 +75,7 @@ impl RelayInformationDocument { | |||
| 77 | curation: None, // Not a curated relay - only SPAM prevention via GRASP-01 policy | 75 | curation: None, // Not a curated relay - only SPAM prevention via GRASP-01 policy |
| 78 | } | 76 | } |
| 79 | } | 77 | } |
| 80 | 78 | ||
| 81 | /// Serialize to JSON string | 79 | /// Serialize to JSON string |
| 82 | pub fn to_json(&self) -> Result<String, serde_json::Error> { | 80 | pub fn to_json(&self) -> Result<String, serde_json::Error> { |
| 83 | serde_json::to_string_pretty(self) | 81 | serde_json::to_string_pretty(self) |
| @@ -102,7 +100,7 @@ mod tests { | |||
| 102 | }; | 100 | }; |
| 103 | 101 | ||
| 104 | let doc = RelayInformationDocument::from_config(&config); | 102 | let doc = RelayInformationDocument::from_config(&config); |
| 105 | 103 | ||
| 106 | assert_eq!(doc.name, "Test Relay"); | 104 | assert_eq!(doc.name, "Test Relay"); |
| 107 | assert_eq!(doc.description, "A test relay"); | 105 | assert_eq!(doc.description, "A test relay"); |
| 108 | assert_eq!(doc.pubkey, Some("npub1test".to_string())); | 106 | assert_eq!(doc.pubkey, Some("npub1test".to_string())); |
| @@ -129,7 +127,7 @@ mod tests { | |||
| 129 | 127 | ||
| 130 | let doc = RelayInformationDocument::from_config(&config); | 128 | let doc = RelayInformationDocument::from_config(&config); |
| 131 | let json = doc.to_json().expect("Failed to serialize to JSON"); | 129 | let json = doc.to_json().expect("Failed to serialize to JSON"); |
| 132 | 130 | ||
| 133 | // Verify JSON contains expected fields | 131 | // Verify JSON contains expected fields |
| 134 | assert!(json.contains("\"name\"")); | 132 | assert!(json.contains("\"name\"")); |
| 135 | assert!(json.contains("\"description\"")); | 133 | assert!(json.contains("\"description\"")); |
| @@ -137,10 +135,10 @@ mod tests { | |||
| 137 | assert!(json.contains("\"supported_grasps\"")); | 135 | assert!(json.contains("\"supported_grasps\"")); |
| 138 | assert!(json.contains("\"repo_acceptance_criteria\"")); | 136 | assert!(json.contains("\"repo_acceptance_criteria\"")); |
| 139 | assert!(json.contains("GRASP-01")); | 137 | assert!(json.contains("GRASP-01")); |
| 140 | 138 | ||
| 141 | // Verify it's valid JSON by parsing | 139 | // Verify it's valid JSON by parsing |
| 142 | let parsed: serde_json::Value = serde_json::from_str(&json).expect("Invalid JSON"); | 140 | let parsed: serde_json::Value = serde_json::from_str(&json).expect("Invalid JSON"); |
| 143 | assert_eq!(parsed["name"], "Test Relay"); | 141 | assert_eq!(parsed["name"], "Test Relay"); |
| 144 | assert_eq!(parsed["supported_grasps"][0], "GRASP-01"); | 142 | assert_eq!(parsed["supported_grasps"][0], "GRASP-01"); |
| 145 | } | 143 | } |
| 146 | } \ No newline at end of file | 144 | } |