View Source NostrBasics.Event (NostrBasics v0.0.11)
Represents the basic structure of anything that's being sent to/from relays
Link to this section Summary
Functions
Adds an ID to an event that doesn't have one
Simplifies the creation of an event, adding the created_at and tags fields and requiring the bare minimum to do so
Creates an ID for an event that doesn't have one
Converts a NIP-01 JSON string decoded as a map by Jason into an %Event{}
A structure an event has to be converted to prior to being SHA256'd, mainly for ID creation
Converts a NIP-01 JSON string into a %Event{}
Link to this section Types
Link to this section Functions
Adds an ID to an event that doesn't have one
examples
Examples
iex> %NostrBasics.Event{
...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
...> created_at: ~U[2023-02-07 18:24:32Z],
...> kind: 1,
...> tags: [],
...> content: "this is the content"
...> }
...> |> NostrBasics.Event.add_id
%NostrBasics.Event{
id: "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
created_at: ~U[2023-02-07 18:24:32Z],
kind: 1,
tags: [],
content: "this is the content"
}
Simplifies the creation of an event, adding the created_at and tags fields and requiring the bare minimum to do so
examples
Examples
iex> now = DateTime.utc_now()
...> pubkey = <<0xEFC83F01C8FB309DF2C8866B8C7924CC8B6F0580AFDDE1D6E16E2B6107C2862C::256>>
...> event = NostrBasics.Event.create(1, "this is the content", pubkey)
...> %{event | created_at: now}
%NostrBasics.Event{
id: nil,
pubkey: <<0xefc83f01c8fb309df2c8866b8c7924cc8b6f0580afdde1d6e16e2b6107c2862c::256>>,
kind: 1,
created_at: now,
tags: [],
content: "this is the content",
sig: nil
}
Creates an ID for an event that doesn't have one
examples
Examples
iex> %NostrBasics.Event{
...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
...> created_at: ~U[2023-02-07 18:24:32Z],
...> kind: 1,
...> tags: [],
...> content: "this is the content"
...> }
...> |> NostrBasics.Event.create_id
"0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34"
Converts a NIP-01 JSON string decoded as a map by Jason into an %Event{}
examples
Examples
iex> %{
...> "content" => "this is the content",
...> "created_at" => 1675794272,
...> "id" => "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
...> "kind" => 1,
...> "pubkey" => "5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2",
...> "tags" => []
...> }
...> |> NostrBasics.Event.decode()
%NostrBasics.Event{
id: "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
created_at: ~U[2023-02-07 18:24:32Z],
kind: 1,
tags: [],
content: "this is the content"
}
A structure an event has to be converted to prior to being SHA256'd, mainly for ID creation
examples
Examples
iex> %NostrBasics.Event{
...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
...> created_at: ~U[2023-02-07 18:24:32Z],
...> kind: 1,
...> tags: [],
...> content: "this is the content"
...> }
...> |> NostrBasics.Event.json_for_id
~s([0,"5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2",1675794272,1,[],"this is the content"])
Converts a NIP-01 JSON string into a %Event{}
examples
Examples
iex> ~s({"id":"0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34","pubkey":"5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2","created_at":1675794272,"kind":1,"tags":[],"content":"this is the content"})
...> |> NostrBasics.Event.parse()
{
:ok,
%NostrBasics.Event{
id: "0f017fc299f6351efe9d5bfbfb36c0c7a1399627f9bec02c49b00d0ec98a5f34",
pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
created_at: ~U[2023-02-07 18:24:32Z],
kind: 1,
tags: [],
content: "this is the content"
}
}