Skip to content

Commit

Permalink
feat: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
reyamir committed Nov 8, 2024
1 parent 14a5bd2 commit 431b31b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions crates/nostr-sdk/examples/comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2022-2023 Yuki Kishimoto
// Copyright (c) 2023-2024 Rust Nostr Developers
// Distributed under the MIT software license

use nostr_sdk::prelude::*;

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

let keys = Keys::generate();
let client = Client::builder().signer(keys).build();

client.add_relay("wss://relay.damus.io/").await?;
client.add_relay("wss://relay.primal.net/").await?;

client.connect().await;

let event_id =
EventId::from_bech32("note1hrrgx2309my3wgeecx2tt6fl2nl8hcwl0myr3xvkcqpnq24pxg2q06armr")?;
let events = client
.fetch_events(vec![Filter::new().id(event_id)], None)
.await?;

let reply_to = events.first().unwrap();
let builder = EventBuilder::comment("This is a reply", reply_to, None, None);

let output = client.send_event_builder(builder).await?;
println!("Output: {:?}", output);

Ok(())
}
4 changes: 2 additions & 2 deletions crates/nostr/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl EventBuilder {
tags.push(Tag::from_standardized_without_cell(TagStandard::Event {
event_id: root.id,
relay_url: relay_url.clone(),
marker: Some(Marker::Root),
marker: None,
public_key: Some(root.pubkey),
uppercase: true,
}));
Expand Down Expand Up @@ -550,7 +550,7 @@ impl EventBuilder {
tags.push(Tag::from_standardized_without_cell(TagStandard::Event {
event_id: reply_to.id,
relay_url,
marker: Some(Marker::Reply),
marker: None,
public_key: Some(reply_to.pubkey),
uppercase: false,
}));
Expand Down

0 comments on commit 431b31b

Please sign in to comment.