nostr_types

Struct EventV3

source
pub struct EventV3 {
    pub id: Id,
    pub pubkey: PublicKey,
    pub created_at: Unixtime,
    pub kind: EventKind,
    pub sig: Signature,
    pub content: String,
    pub tags: Vec<TagV3>,
}
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

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

§content: String

The content of the event

§tags: Vec<TagV3>

A set of tags that apply to the event

Implementations§

source§

impl EventV3

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 k_tag_kind(&self) -> Option<EventKind>

Get the k-tag kind, if any

source

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

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

source

pub fn is_tagged(&self, pk: &PublicKey) -> bool

If the pubkey is tagged in the event

source

pub fn people_referenced_in_content(&self) -> Vec<PublicKey>

If the event refers to people within the contents, get all the PublicKeys it refers to within the contents.

source

pub fn referred_events(&self) -> Vec<EventReference>

All events IDs that this event refers to, whether root, reply, mention, or otherwise along with optional recommended relay URLs

source

pub fn replies_to(&self) -> Option<EventReference>

Get a reference to another event that this event replies to. An event can only reply to one other event via ‘e’ or ‘a’ tag from a feed-displayable event that is not a Repost.

source

pub fn replies_to_root(&self) -> Option<EventReference>

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 quotes(&self) -> Vec<EventReference>

If this event quotes others, get those other events

source

pub fn mentions(&self) -> Vec<EventReference>

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

source

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

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<EventReference>, String)>

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

source

pub fn delete_author_allowed(&self, by: PublicKey) -> bool

Can this event be deleted by the given public key?

source

pub fn zaps(&self) -> Result<Option<ZapData>, Error>

If this event zaps another event, get data about that.

Errors returned from this are not fatal, but may be useful for explaining to a user why a zap receipt is invalid.

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 title(&self) -> Option<String>

If this event specifies a title, return that title string

source

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

If this event specifies a summary, return that summary string

source

pub fn is_annotation(&self) -> bool

Is this event an annotation

source

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

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

source

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

If this is a parameterized event, get the parameter

source

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

Return all the hashtags this event refers to

source

pub fn file_metadata(&self) -> Vec<FileMetadata>

Return all attached FileMetadata objects

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?

source

pub fn proxy(&self) -> Option<(String, String)>

If the event came through a proxy, get the (Protocol, Id)

source§

impl EventV3

source

pub fn get_id_from_speedy_bytes(bytes: &[u8]) -> Option<Id>

Read the ID of the event from a speedy encoding without decoding (zero allocation)

Note this function is fragile, if the Event structure is reordered, or if speedy code changes, this will break. Neither should happen.

source

pub fn get_pubkey_from_speedy_bytes(bytes: &[u8]) -> Option<PublicKey>

Read the pubkey of the event from a speedy encoding without decoding (close to zero allocation, VerifyingKey does stuff I didn’t check)

Note this function is fragile, if the Event structure is reordered, or if speedy code changes, this will break. Neither should happen.

source

pub fn get_created_at_from_speedy_bytes(bytes: &[u8]) -> Option<Unixtime>

Read the created_at of the event from a speedy encoding without decoding (zero allocation)

Note this function is fragile, if the Event structure is reordered, or if speedy code changes, this will break. Neither should happen.

source

pub fn get_kind_from_speedy_bytes(bytes: &[u8]) -> Option<EventKind>

Read the kind of the event from a speedy encoding without decoding (zero allocation)

Note this function is fragile, if the Event structure is reordered, or if speedy code changes, this will break. Neither should happen.

source

pub fn get_content_from_speedy_bytes(bytes: &[u8]) -> Option<&str>

Read the content of the event from a speedy encoding without decoding (zero allocation)

Note this function is fragile, if the Event structure is reordered, or if speedy code changes, this will break. Neither should happen.

source

pub fn tag_search_in_speedy_bytes( bytes: &[u8], re: &Regex, ) -> Result<bool, Error>

Check if any human-readable tag matches the Regex in the speedy encoding without decoding the whole thing (because our TagV3 representation is so complicated, we do deserialize the tags for now)

Note this function is fragile, if the Event structure is reordered, or if speedy code changes, this will break. Neither should happen.

Trait Implementations§

source§

impl Clone for EventV3

source§

fn clone(&self) -> EventV3

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 EventV3

source§

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

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

impl<'de> Deserialize<'de> for EventV3

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 From<EventV3> for RumorV3

source§

fn from(e: EventV3) -> RumorV3

Converts to this type from the input type.
source§

impl Ord for EventV3

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for EventV3

source§

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

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

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 PartialOrd for EventV3

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a_, C_: Context> Readable<'a_, C_> for EventV3

source§

fn read_from<R_: Reader<'a_, C_>>(_reader_: &mut R_) -> Result<Self, C_::Error>

source§

fn minimum_bytes_needed() -> usize

§

fn read_from_buffer_with_ctx( context: C, buffer: &'a [u8], ) -> Result<Self, <C as Context>::Error>

§

fn read_with_length_from_buffer_with_ctx( context: C, buffer: &'a [u8], ) -> (Result<Self, <C as Context>::Error>, usize)

§

fn read_from_buffer_copying_data_with_ctx( context: C, buffer: &[u8], ) -> Result<Self, <C as Context>::Error>

§

fn read_with_length_from_buffer_copying_data_with_ctx( context: C, buffer: &[u8], ) -> (Result<Self, <C as Context>::Error>, usize)

§

fn read_with_length_from_buffer_copying_data_with_ctx_mut( context: &mut C, buffer: &[u8], ) -> (Result<Self, <C as Context>::Error>, usize)

§

fn read_from_stream_unbuffered_with_ctx<S>( context: C, stream: S, ) -> Result<Self, <C as Context>::Error>
where S: Read,

§

fn read_from_stream_buffered_with_ctx<S>( context: C, stream: S, ) -> Result<Self, <C as Context>::Error>
where S: Read,

§

fn read_from_file_with_ctx( context: C, path: impl AsRef<Path>, ) -> Result<Self, <C as Context>::Error>

source§

impl Serialize for EventV3

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<C_: Context> Writable<C_> for EventV3

source§

fn write_to<T_: ?Sized + Writer<C_>>( &self, _writer_: &mut T_, ) -> Result<(), C_::Error>

§

fn write_to_buffer_with_ctx( &self, context: C, buffer: &mut [u8], ) -> Result<(), <C as Context>::Error>

§

fn write_to_buffer_with_ctx_mut( &self, context: &mut C, buffer: &mut [u8], ) -> Result<(), <C as Context>::Error>

§

fn write_to_vec_with_ctx( &self, context: C, ) -> Result<Vec<u8>, <C as Context>::Error>

§

fn write_to_vec_with_ctx_mut( &self, context: &mut C, ) -> Result<Vec<u8>, <C as Context>::Error>

§

fn write_to_stream_with_ctx<S>( &self, context: C, stream: S, ) -> Result<(), <C as Context>::Error>
where S: Write,

§

fn write_to_file_with_ctx( &self, context: C, path: impl AsRef<Path>, ) -> Result<(), <C as Context>::Error>

§

fn bytes_needed(&self) -> Result<usize, <C as Context>::Error>

source§

impl Eq for EventV3

source§

impl StructuralPartialEq for EventV3

Auto Trait Implementations§

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.
§

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

§

fn vzip(self) -> V

source§

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