Skip to content

Commit

Permalink
sdk: add wait-for-ok example
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Aug 1, 2023
1 parent a04f89c commit fbe34f3
Show file tree
Hide file tree
Showing 2 changed files with 39 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 @@ -68,4 +68,8 @@ name = "client-stop"
required-features = ["all-nips"]

[[example]]
name = "shutdown-on-drop"
name = "shutdown-on-drop"

[[example]]
name = "wait-for-ok"
required-features = ["nip19"]
34 changes: 34 additions & 0 deletions crates/nostr-sdk/examples/wait-for-ok.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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<()> {
env_logger::init();

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

let opts = Options::new()
.wait_for_ok(true)
.send_timeout(Some(Duration::from_secs(30)));
let client = Client::with_opts(&my_keys, opts);

// Paid relays that will not allow this public key to publish event
client.add_relay("wss://eden.nostr.land", None).await?;
client.add_relay("wss://nostr.wine", None).await?;

client.connect().await;

// Publish a text note
client
.publish_text_note("Hello from rust nostr-sdk", &[])
.await?;

Ok(())
}

0 comments on commit fbe34f3

Please sign in to comment.