From 32b7ff94ec5425a2bc3bc9639c19740e6e80e532 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 11 Jul 2024 10:53:58 +0300 Subject: [PATCH] feat: implement sending events from args and finding events --- src/main.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 65ae222..da9b770 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,14 @@ +use std::env::args; use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; +use std::time::Duration; +use nostr_sdk::async_utility::futures_util::TryFutureExt; use nostr_sdk::prelude::*; #[tokio::main] async fn main() { let my_keys: Keys = Keys::generate(); - let client = Client::new(&my_keys); + let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050))); client.add_relay("ws://localhost:4736").await; @@ -37,10 +40,26 @@ async fn main() { client.connect().await; - let filter = Filter::new().kind(Kind::from(90002)); - let sub_id: SubscriptionId = client.subscribe(vec![filter], None).await; + let timeout = Duration::from_secs(3); + let task_kind = Kind::from(90002); + + let filter = Filter::new().kind(task_kind); + let sub_id: SubscriptionId = client.subscribe(vec![filter.clone()], None).await; + + for argument in args().skip(1) { + println!("Sending {}", argument); + let event = EventBuilder::new(task_kind, argument, []).to_event(&my_keys).unwrap(); + let _ = client.send_event(event).await; + } + + println!("Finding existing events"); + let res = client.get_events_of(vec![filter], Option::from(timeout)).map_ok(|res| + for event in res { + println!("Found {} {:?}", event.content, event.tags) + }).await; let mut notifications = client.notifications(); + println!("Listening for events..."); while let Ok(notification) = notifications.recv().await { if let RelayPoolNotification::Event { subscription_id, event, .. } = notification { let kind = event.kind;