Struct Event

Source
pub struct Event {
    pub id: Id,
    pub pubkey: PublicKey,
    pub created_at: Unixtime,
    pub kind: EventKind,
    pub tags: Vec<Tag>,
    pub content: String,
    pub ots: Option<String>,
    pub sig: Signature,
}
Expand description

The main event type

Fields§

§id: Id

The Id of the event, generated as a SHA256 of the inner event data

§pubkey: PublicKey

The public key of the actor who created the event

§created_at: Unixtime

The (unverified) time at which the event was created

§kind: EventKind

The kind of event

§tags: Vec<Tag>

A set of tags that apply to the event

§content: String

The content of the event

§ots: Option<String>

An optional verified time for the event (using OpenTimestamp)

§sig: Signature

The signature of the event, which cryptographically verifies that the holder of the PrivateKey matching the event’s PublicKey generated (or authorized) this event. The signature is taken over the id field only, but the id field is taken over the rest of the event data.

Implementations§

Source§

impl Event

Source

pub fn new(input: PreEvent, privkey: &PrivateKey) -> Result<Event, Error>

Create a new event

Source

pub fn new_with_pow( input: PreEvent, privkey: &PrivateKey, zero_bits: u8, ) -> Result<Event, Error>

Create a new event with proof of work.

This can take a long time, and is only cancellable by killing the thread.

Source

pub fn verify(&self, maxtime: Option<Unixtime>) -> Result<(), Error>

Check the validity of an event. This is useful if you deserialize an event from the network. If you create an event using new() it should already be trustworthy.

Source

pub fn new_set_metadata( input: PreEvent, privkey: &PrivateKey, metadata: Metadata, ) -> Result<Event, Error>

Create an event that sets Metadata

Source

pub fn new_zap_request( privkey: &PrivateKey, recipient_pubkey: PublicKeyHex, zapped_event: Option<Id>, millisatoshis: u64, relays: Vec<String>, content: String, ) -> Result<Event, Error>

Create a ZapRequest event These events are not published to nostr, they are sent to a lnurl.

Source

pub fn decrypted_contents( &self, private_key: &PrivateKey, ) -> Result<String, Error>

If an event is an EncryptedDirectMessage, decrypt it’s contents

Source

pub fn people(&self) -> Vec<(PublicKeyHex, Option<RelayUrl>, Option<String>)>

If the event refers to people, get all the PublicKeys it refers to along with recommended relay URL and petname for each

Source

pub fn referenced_people( &self, ) -> Vec<(PublicKeyHex, Option<RelayUrl>, Option<String>)>

If the event refers to people, get all the PublicKeys it refers to along with recommended relay URL and petname for each, but only if they are referenced within the note.

Source

pub fn is_reply(&self) -> bool

👎Deprecated since 0.2.0: please use replies_to instead

Is the event a reply?

Source

pub fn replies_to(&self) -> Option<(Id, Option<RelayUrl>)>

If this event replies to another, get that other event’s Id along with an optional recommended_relay_url

Source

pub fn replies_to_root(&self) -> Option<(Id, Option<RelayUrl>)>

If this event replies to a thread, get that threads root event Id if available, along with an optional recommended_relay_url

Source

pub fn replies_to_ancestors(&self) -> Vec<(Id, Option<RelayUrl>)>

If this event replies to a thread, get all ancestors in that thread. This also gets all mentioned events.

Source

pub fn mentions(&self) -> Vec<(Id, Option<RelayUrl>)>

If this event mentions others, get those other event Ids and optional recommended relay Urls

Source

pub fn reacts_to(&self) -> Option<(Id, String, Option<RelayUrl>)>

If this event reacts to another, get that other event’s Id, the reaction content, and an optional Recommended relay Url

Source

pub fn deletes(&self) -> Option<(Vec<Id>, String)>

If this event deletes others, get all the Ids of the events that it deletes along with the reason for the deletion

Source

pub fn client(&self) -> Option<String>

If this event specifies the client that created it, return that client string

Source

pub fn subject(&self) -> Option<String>

If this event specifies a subject, return that subject string

Source

pub fn content_warning(&self) -> Option<String>

If this event specifies a content warning, return that subject string

Source

pub fn hashtags(&self) -> Vec<String>

Return all the hashtags this event refers to

Source

pub fn urls(&self) -> Vec<RelayUrl>

Return all the URLs this event refers to

Source

pub fn pow(&self) -> u8

Get the proof-of-work count of leading bits

Source

pub fn delegation(&self) -> EventDelegation

Was this event delegated, was that valid, and if so what is the pubkey of the delegator?

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

Source§

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

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

impl<'de> Deserialize<'de> for Event

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Event

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Event

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Event

Source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,