Add core packages, configuration system, and initial application structure
This commit is contained in:
47
pkg/encoders/event/event.go
Normal file
47
pkg/encoders/event/event.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package event
|
||||
|
||||
// E is the primary datatype of nostr. This is the form of the structure that
|
||||
// defines its JSON string-based format.
|
||||
type E struct {
|
||||
|
||||
// ID is the SHA256 hash of the canonical encoding of the event in binary format
|
||||
ID []byte
|
||||
|
||||
// Pubkey is the public key of the event creator in binary format
|
||||
Pubkey []byte
|
||||
|
||||
// CreatedAt is the UNIX timestamp of the event according to the event
|
||||
// creator (never trust a timestamp!)
|
||||
CreatedAt int64
|
||||
|
||||
// Kind is the nostr protocol code for the type of event. See kind.T
|
||||
Kind uint16
|
||||
|
||||
// Tags are a list of tags, which are a list of strings usually structured
|
||||
// as a 3-layer scheme indicating specific features of an event.
|
||||
Tags [][]byte
|
||||
|
||||
// Content is an arbitrary string that can contain anything, but usually
|
||||
// conforming to a specification relating to the Kind and the Tags.
|
||||
Content []byte
|
||||
|
||||
// Sig is the signature on the ID hash that validates as coming from the
|
||||
// Pubkey in binary format.
|
||||
Sig []byte
|
||||
}
|
||||
|
||||
// S is an array of event.E that sorts in reverse chronological order.
|
||||
type S []*E
|
||||
|
||||
// Len returns the length of the event.Es.
|
||||
func (ev S) Len() int { return len(ev) }
|
||||
|
||||
// Less returns whether the first is newer than the second (larger unix
|
||||
// timestamp).
|
||||
func (ev S) Less(i, j int) bool { return ev[i].CreatedAt > ev[j].CreatedAt }
|
||||
|
||||
// Swap two indexes of the event.Es with each other.
|
||||
func (ev S) Swap(i, j int) { ev[i], ev[j] = ev[j], ev[i] }
|
||||
|
||||
// C is a channel that carries event.E.
|
||||
type C chan *E
|
||||
10
pkg/encoders/event/examples/eventcache.go
Normal file
10
pkg/encoders/event/examples/eventcache.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// Package examples is an embedded jsonl format of a collection of events
|
||||
// intended to be used to test an event codec.
|
||||
package examples
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed out.jsonl
|
||||
var Cache []byte
|
||||
11596
pkg/encoders/event/examples/out.jsonl
Normal file
11596
pkg/encoders/event/examples/out.jsonl
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user