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_event_with_ctx<C, R, T>(
self,
secp: &Secp256k1<C>,
rng: &mut R,
supplier: &T,
keys: &Keys
) -> Result<Event, Error>where
C: Signing,
R: Rng + CryptoRng,
T: TimeSupplier,
pub fn to_event_with_ctx<C, R, T>( self, secp: &Secp256k1<C>, rng: &mut R, supplier: &T, keys: &Keys ) -> Result<Event, Error>where C: Signing, R: Rng + CryptoRng, T: TimeSupplier,
Build Event
sourcepub fn to_unsigned_event_with_supplier<T>(
self,
supplier: &T,
pubkey: XOnlyPublicKey
) -> UnsignedEventwhere
T: TimeSupplier,
pub fn to_unsigned_event_with_supplier<T>( self, supplier: &T, pubkey: XOnlyPublicKey ) -> UnsignedEventwhere T: TimeSupplier,
Build UnsignedEvent
sourcepub fn to_pow_event_with_ctx<C, R, T>(
self,
secp: &Secp256k1<C>,
rng: &mut R,
supplier: &T,
keys: &Keys,
difficulty: u8
) -> Result<Event, Error>where
C: Signing,
R: Rng + CryptoRng,
T: TimeSupplier,
pub fn to_pow_event_with_ctx<C, R, T>( self, secp: &Secp256k1<C>, rng: &mut R, supplier: &T, keys: &Keys, difficulty: u8 ) -> Result<Event, Error>where C: Signing, R: Rng + CryptoRng, T: TimeSupplier,
Build POW Event
sourcepub fn to_unsigned_pow_event_with_supplier<T>(
self,
supplier: &T,
pubkey: XOnlyPublicKey,
difficulty: u8
) -> UnsignedEventwhere
T: TimeSupplier,
pub fn to_unsigned_pow_event_with_supplier<T>( self, supplier: &T, pubkey: XOnlyPublicKey, difficulty: u8 ) -> UnsignedEventwhere T: TimeSupplier,
Build unsigned POW Event
source§impl EventBuilder
impl 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, 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("wss://relay.example.com")), 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,
reply_to: Option<EventId>
) -> Result<EventBuilder, Error>where
S: Into<String>,
pub fn new_encrypted_direct_msg<S>( sender_keys: &Keys, receiver_pubkey: XOnlyPublicKey, content: S, reply_to: Option<EventId> ) -> 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 live_event(live_event: LiveEvent) -> EventBuilder
pub fn live_event(live_event: LiveEvent) -> EventBuilder
sourcepub fn live_event_msg<S>(
live_event_id: S,
live_event_host: XOnlyPublicKey,
content: S,
relay_url: Option<Url>,
tags: Vec<Tag, Global>
) -> EventBuilderwhere
S: Into<String>,
pub fn live_event_msg<S>( live_event_id: S, live_event_host: XOnlyPublicKey, content: S, relay_url: Option<Url>, tags: Vec<Tag, Global> ) -> EventBuilderwhere S: Into<String>,
Live Event Message
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
sourcepub fn new_zap_request(data: ZapRequestData) -> EventBuilder
pub fn new_zap_request(data: ZapRequestData) -> EventBuilder
Create zap request event
sourcepub fn new_zap_receipt<S>(
bolt11: S,
preimage: Option<S>,
zap_request: Event
) -> EventBuilderwhere
S: Into<String>,
pub fn new_zap_receipt<S>( bolt11: S, preimage: Option<S>, zap_request: Event ) -> EventBuilderwhere S: Into<String>,
Create zap receipt event
sourcepub fn define_badge<S>(
badge_id: S,
name: Option<S>,
description: Option<S>,
image: Option<UncheckedUrl>,
image_dimensions: Option<ImageDimensions>,
thumbnails: Option<Vec<(UncheckedUrl, Option<ImageDimensions>), Global>>
) -> EventBuilderwhere
S: Into<String>,
pub fn define_badge<S>( badge_id: S, name: Option<S>, description: Option<S>, image: Option<UncheckedUrl>, image_dimensions: Option<ImageDimensions>, thumbnails: Option<Vec<(UncheckedUrl, Option<ImageDimensions>), Global>> ) -> EventBuilderwhere S: Into<String>,
Create a badge definition event
https://github.com/nostr-protocol/nips/blob/master/58.md
Example
use nostr::{EventBuilder, ImageDimensions, UncheckedUrl};
let badge_id = String::from("nostr-sdk-test-badge");
let name = Some(String::from("Nostr SDK test badge"));
let description = Some(String::from("This is a test badge"));
let image_url = Some(UncheckedUrl::from("https://nostr.build/someimage/1337"));
let image_size = Some(ImageDimensions::new(1024, 1024));
let thumbs = Some(vec![(
UncheckedUrl::from("https://nostr.build/somethumbnail/1337"),
Some(ImageDimensions::new(256, 256)),
)]);
let event_builder =
EventBuilder::define_badge(badge_id, name, description, image_url, image_size, thumbs);
sourcepub fn award_badge(
badge_definition: &Event,
awarded_pubkeys: Vec<Tag, Global>
) -> Result<EventBuilder, Error>
pub fn award_badge( badge_definition: &Event, awarded_pubkeys: Vec<Tag, Global> ) -> Result<EventBuilder, Error>
Create a badge award event
sourcepub fn profile_badges(
badge_definitions: Vec<Event, Global>,
badge_awards: Vec<Event, Global>,
pubkey_awarded: &XOnlyPublicKey
) -> Result<EventBuilder, Error>
pub fn profile_badges( badge_definitions: Vec<Event, Global>, badge_awards: Vec<Event, Global>, pubkey_awarded: &XOnlyPublicKey ) -> Result<EventBuilder, Error>
Create a profile badges event
sourcepub fn file_metadata<S>(description: S, metadata: FileMetadata) -> EventBuilderwhere
S: Into<String>,
pub fn file_metadata<S>(description: S, metadata: FileMetadata) -> EventBuilderwhere S: Into<String>,
File metadata
sourcepub fn http_auth(data: HttpData) -> EventBuilder
pub fn http_auth(data: HttpData) -> EventBuilder
Trait Implementations§
source§impl Clone for EventBuilder
impl Clone for EventBuilder
source§fn clone(&self) -> EventBuilder
fn clone(&self) -> EventBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
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<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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
key
and return true
if they are equal.