Struct nostr::event::Event

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

Event struct

Implementations§

source§

impl Event

source

pub fn new<I, S>( id: EventId, public_key: PublicKey, created_at: Timestamp, kind: Kind, tags: I, content: S, sig: Signature ) -> Self
where I: IntoIterator<Item = Tag>, S: Into<String>,

Compose event

source

pub fn from_value(value: Value) -> Result<Self, Error>

Deserialize Event from Value

This method NOT verify the signature!

source

pub fn id(&self) -> EventId

Get event ID

source

pub fn author(&self) -> PublicKey

Get event author (pubkey field)

source

pub fn author_ref(&self) -> &PublicKey

Get event author reference (pubkey field)

source

pub fn created_at(&self) -> Timestamp

Get Timestamp of when the event was created

source

pub fn kind(&self) -> Kind

Get event Kind

source

pub fn tags(&self) -> &[Tag]

Get reference to event tags

source

pub fn iter_tags(&self) -> impl Iterator<Item = &Tag>

Iterate event tags

source

pub fn into_iter_tags(self) -> impl Iterator<Item = Tag>

Iterate and consume event tags

source

pub fn content(&self) -> &str

Get reference to event content

source

pub fn signature(&self) -> Signature

Get event signature

source

pub fn verify(&self) -> Result<(), Error>

Available on crate feature std only.

Verify both EventId and Signature

source

pub fn verify_with_ctx<C>(&self, secp: &Secp256k1<C>) -> Result<(), Error>
where C: Verification,

Verify EventId and Signature

source

pub fn verify_id(&self) -> Result<(), Error>

Verify if the EventId it’s composed correctly

source

pub fn verify_signature(&self) -> Result<(), Error>

Available on crate feature std only.

Verify only event Signature

source

pub fn verify_signature_with_ctx<C>( &self, secp: &Secp256k1<C> ) -> Result<(), Error>
where C: Verification,

Verify event Signature

source

pub fn check_pow(&self, difficulty: u8) -> bool

source

pub fn expiration(&self) -> Option<&Timestamp>

Get Timestamp expiration if set

source

pub fn is_expired(&self) -> bool

Available on crate feature std only.

Returns true if the event has an expiration tag that is expired. If an event has no Expiration tag, then it will return false.

https://github.com/nostr-protocol/nips/blob/master/40.md

source

pub fn is_expired_with_supplier<T>(&self, supplier: &T) -> bool
where T: TimeSupplier,

Returns true if the event has an expiration tag that is expired. If an event has no Expiration tag, then it will return false.

https://github.com/nostr-protocol/nips/blob/master/40.md

source

pub fn is_expired_at(&self, now: &Timestamp) -> bool

Returns true if the event has an expiration tag that is expired. If an event has no Expiration tag, then it will return false.

https://github.com/nostr-protocol/nips/blob/master/40.md

source

pub fn is_job_request(&self) -> bool

source

pub fn is_job_result(&self) -> bool

source

pub fn is_regular(&self) -> bool

source

pub fn is_replaceable(&self) -> bool

source

pub fn is_ephemeral(&self) -> bool

source

pub fn is_parameterized_replaceable(&self) -> bool

Check if event Kind is Parameterized replaceable

https://github.com/nostr-protocol/nips/blob/master/01.md

source

pub fn identifier(&self) -> Option<&str>

Extract identifier (d tag), if exists.

source

pub fn public_keys(&self) -> impl Iterator<Item = &PublicKey>

Extract public keys from tags (p tag)

This method extract ONLY TagStandard::PublicKey

source

pub fn event_ids(&self) -> impl Iterator<Item = &EventId>

Extract event IDs from tags (e tag)

This method extract ONLY TagStandard::Event

source

pub fn coordinates(&self) -> impl Iterator<Item = &Coordinate>

Extract coordinates from tags (a tag)

source

pub fn tags_indexes(&self) -> &TagsIndexes

Available on crate feature std only.

Get tags indexes

Trait Implementations§

source§

impl Clone for Event

source§

fn clone(&self) -> Event

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 Event

source§

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

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

impl Deref for Event

§

type Target = EventIntermediate

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
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 From<Event> for UnsignedEvent

source§

fn from(event: Event) -> Self

Converts to this type from the input type.
source§

impl Hash for Event

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl JsonUtil for Event

source§

fn from_json<T>(json: T) -> Result<Self, Self::Err>
where T: AsRef<[u8]>,

Deserialize Event from JSON

This method NOT verify the signature!

§

type Err = Error

Error
source§

fn as_json(&self) -> String

Serialize to JSON string Read more
source§

fn try_as_json(&self) -> Result<String, Self::Err>

Serialize to JSON string
source§

impl Ord for Event

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

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

impl PartialEq for Event

source§

fn eq(&self, other: &Self) -> 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 PartialOrd for Event

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
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 TryFrom<RawEvent> for Event

§

type Error = Error

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

fn try_from(raw: RawEvent) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq 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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

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

source§

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

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where 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 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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.
source§

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

source§

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

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