store

package
v0.48.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2026 License: Unlicense Imports: 11 Imported by: 0

Documentation

Overview

Package store is an interface and ancillary helpers and types for defining a series of API elements for abstracting the event storage from the implementation.

It is composed so that the top-level interface can be partially implemented if need be.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDupEvent       = errors.New("duplicate: event already exists")
	ErrEventNotExists = errors.New("unknown: event not known by any source of this realy")
)

Functions

This section is empty.

Types

type Accountant

type Accountant interface {
	EventCount() (count uint64, err error)
}

type Configuration

type Configuration struct {
	BlockList []string `json:"block_list" doc:"list of IP addresses that will be ignored"`
}

type Configurationer

type Configurationer interface {
	GetConfiguration() (c config.C, err error)
	SetConfiguration(c config.C) (err error)
}

type Deleter

type Deleter interface {
	// DeleteEvent is used to handle deletion events, as per NIP-09.
	DeleteEvent(c context.Context, ev []byte) (err error)
}

type EventIdSerialer

type EventIdSerialer interface {
	EventIdsBySerial(start uint64, count int) (
		evs [][]byte,
		err error,
	)
}

type EventRef added in v0.36.11

type EventRef struct {
	// contains filtered or unexported fields
}

EventRef is a stack-friendly event reference using fixed-size arrays. Total size: 80 bytes (32+32+8+8), fits in a cache line, copies stay on stack. Use this type when you need safe, immutable event references.

func NewEventRef added in v0.36.11

func NewEventRef(id, pub []byte, ts int64, ser uint64) EventRef

NewEventRef creates an EventRef from byte slices. The slices are copied into fixed-size arrays.

func (EventRef) ID added in v0.36.11

func (r EventRef) ID() ntypes.EventID

ID returns the event ID (copy, stays on stack).

func (EventRef) IDHex added in v0.36.11

func (r EventRef) IDHex() string

IDHex returns the event ID as lowercase hex.

func (*EventRef) IDSlice added in v0.36.11

func (r *EventRef) IDSlice() []byte

IDSlice returns a slice view of the ID (shares memory, use carefully).

func (EventRef) Pub added in v0.36.11

func (r EventRef) Pub() ntypes.Pubkey

Pub returns the pubkey (copy, stays on stack).

func (EventRef) PubHex added in v0.36.11

func (r EventRef) PubHex() string

PubHex returns the pubkey as lowercase hex.

func (*EventRef) PubSlice added in v0.36.11

func (r *EventRef) PubSlice() []byte

PubSlice returns a slice view of the pubkey (shares memory, use carefully).

func (EventRef) Ser added in v0.36.11

func (r EventRef) Ser() uint64

Ser returns the serial number.

func (EventRef) ToIdPkTs added in v0.36.11

func (r EventRef) ToIdPkTs() *IdPkTs

ToIdPkTs converts EventRef to IdPkTs for backward compatibility. Note: This allocates new slices.

func (EventRef) Ts added in v0.36.11

func (r EventRef) Ts() int64

Ts returns the timestamp.

type Exporter

type Exporter interface {
	// Export writes a stream of line structured JSON of all events in the
	// store.
	//
	// If pubkeys are present, only those with these pubkeys in the `pubkey`
	// field and in `p` tags will be included.
	Export(c context.Context, w io.Writer, pubkeys ...[]byte)
}

type GetIdsWriter

type GetIdsWriter interface {
	FetchIds(c context.Context, evIds *tag.T, out io.Writer) (err error)
}

type I

I am a type for a persistence layer for nostr events handled by a relay.

type IdPkTs

type IdPkTs struct {
	Id  []byte
	Pub []byte
	Ts  int64
	Ser uint64
}

IdPkTs holds event reference data with slice fields for backward compatibility. For new code preferring stack-allocated, copy-on-assignment semantics, use the IDFixed() and PubFixed() methods or convert to EventRef.

func (*IdPkTs) IDFixed added in v0.36.11

func (i *IdPkTs) IDFixed() ntypes.EventID

IDFixed returns the event ID as a fixed-size array (stack-allocated, copied on assignment).

func (*IdPkTs) IDHex added in v0.36.11

func (i *IdPkTs) IDHex() string

IDHex returns the event ID as a lowercase hex string.

func (*IdPkTs) PubFixed added in v0.36.11

func (i *IdPkTs) PubFixed() ntypes.Pubkey

PubFixed returns the pubkey as a fixed-size array (stack-allocated, copied on assignment).

func (*IdPkTs) PubHex added in v0.36.11

func (i *IdPkTs) PubHex() string

PubHex returns the pubkey as a lowercase hex string.

func (*IdPkTs) ToEventRef added in v0.36.11

func (i *IdPkTs) ToEventRef() EventRef

ToEventRef converts IdPkTs to an EventRef (fully stack-allocated).

type Importer

type Importer interface {
	// Import reads in a stream of line-structured JSON the events to save into
	// the store.
	Import(r io.Reader)
}

type Initer

type Initer interface {
	Init(path string) (err error)
}

type LogLeveler

type LogLeveler interface {
	SetLogLevel(level string)
}

type OK

type OK = okenvelope.T

type Pather

type Pather interface {
	// Path returns the directory of the database.
	Path() (s string)
}

type Querent

type Querent interface {
	// QueryEvents is invoked upon a client's REQ as described in NIP-01. It
	// returns the matching events in reverse chronological order in a slice.
	QueryEvents(c context.Context, f *filter.F) (evs event.S, err error)
}

type Querier

type Querier interface {
	QueryForIds(c context.Context, f *filter.F) (evs []*IdPkTs, err error)
}

type Req

type Req = *http.Request

type Rescanner

type Rescanner interface {
	// Rescan triggers the regeneration of indexes of the database to enable old
	// records to be found with new indexes.
	Rescan() (err error)
}

type Responder

type Responder = http.ResponseWriter

type Saver

type Saver interface {
	// SaveEvent is called once relay.AcceptEvent reports true. The owners
	// parameter is for designating admins whose delete by e tag events apply
	// the same as author's own.
	SaveEvent(c context.Context, ev *event.E) (replaced bool, err error)
}

type SerialByIder

type SerialByIder interface {
	GetSerialById(id []byte) (ser *types.Uint40, err error)
}

type Syncer

type Syncer interface {
	// Sync signals the event store to flush its buffers.
	Sync() (err error)
}

type Wiper

type Wiper interface {
	// Wipe deletes everything in the database.
	Wipe() (err error)
}

Source Files

  • alias.go
  • errors.go
  • store_interface.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL