upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/src/client.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 07:45:56 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 07:45:56 +0000
commit8190a3a1b4541e86692d5e1210f955fc8c8351a8 (patch)
treec6353e2d4756b96f08bf64de7bc66a903cbf392f /grasp-audit/src/client.rs
parentc92faa11d669832e9339d8f7707220ff44553008 (diff)
Fix audit system tag filtering and event validation
- Changed from multi-letter custom tags to single-letter tags (g, r, c) for compatibility with Nostr Filter API - Added validation check in send_event() to detect relay rejections by checking output.success and output.failed - Improved connection stability with retry loop - Added debug output for troubleshooting query issues - All tests now pass: 12/12 unit tests, 6/6 integration tests - CLI verified working with Docker relay Fixes issues discovered during Path 1 integration testing.
Diffstat (limited to 'grasp-audit/src/client.rs')
-rw-r--r--grasp-audit/src/client.rs36
1 files changed, 30 insertions, 6 deletions
diff --git a/grasp-audit/src/client.rs b/grasp-audit/src/client.rs
index 7c6cf00..d78b33c 100644
--- a/grasp-audit/src/client.rs
+++ b/grasp-audit/src/client.rs
@@ -18,11 +18,27 @@ impl AuditClient {
18 let keys = Keys::generate(); 18 let keys = Keys::generate();
19 let client = Client::new(keys.clone()); 19 let client = Client::new(keys.clone());
20 20
21 // Add relay and connect
21 client.add_relay(relay_url).await?; 22 client.add_relay(relay_url).await?;
22 client.connect().await; 23 client.connect().await;
23 24
24 // Wait a bit for connection to establish 25 // Wait for connection to establish (with retries)
25 tokio::time::sleep(Duration::from_millis(500)).await; 26 let mut attempts = 0;
27 while attempts < 20 {
28 tokio::time::sleep(Duration::from_millis(100)).await;
29
30 let relays = client.relays().await;
31 let connected = relays.values().any(|r| r.is_connected());
32
33 if connected {
34 break;
35 }
36
37 attempts += 1;
38 }
39
40 // Give it a bit more time to stabilize
41 tokio::time::sleep(Duration::from_millis(200)).await;
26 42
27 Ok(Self { 43 Ok(Self {
28 client, 44 client,
@@ -57,6 +73,11 @@ impl AuditClient {
57 let output = self.client.send_event(&event).await?; 73 let output = self.client.send_event(&event).await?;
58 let event_id = *output.id(); 74 let event_id = *output.id();
59 75
76 // Check if any relay rejected the event
77 if output.success.is_empty() && !output.failed.is_empty() {
78 return Err(anyhow!("All relays rejected the event"));
79 }
80
60 // Wait a bit for event to propagate 81 // Wait a bit for event to propagate
61 tokio::time::sleep(Duration::from_millis(100)).await; 82 tokio::time::sleep(Duration::from_millis(100)).await;
62 83
@@ -70,16 +91,19 @@ impl AuditClient {
70 91
71 /// Query events, optionally filtered to this audit run 92 /// Query events, optionally filtered to this audit run
72 pub async fn query(&self, mut filter: Filter) -> Result<Vec<Event>> { 93 pub async fn query(&self, mut filter: Filter) -> Result<Vec<Event>> {
94 use nostr_sdk::prelude::{Alphabet, SingleLetterTag};
95
73 if self.config.mode == AuditMode::CI { 96 if self.config.mode == AuditMode::CI {
74 // In CI mode, only see our own audit events 97 // In CI mode, only see our own audit events
98 // Filter by "g" tag (grasp-audit marker) and "r" tag (run ID)
75 filter = filter 99 filter = filter
76 .custom_tag( 100 .custom_tag(
77 SingleLetterTag::lowercase(Alphabet::G), 101 SingleLetterTag::lowercase(Alphabet::G),
78 "true" // grasp-audit tag 102 "grasp-audit"
79 ) 103 )
80 .custom_tag( 104 .custom_tag(
81 SingleLetterTag::lowercase(Alphabet::R), 105 SingleLetterTag::lowercase(Alphabet::R),
82 &self.config.run_id // audit-run-id tag 106 &self.config.run_id
83 ); 107 );
84 } 108 }
85 // In Production mode, see all events (no filter modification) 109 // In Production mode, see all events (no filter modification)