diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:53:03 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:53:03 +0000 |
| commit | 2a9160836bb87fdea3ae891563b0169c68d1c2ab (patch) | |
| tree | 583c890687beaf7f380fc0be131bdf17485f06fa /src/nostr | |
| parent | 52489d3b1a7d79e164b4cc901b53fd06c05ce1b1 (diff) | |
fix: resolve all fmt and clippy warnings
Main lib (src/):
- Add #[allow(dead_code)] for build_info field (stored to prevent Prometheus unregistration)
- Add #[allow(dead_code)] for first_seen field (reserved for future rate limiting)
- Replace .or_insert_with(RelaySyncNeeds::default) with .or_default()
- Replace manual div_ceil implementations with .div_ceil(100)
Test code (tests/):
- Replace .expect(&format!(...)) with .unwrap_or_else(|_| panic!(...))
- Remove needless borrows in fetch_metrics() calls
- Add #[allow(dead_code)] and #[allow(unused_imports)] to test helpers module
grasp-audit:
- Apply cargo fmt to fix formatting
Diffstat (limited to 'src/nostr')
| -rw-r--r-- | src/nostr/builder.rs | 22 | ||||
| -rw-r--r-- | src/nostr/policy/announcement.rs | 7 | ||||
| -rw-r--r-- | src/nostr/policy/mod.rs | 3 | ||||
| -rw-r--r-- | src/nostr/policy/pr_event.rs | 2 | ||||
| -rw-r--r-- | src/nostr/policy/related.rs | 7 | ||||
| -rw-r--r-- | src/nostr/policy/state.rs | 7 |
6 files changed, 22 insertions, 26 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index 2284c18..c9bd1e1 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs | |||
| @@ -16,8 +16,8 @@ use crate::nostr::events::{ | |||
| 16 | KIND_REPOSITORY_STATE, | 16 | KIND_REPOSITORY_STATE, |
| 17 | }; | 17 | }; |
| 18 | use crate::nostr::policy::{ | 18 | use crate::nostr::policy::{ |
| 19 | AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, RelatedEventPolicy, | 19 | AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, |
| 20 | ReferenceResult, StatePolicy, StateResult, | 20 | RelatedEventPolicy, StatePolicy, StateResult, |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | /// Type alias for the shared database used by the relay | 23 | /// Type alias for the shared database used by the relay |
| @@ -77,7 +77,9 @@ impl Nip34WritePolicy { | |||
| 77 | match RepositoryAnnouncement::from_event(event.clone()) { | 77 | match RepositoryAnnouncement::from_event(event.clone()) { |
| 78 | Ok(announcement) => { | 78 | Ok(announcement) => { |
| 79 | // Try to create bare repository if it doesn't exist | 79 | // Try to create bare repository if it doesn't exist |
| 80 | if let Err(e) = self.announcement_policy.ensure_bare_repository(&announcement) | 80 | if let Err(e) = self |
| 81 | .announcement_policy | ||
| 82 | .ensure_bare_repository(&announcement) | ||
| 81 | { | 83 | { |
| 82 | tracing::warn!( | 84 | tracing::warn!( |
| 83 | "Failed to create bare repository for {}: {}", | 85 | "Failed to create bare repository for {}: {}", |
| @@ -145,22 +147,14 @@ impl Nip34WritePolicy { | |||
| 145 | Ok(_state) => { | 147 | Ok(_state) => { |
| 146 | // Process state alignment asynchronously | 148 | // Process state alignment asynchronously |
| 147 | if let Err(e) = self.state_policy.process_state_event(event).await { | 149 | if let Err(e) = self.state_policy.process_state_event(event).await { |
| 148 | tracing::warn!( | 150 | tracing::warn!("Failed to process state event {}: {}", event_id_str, e); |
| 149 | "Failed to process state event {}: {}", | ||
| 150 | event_id_str, | ||
| 151 | e | ||
| 152 | ); | ||
| 153 | } | 151 | } |
| 154 | 152 | ||
| 155 | tracing::debug!("Accepted repository state: {}", event_id_str); | 153 | tracing::debug!("Accepted repository state: {}", event_id_str); |
| 156 | PolicyResult::Accept | 154 | PolicyResult::Accept |
| 157 | } | 155 | } |
| 158 | Err(e) => { | 156 | Err(e) => { |
| 159 | tracing::warn!( | 157 | tracing::warn!("Failed to parse repository state {}: {}", event_id_str, e); |
| 160 | "Failed to parse repository state {}: {}", | ||
| 161 | event_id_str, | ||
| 162 | e | ||
| 163 | ); | ||
| 164 | // Still accept the event even if we can't parse it | 158 | // Still accept the event even if we can't parse it |
| 165 | // The validation passed, so it's structurally valid | 159 | // The validation passed, so it's structurally valid |
| 166 | PolicyResult::Accept | 160 | PolicyResult::Accept |
| @@ -348,4 +342,4 @@ pub fn create_relay(config: &Config) -> Result<RelayWithDatabase> { | |||
| 348 | database, | 342 | database, |
| 349 | write_policy, | 343 | write_policy, |
| 350 | }) | 344 | }) |
| 351 | } \ No newline at end of file | 345 | } |
diff --git a/src/nostr/policy/announcement.rs b/src/nostr/policy/announcement.rs index 8d30baf..353738b 100644 --- a/src/nostr/policy/announcement.rs +++ b/src/nostr/policy/announcement.rs | |||
| @@ -72,7 +72,10 @@ impl AnnouncementPolicy { | |||
| 72 | 72 | ||
| 73 | /// Create a bare git repository if it doesn't exist | 73 | /// Create a bare git repository if it doesn't exist |
| 74 | /// Path format: <git_data_path>/<npub>/<identifier>.git | 74 | /// Path format: <git_data_path>/<npub>/<identifier>.git |
| 75 | pub fn ensure_bare_repository(&self, announcement: &RepositoryAnnouncement) -> Result<(), String> { | 75 | pub fn ensure_bare_repository( |
| 76 | &self, | ||
| 77 | announcement: &RepositoryAnnouncement, | ||
| 78 | ) -> Result<(), String> { | ||
| 76 | let repo_path = self.ctx.git_data_path.join(announcement.repo_path()); | 79 | let repo_path = self.ctx.git_data_path.join(announcement.repo_path()); |
| 77 | 80 | ||
| 78 | // Check if repository already exists | 81 | // Check if repository already exists |
| @@ -154,4 +157,4 @@ impl AnnouncementPolicy { | |||
| 154 | 157 | ||
| 155 | Ok(false) | 158 | Ok(false) |
| 156 | } | 159 | } |
| 157 | } \ No newline at end of file | 160 | } |
diff --git a/src/nostr/policy/mod.rs b/src/nostr/policy/mod.rs index 6d67394..19db5f6 100644 --- a/src/nostr/policy/mod.rs +++ b/src/nostr/policy/mod.rs | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | /// - `StatePolicy` - State event validation + ref alignment | 5 | /// - `StatePolicy` - State event validation + ref alignment |
| 6 | /// - `PrEventPolicy` - PR/PR Update validation | 6 | /// - `PrEventPolicy` - PR/PR Update validation |
| 7 | /// - `RelatedEventPolicy` - Forward/backward reference checking | 7 | /// - `RelatedEventPolicy` - Forward/backward reference checking |
| 8 | |||
| 9 | mod announcement; | 8 | mod announcement; |
| 10 | mod pr_event; | 9 | mod pr_event; |
| 11 | mod related; | 10 | mod related; |
| @@ -38,4 +37,4 @@ impl PolicyContext { | |||
| 38 | git_data_path: git_data_path.into(), | 37 | git_data_path: git_data_path.into(), |
| 39 | } | 38 | } |
| 40 | } | 39 | } |
| 41 | } \ No newline at end of file | 40 | } |
diff --git a/src/nostr/policy/pr_event.rs b/src/nostr/policy/pr_event.rs index fee9a2a..53da369 100644 --- a/src/nostr/policy/pr_event.rs +++ b/src/nostr/policy/pr_event.rs | |||
| @@ -195,4 +195,4 @@ impl PrEventPolicy { | |||
| 195 | Ok(None) | 195 | Ok(None) |
| 196 | } | 196 | } |
| 197 | } | 197 | } |
| 198 | } \ No newline at end of file | 198 | } |
diff --git a/src/nostr/policy/related.rs b/src/nostr/policy/related.rs index 1937ca7..7ce87db 100644 --- a/src/nostr/policy/related.rs +++ b/src/nostr/policy/related.rs | |||
| @@ -169,10 +169,7 @@ impl RelatedEventPolicy { | |||
| 169 | 169 | ||
| 170 | /// Check if any events exist in database | 170 | /// Check if any events exist in database |
| 171 | /// Returns the first matching event ID found, or None if none match | 171 | /// Returns the first matching event ID found, or None if none match |
| 172 | async fn find_accepted_event( | 172 | async fn find_accepted_event(&self, event_ids: &[EventId]) -> Result<Option<EventId>, String> { |
| 173 | &self, | ||
| 174 | event_ids: &[EventId], | ||
| 175 | ) -> Result<Option<EventId>, String> { | ||
| 176 | if event_ids.is_empty() { | 173 | if event_ids.is_empty() { |
| 177 | return Ok(None); | 174 | return Ok(None); |
| 178 | } | 175 | } |
| @@ -273,4 +270,4 @@ impl RelatedEventPolicy { | |||
| 273 | 270 | ||
| 274 | Ok(false) | 271 | Ok(false) |
| 275 | } | 272 | } |
| 276 | } \ No newline at end of file | 273 | } |
diff --git a/src/nostr/policy/state.rs b/src/nostr/policy/state.rs index 5692bd8..43349e2 100644 --- a/src/nostr/policy/state.rs +++ b/src/nostr/policy/state.rs | |||
| @@ -239,7 +239,10 @@ impl StatePolicy { | |||
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | // Build repository path: <git_data_path>/<owner_npub>/<identifier>.git | 241 | // Build repository path: <git_data_path>/<owner_npub>/<identifier>.git |
| 242 | let repo_path = self.ctx.git_data_path.join(announcement.repo_path().clone()); | 242 | let repo_path = self |
| 243 | .ctx | ||
| 244 | .git_data_path | ||
| 245 | .join(announcement.repo_path().clone()); | ||
| 243 | owner_repos.push((announcement, repo_path)); | 246 | owner_repos.push((announcement, repo_path)); |
| 244 | } | 247 | } |
| 245 | 248 | ||
| @@ -416,4 +419,4 @@ impl StatePolicy { | |||
| 416 | 419 | ||
| 417 | result | 420 | result |
| 418 | } | 421 | } |
| 419 | } \ No newline at end of file | 422 | } |