test(nostr): add log messages

This commit is contained in:
Ryan 2024-12-16 13:31:11 +03:00
parent a73e7c1d68
commit 06bd46c40c
2 changed files with 9 additions and 6 deletions

View File

@ -19,7 +19,7 @@ pub fn App() -> impl IntoView {
spawn_local(async move { spawn_local(async move {
//initialize nostr client //initialize nostr client
let nostr_client = NostrClient::new("wss://relay.example.com").await.unwrap(); let nostr_client = NostrClient::new("wss://relay.damus.io").await.unwrap();
nostr_client.subscribe_to_items(tx.clone()).await.unwrap(); nostr_client.subscribe_to_items(tx.clone()).await.unwrap();
//handle incoming events //handle incoming events

View File

@ -40,6 +40,7 @@ impl NostrClient {
let client = Client::new(keys.clone()); let client = Client::new(keys.clone());
client.add_relay(relay_url).await?; client.add_relay(relay_url).await?;
client.connect().await; client.connect().await;
println!("Connected to relay: {}", relay_url);
Ok(Self { client, keys }) Ok(Self { client, keys })
} }
@ -61,7 +62,7 @@ impl NostrClient {
); );
// Create the event builder // Create the event builder
let event_builder = EventBuilder::new(Kind::TextNote, content); let event_builder = EventBuilder::new(Kind::TextNote, content.clone());
// Build the unsigned event // Build the unsigned event
let unsigned_event = event_builder.build(self.keys.public_key()); let unsigned_event = event_builder.build(self.keys.public_key());
// Sign the event and handle the error explicitly // Sign the event and handle the error explicitly
@ -71,7 +72,9 @@ impl NostrClient {
}; };
// Send the event // Send the event
self.client.send_event(signed_event).await?; self.client.send_event(signed_event.clone()).await?;
println!("Event published: {:?}", signed_event);
println!("Publishing content: {}", content);
Ok(()) Ok(())
} }
pub async fn subscribe_to_items( pub async fn subscribe_to_items(