Struct nostr_sdk::EventBuilder

source ·
pub struct EventBuilder { /* private fields */ }
Expand description

Event builder

Implementations§

source§

impl EventBuilder

source

pub fn new<S>(kind: Kind, content: S, tags: &[Tag]) -> EventBuilderwhere S: Into<String>,

source

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

source

pub fn to_unsigned_event_with_supplier<T>( self, supplier: &T, pubkey: XOnlyPublicKey ) -> UnsignedEventwhere T: TimeSupplier,

source

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

source

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

source

pub fn to_event(self, keys: &Keys) -> Result<Event, Error>

Build Event

source

pub fn to_unsigned_event(self, pubkey: XOnlyPublicKey) -> UnsignedEvent

source

pub fn to_pow_event(self, keys: &Keys, difficulty: u8) -> Result<Event, Error>

Build POW Event

source

pub fn to_unsigned_pow_event( self, pubkey: XOnlyPublicKey, difficulty: u8 ) -> UnsignedEvent

Build unsigned POW Event

source§

impl EventBuilder

source

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);

Add recommended relay

source

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!", &[]);
source

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!", &[]);
source

pub fn set_contact_list(list: Vec<Contact, Global>) -> EventBuilder

Set contact list

source

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

source

pub fn repost(event_id: EventId, public_key: XOnlyPublicKey) -> EventBuilder

Repost event

source

pub fn delete<S>(ids: Vec<EventId, Global>, reason: Option<S>) -> EventBuilderwhere S: Into<String>,

Create delete event

source

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

source

pub fn new_channel(metadata: Metadata) -> EventBuilder

source

pub fn set_channel_metadata( channel_id: ChannelId, relay_url: Option<Url>, metadata: Metadata ) -> EventBuilder

source

pub fn new_channel_msg<S>( channel_id: ChannelId, relay_url: Url, content: S ) -> EventBuilderwhere S: Into<String>,

source

pub fn hide_channel_msg<S>( message_id: EventId, reason: Option<S> ) -> EventBuilderwhere S: Into<String>,

source

pub fn mute_channel_user<S>( pubkey: XOnlyPublicKey, reason: Option<S> ) -> EventBuilderwhere S: Into<String>,

source

pub fn auth<S>(challenge: S, relay: Url) -> EventBuilderwhere S: Into<String>,

source

pub fn nostr_connect( sender_keys: &Keys, receiver_pubkey: XOnlyPublicKey, msg: Message ) -> Result<EventBuilder, Error>

source

pub fn live_event(live_event: LiveEvent) -> EventBuilder

source

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>,

source

pub fn report<S>(tags: &[Tag], content: S) -> EventBuilderwhere S: Into<String>,

source

pub fn new_zap_request(data: ZapRequestData) -> EventBuilder

source

pub fn new_zap_receipt<S>( bolt11: S, preimage: Option<S>, zap_request: Event ) -> EventBuilderwhere S: Into<String>,

source

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);
source

pub fn award_badge( badge_definition: &Event, awarded_pubkeys: Vec<Tag, Global> ) -> Result<EventBuilder, Error>

source

pub fn profile_badges( badge_definitions: Vec<Event, Global>, badge_awards: Vec<Event, Global>, pubkey_awarded: &XOnlyPublicKey ) -> Result<EventBuilder, Error>

source

pub fn file_metadata<S>(description: S, metadata: FileMetadata) -> EventBuilderwhere S: Into<String>,

source

pub fn http_auth(data: HttpData) -> EventBuilder

Trait Implementations§

source§

impl Clone for EventBuilder

source§

fn clone(&self) -> EventBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for EventBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl PartialEq<EventBuilder> for EventBuilder

source§

fn eq(&self, other: &EventBuilder) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for EventBuilder

source§

impl StructuralEq for EventBuilder

source§

impl StructuralPartialEq for EventBuilder

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more