rust-nostr / nostr

Nostr protocol implementation, SDK and FFI
https://rust-nostr.org/
MIT License
417 stars 90 forks source link

`Client.get_events_of()` bug #116

Closed ok300 closed 1 year ago

ok300 commented 1 year ago

Describe the bug

Starting with commit 2dd972de2f56aee19818f8798869ac9355f6aadd calling Client.get_events_of() returns an empty list.

This works fine in the commit before that, 2ebd5a117cdb4bd2a16c68da7a61ddef8d82df7d .

Using Client.notifications().recv() works in both commits.

To Reproduce

Here is a code snippet to reproduce the bug ```rust use std::time::Duration; use nostr::prelude::*; use nostr_sdk::prelude::*; #[tokio::main] async fn main() -> Result<()> { let filters = vec![Filter::new().kind(Kind::TextNote).limit(10)]; let client = Client::new(&Keys::generate()); client.add_relay("wss://relay.damus.io", None).await?; client.connect().await; let res_get_events_of = client .get_events_of(filters.clone(), Some(Duration::from_secs(3))) .await?; println!("recv via get_events_of: {} events", res_get_events_of.len()); let res_notification_recv = get_events_via_notification_recv(&client, filters).await?; println!("recv via notifications: {} events", res_notification_recv.len()); Ok(()) } async fn get_events_via_notification_recv( client: &Client, filters: Vec, ) -> Result> { let mut res: Vec = vec![]; client.subscribe(filters).await; let mut notifications = client.notifications(); loop { match notifications.recv().await { Ok(notification) => { if let RelayPoolNotification::Message(_, msg) = notification { match msg { RelayMessage::Event { subscription_id: _, event, } => res.push(*event), RelayMessage::EndOfStoredEvents(_) => break, _ => {} } } } Err(e) => panic!("Unexpected error: {e}"), } } Ok(res) } ```

Expected behavior

In the code snippet above, Client.get_events_of() and Client.notifications().recv() should return the same number of events.

Build environment

Additional context

Dependencies in Cargo.toml:

[dependencies]
nostr = { git = "https://github.com/rust-nostr/nostr", default-features = false, rev = "2dd972de2f56aee19818f8798869ac9355f6aadd" }
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", default-features = false, rev = "2dd972de2f56aee19818f8798869ac9355f6aadd" }
tokio = { version = "*", default-features = false, features = ["rt", "macros"] }
yukibtc commented 1 year ago

I reverted that commit at c35a006

ok300 commented 1 year ago

You're right, didn't see that.