Struct nostr_sdk::EventBuilder
source · pub struct EventBuilder { /* private fields */ }
Expand description
Event
builder
Implementations§
source§impl EventBuilder
impl EventBuilder
sourcepub fn new<S>(kind: Kind, content: S, tags: &[Tag]) -> EventBuilderwhere
S: Into<String>,
pub fn new<S>(kind: Kind, content: S, tags: &[Tag]) -> EventBuilderwhere S: Into<String>,
New EventBuilder
sourcepub fn to_unsigned_event(self, pubkey: XOnlyPublicKey) -> UnsignedEvent
pub fn to_unsigned_event(self, pubkey: XOnlyPublicKey) -> UnsignedEvent
Build UnsignedEvent
sourcepub fn to_unsigned_pow_event(
self,
pubkey: XOnlyPublicKey,
difficulty: u8
) -> UnsignedEvent
pub fn to_unsigned_pow_event( self, pubkey: XOnlyPublicKey, difficulty: u8 ) -> UnsignedEvent
Build unsigned POW Event
source§impl EventBuilder
impl EventBuilder
sourcepub fn set_metadata(metadata: Metadata) -> EventBuilder
pub fn set_metadata(metadata: Metadata) -> EventBuilder
Set metadata
https://github.com/nostr-protocol/nips/blob/master/01.md
Example
use nostr::url::Url;
use nostr::{EventBuilder, Metadata};
let metadata = Metadata::new()
.name("username")
.display_name("My Username")
.about("Description")
.picture(Url::parse("https://example.com/avatar.png").unwrap())
.nip05("username@example.com")
.lud16("yuki@getalby.com");
let builder = EventBuilder::set_metadata(metadata);
sourcepub fn add_recommended_relay(url: &Url) -> EventBuilder
pub fn add_recommended_relay(url: &Url) -> EventBuilder
Add recommended relay
sourcepub fn new_text_note<S>(content: S, tags: &[Tag]) -> EventBuilderwhere
S: Into<String>,
pub fn new_text_note<S>(content: S, tags: &[Tag]) -> EventBuilderwhere S: Into<String>,
Text note
https://github.com/nostr-protocol/nips/blob/master/01.md
Example
use nostr::EventBuilder;
let builder = EventBuilder::new_text_note("My first text note from Nostr SDK!", &[]);
sourcepub fn long_form_text_note<S>(content: S, tags: &[Tag]) -> EventBuilderwhere
S: Into<String>,
pub fn long_form_text_note<S>(content: S, tags: &[Tag]) -> EventBuilderwhere S: Into<String>,
Long-form text note (generally referred to as “articles” or “blog posts”).
https://github.com/nostr-protocol/nips/blob/master/23.md
Example
use std::str::FromStr;
use nostr::{EventBuilder, Tag, Timestamp, EventId};
use nostr::prelude::tag::UncheckedUrl;
let event_id = EventId::from_hex("b3e392b11f5d4f28321cedd09303a748acfd0487aea5a7450b3481c60b6e4f87").unwrap();
let content: &str = "Lorem [ipsum][4] dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\nRead more at #[3].";
let tags = &[
Tag::Identifier("lorem-ipsum".to_string()),
Tag::Title("Lorem Ipsum".to_string()),
Tag::PublishedAt(Timestamp::from(1296962229)),
Tag::Hashtag("placeholder".to_string()),
Tag::Event(event_id, Some(UncheckedUrl::from_str("wss://relay.example.com").unwrap()), None),
];
let builder = EventBuilder::long_form_text_note("My first text note from Nostr SDK!", &[]);
sourcepub fn set_contact_list(list: Vec<Contact, Global>) -> EventBuilder
pub fn set_contact_list(list: Vec<Contact, Global>) -> EventBuilder
Set contact list
sourcepub fn new_encrypted_direct_msg<S>(
sender_keys: &Keys,
receiver_pubkey: XOnlyPublicKey,
content: S
) -> Result<EventBuilder, Error>where
S: Into<String>,
pub fn new_encrypted_direct_msg<S>( sender_keys: &Keys, receiver_pubkey: XOnlyPublicKey, content: S ) -> Result<EventBuilder, Error>where S: Into<String>,
Create encrypted direct msg event
sourcepub fn repost(event_id: EventId, public_key: XOnlyPublicKey) -> EventBuilder
pub fn repost(event_id: EventId, public_key: XOnlyPublicKey) -> EventBuilder
Repost event
sourcepub fn delete<S>(ids: Vec<EventId, Global>, reason: Option<S>) -> EventBuilderwhere
S: Into<String>,
pub fn delete<S>(ids: Vec<EventId, Global>, reason: Option<S>) -> EventBuilderwhere S: Into<String>,
Create delete event
sourcepub fn new_reaction<S>(
event_id: EventId,
public_key: XOnlyPublicKey,
content: S
) -> EventBuilderwhere
S: Into<String>,
pub fn new_reaction<S>( event_id: EventId, public_key: XOnlyPublicKey, content: S ) -> EventBuilderwhere S: Into<String>,
Add reaction (like/upvote, dislike/downvote or emoji) to an event
sourcepub fn new_channel(metadata: Metadata) -> EventBuilder
pub fn new_channel(metadata: Metadata) -> EventBuilder
Create new channel
sourcepub fn set_channel_metadata(
channel_id: ChannelId,
relay_url: Option<Url>,
metadata: Metadata
) -> EventBuilder
pub fn set_channel_metadata( channel_id: ChannelId, relay_url: Option<Url>, metadata: Metadata ) -> EventBuilder
Set channel metadata
sourcepub fn new_channel_msg<S>(
channel_id: ChannelId,
relay_url: Url,
content: S
) -> EventBuilderwhere
S: Into<String>,
pub fn new_channel_msg<S>( channel_id: ChannelId, relay_url: Url, content: S ) -> EventBuilderwhere S: Into<String>,
New channel message
sourcepub fn hide_channel_msg<S>(
message_id: EventId,
reason: Option<S>
) -> EventBuilderwhere
S: Into<String>,
pub fn hide_channel_msg<S>( message_id: EventId, reason: Option<S> ) -> EventBuilderwhere S: Into<String>,
sourcepub fn mute_channel_user<S>(
pubkey: XOnlyPublicKey,
reason: Option<S>
) -> EventBuilderwhere
S: Into<String>,
pub fn mute_channel_user<S>( pubkey: XOnlyPublicKey, reason: Option<S> ) -> EventBuilderwhere S: Into<String>,
Mute channel user
sourcepub fn auth<S>(challenge: S, relay: Url) -> EventBuilderwhere
S: Into<String>,
pub fn auth<S>(challenge: S, relay: Url) -> EventBuilderwhere S: Into<String>,
Create an auth event
sourcepub fn nostr_connect(
sender_keys: &Keys,
receiver_pubkey: XOnlyPublicKey,
msg: Message
) -> Result<EventBuilder, Error>
pub fn nostr_connect( sender_keys: &Keys, receiver_pubkey: XOnlyPublicKey, msg: Message ) -> Result<EventBuilder, Error>
Nostr Connect
sourcepub fn report<S>(tags: &[Tag], content: S) -> EventBuilderwhere
S: Into<String>,
pub fn report<S>(tags: &[Tag], content: S) -> EventBuilderwhere S: Into<String>,
Create report event
Trait Implementations§
source§impl Clone for EventBuilder
impl Clone for EventBuilder
source§fn clone(&self) -> EventBuilder
fn clone(&self) -> EventBuilder
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for EventBuilder
impl Debug for EventBuilder
source§impl PartialEq<EventBuilder> for EventBuilder
impl PartialEq<EventBuilder> for EventBuilder
source§fn eq(&self, other: &EventBuilder) -> bool
fn eq(&self, other: &EventBuilder) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Eq for EventBuilder
impl StructuralEq for EventBuilder
impl StructuralPartialEq for EventBuilder
Auto Trait Implementations§
impl RefUnwindSafe for EventBuilder
impl Send for EventBuilder
impl Sync for EventBuilder
impl Unpin for EventBuilder
impl UnwindSafe for EventBuilder
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.