test(nostr): add log messages
This commit is contained in:
parent
a73e7c1d68
commit
06bd46c40c
|
@ -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
|
||||||
|
|
11
src/nostr.rs
11
src/nostr.rs
|
@ -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,17 +62,19 @@ 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
|
||||||
let signed_event = match unsigned_event.sign(&self.keys).await {
|
let signed_event = match unsigned_event.sign(&self.keys).await {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
Err(e) => return Err(MyError::from(e)), // Convert the error to the expected type
|
Err(e) => return Err(MyError::from(e)), // Convert the error to the expected type
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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(
|
||||||
|
|
Loading…
Reference in New Issue