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
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
impl Event
Sourcepub fn new_with_pow(
input: PreEvent,
privkey: &PrivateKey,
zero_bits: u8,
) -> Result<Event, Error>
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.
Sourcepub fn verify(&self, maxtime: Option<Unixtime>) -> Result<(), Error>
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.
Sourcepub fn new_set_metadata(
input: PreEvent,
privkey: &PrivateKey,
metadata: Metadata,
) -> Result<Event, Error>
pub fn new_set_metadata( input: PreEvent, privkey: &PrivateKey, metadata: Metadata, ) -> Result<Event, Error>
Create an event that sets Metadata
Sourcepub fn new_zap_request(
privkey: &PrivateKey,
recipient_pubkey: PublicKeyHex,
zapped_event: Option<Id>,
millisatoshis: u64,
relays: Vec<String>,
content: String,
) -> Result<Event, Error>
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.
Sourcepub fn decrypted_contents(
&self,
private_key: &PrivateKey,
) -> Result<String, Error>
pub fn decrypted_contents( &self, private_key: &PrivateKey, ) -> Result<String, Error>
If an event is an EncryptedDirectMessage, decrypt it’s contents
Sourcepub fn people(&self) -> Vec<(PublicKeyHex, Option<RelayUrl>, Option<String>)>
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
Sourcepub fn referenced_people(
&self,
) -> Vec<(PublicKeyHex, Option<RelayUrl>, Option<String>)>
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.
Sourcepub fn is_reply(&self) -> bool
👎Deprecated since 0.2.0: please use replies_to
instead
pub fn is_reply(&self) -> bool
replies_to
insteadIs the event a reply?
Sourcepub fn replies_to(&self) -> Option<(Id, Option<RelayUrl>)>
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
Sourcepub fn replies_to_root(&self) -> Option<(Id, Option<RelayUrl>)>
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
Sourcepub fn replies_to_ancestors(&self) -> Vec<(Id, Option<RelayUrl>)>
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.
Sourcepub fn mentions(&self) -> Vec<(Id, Option<RelayUrl>)>
pub fn mentions(&self) -> Vec<(Id, Option<RelayUrl>)>
If this event mentions others, get those other event Ids and optional recommended relay Urls
Sourcepub fn reacts_to(&self) -> Option<(Id, String, Option<RelayUrl>)>
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
Sourcepub fn deletes(&self) -> Option<(Vec<Id>, String)>
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
Sourcepub fn client(&self) -> Option<String>
pub fn client(&self) -> Option<String>
If this event specifies the client that created it, return that client string
Sourcepub fn subject(&self) -> Option<String>
pub fn subject(&self) -> Option<String>
If this event specifies a subject, return that subject string
Sourcepub fn content_warning(&self) -> Option<String>
pub fn content_warning(&self) -> Option<String>
If this event specifies a content warning, return that subject string
Return all the hashtags this event refers to
Sourcepub fn delegation(&self) -> EventDelegation
pub fn delegation(&self) -> EventDelegation
Was this event delegated, was that valid, and if so what is the pubkey of the delegator?