Skip to content

Commit

Permalink
sdk: add get-events-of example
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 5, 2023
1 parent 6e14885 commit 1f8a712
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/nostr-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ tokio = { workspace = true, features = ["rt", "macros", "sync"] }
[dev-dependencies]
tracing-subscriber = { workspace = true, features = ["env-filter"] }

[[example]]
name = "client-with-opts"
required-features = ["all-nips"]

[[example]]
name = "client"
required-features = ["all-nips"]

[[example]]
name = "client-with-opts"
name = "get-events-of"
required-features = ["all-nips"]

[[example]]
Expand Down
33 changes: 33 additions & 0 deletions crates/nostr-sdk/examples/get-events-of.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2022-2023 Yuki Kishimoto
// Distributed under the MIT software license

use std::time::Duration;

use nostr_sdk::prelude::*;

const BECH32_SK: &str = "nsec1ufnus6pju578ste3v90xd5m2decpuzpql2295m3sknqcjzyys9ls0qlc85";

#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();

let secret_key = SecretKey::from_bech32(BECH32_SK)?;
let my_keys = Keys::new(secret_key);

let client = Client::new(&my_keys);
client.add_relay("wss://relay.damus.io", None).await?;
client.add_relay("wss://nostr.wine", None).await?;
client.add_relay("wss://relay.nostr.info", None).await?;

client.connect().await;

let filter = Filter::new()
.author(my_keys.public_key().to_string())
.kind(Kind::Metadata);
let events = client
.get_events_of(vec![filter], Some(Duration::from_secs(10)))
.await;
println!("{events:#?}");

Ok(())
}

0 comments on commit 1f8a712

Please sign in to comment.