Documentation
¶
Index ¶
- Variables
- func CheckExpiration(ev *event.E) (expired bool)
- func CreateIdHashFromData(data []byte) (i *types2.IdHash, err error)
- func CreatePubHashFromData(data []byte) (p *types2.PubHash, err error)
- func GetIndexesForEvent(ev *event.E, serial uint64) (idxs [][]byte, err error)
- func IsHexString(data []byte) (isHex bool)
- func NewLogger(logLevel int, label string) (l *logger)
- func TokenHashes(content []byte) [][]byte
- type D
- func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error)
- func (d *D) Close() (err error)
- func (d *D) CountEvents(c context.Context, f *filter.F) (count int, approx bool, err error)
- func (d *D) DeleteEvent(c context.Context, eid []byte) (err error)
- func (d *D) DeleteEventBySerial(c context.Context, ser *types.Uint40, ev *event.E) (err error)
- func (d *D) DeleteExpired()
- func (d *D) DeleteMarker(key string) (err error)
- func (d *D) EventIdsBySerial(start uint64, count int) (evs []uint64, err error)
- func (d *D) Export(c context.Context, w io.Writer, pubkeys ...[]byte)
- func (d *D) ExtendSubscription(pubkey []byte, days int) error
- func (d *D) FetchEventBySerial(ser *types.Uint40) (ev *event.E, err error)
- func (d *D) FetchEventsBySerials(serials []*types.Uint40) (events map[uint64]*event.E, err error)
- func (d *D) GetFullIdPubkeyBySerial(ser *types.Uint40) (fidpk *store.IdPkTs, err error)
- func (d *D) GetFullIdPubkeyBySerials(sers []*types.Uint40) (fidpks []*store.IdPkTs, err error)
- func (d *D) GetMarker(key string) (value []byte, err error)
- func (d *D) GetOrCreateRelayIdentitySecret() (skb []byte, err error)
- func (d *D) GetPaymentHistory(pubkey []byte) ([]Payment, error)
- func (d *D) GetRelayIdentitySecret() (skb []byte, err error)
- func (d *D) GetSerialById(id []byte) (ser *types.Uint40, err error)
- func (d *D) GetSerialsByIds(ids *tag.T) (serials map[string]*types.Uint40, err error)
- func (d *D) GetSerialsByIdsWithFilter(ids *tag.T, fn func(ev *event.E, ser *types.Uint40) bool) (serials map[string]*types.Uint40, err error)
- func (d *D) GetSerialsByRange(idx Range) (sers types.Uint40s, err error)
- func (d *D) GetSerialsFromFilter(f *filter.F) (sers types.Uint40s, err error)
- func (d *D) GetSubscription(pubkey []byte) (*Subscription, error)
- func (d *D) HasMarker(key string) (exists bool)
- func (d *D) Import(rr io.Reader)
- func (d *D) Init(path string) (err error)
- func (d *D) IsFirstTimeUser(pubkey []byte) (bool, error)
- func (d *D) IsSubscriptionActive(pubkey []byte) (bool, error)
- func (d *D) Path() string
- func (d *D) ProcessDelete(ev *event.E, admins [][]byte) (err error)
- func (d *D) QueryDeleteEventsByTargetId(c context.Context, targetEventId []byte) (evs event.S, err error)
- func (d *D) QueryEvents(c context.Context, f *filter.F) (evs event.S, err error)
- func (d *D) QueryEventsWithOptions(c context.Context, f *filter.F, includeDeleteEvents bool) (evs event.S, err error)
- func (d *D) QueryForIds(c context.Context, f *filter.F) (idPkTs []*store.IdPkTs, err error)
- func (d *D) QueryForSerials(c context.Context, f *filter.F) (sers types.Uint40s, err error)
- func (d *D) RecordPayment(pubkey []byte, amount int64, invoice, preimage string) error
- func (d *D) RunMigrations()
- func (d *D) SaveEvent(c context.Context, ev *event.E) (replaced bool, err error)
- func (d *D) SetLogLevel(level string)
- func (d *D) SetMarker(key string, value []byte) (err error)
- func (d *D) SetRelayIdentitySecret(skb []byte) (err error)
- func (d *D) Sync() (err error)
- func (d *D) UpdateExpirationTags()
- func (d *D) UpdateWordIndexes()
- func (d *D) Wipe() (err error)
- func (d *D) WouldReplaceEvent(ev *event.E) (bool, types.Uint40s, error)
- type Payment
- type Range
- type Subscription
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOlderThanExisting is returned when a candidate event is older than an existing replaceable/addressable event. ErrOlderThanExisting = errors.New("older than existing event") // ErrMissingDTag is returned when a parameterized replaceable event lacks the required 'd' tag. ErrMissingDTag = errors.New("event is missing a d tag identifier") )
Functions ¶
func CreateIdHashFromData ¶
CreateIdHashFromData creates an IdHash from data that could be hex or binary
func CreatePubHashFromData ¶
CreatePubHashFromData creates a PubHash from data that could be hex or binary
func GetIndexesForEvent ¶
GetIndexesForEvent creates all the indexes for an event.E instance as defined in keys.go. It returns a slice of byte slices that can be used to store the event in the database.
func IsHexString ¶
IsHexString checks if the byte slice contains only hex characters
func NewLogger ¶
NewLogger creates a new badger logger.
func TokenHashes ¶ added in v0.9.0
TokenHashes extracts unique word hashes (8-byte truncated sha256) from content. Rules: - Unicode-aware: words are sequences of letters or numbers. - Lowercased using unicode case mapping. - Ignore URLs (starting with http://, https://, www., or containing "://"). - Ignore nostr: URIs and #[n] mentions. - Ignore words shorter than 2 runes. - Exclude 64-character hexadecimal strings (likely IDs/pubkeys).
Types ¶
type D ¶
func New ¶
func (*D) CheckForDeleted ¶
CheckForDeleted checks if the event is deleted, and returns an error with prefix "blocked:" if it is. This function also allows designating admin pubkeys that also may delete the event, normally only the author is allowed to delete an event.
func (*D) CountEvents ¶ added in v0.10.0
CountEvents mirrors the initial selection logic of QueryEvents but stops once we have identified candidate event serials (id/pk/ts). It returns the count of those serials. The `approx` flag is always false as requested.
func (*D) DeleteEvent ¶
DeleteEvent removes an event from the database identified by `eid`. If noTombstone is false or not provided, a tombstone is created for the event.
func (*D) DeleteEventBySerial ¶
func (*D) DeleteMarker ¶ added in v0.6.0
DeleteMarker removes a marker from the database
func (*D) EventIdsBySerial ¶
func (*D) Export ¶
Export the complete database of stored events to an io.Writer in line structured minified JSON.
func (*D) FetchEventBySerial ¶
func (*D) FetchEventsBySerials ¶ added in v0.4.9
FetchEventsBySerials fetches multiple events by their serials in a single database transaction. Returns a map of serial uint64 value to event, only including successfully fetched events.
func (*D) GetFullIdPubkeyBySerial ¶
func (*D) GetFullIdPubkeyBySerials ¶
GetFullIdPubkeyBySerials seeks directly to each serial's prefix in the FullIdPubkey index. The input sers slice is expected to be sorted in ascending order, allowing efficient forward-only iteration via a single Badger iterator.
func (*D) GetMarker ¶ added in v0.6.0
GetMarker retrieves an arbitrary marker from the database
func (*D) GetOrCreateRelayIdentitySecret ¶ added in v0.8.0
GetOrCreateRelayIdentitySecret retrieves the existing relay identity secret key or creates and stores a new one if none exists.
func (*D) GetRelayIdentitySecret ¶ added in v0.8.0
GetRelayIdentitySecret returns the relay identity secret key bytes if present. If the key is not found, returns (nil, badger.ErrKeyNotFound).
func (*D) GetSerialsByIds ¶ added in v0.4.9
GetSerialsByIds takes a tag.T containing multiple IDs and returns a map of IDs to their corresponding serial numbers. It directly queries the IdPrefix index for matching IDs, which is more efficient than using GetIndexesFromFilter.
func (*D) GetSerialsByIdsWithFilter ¶ added in v0.4.9
func (d *D) GetSerialsByIdsWithFilter( ids *tag.T, fn func(ev *event.E, ser *types.Uint40) bool, ) (serials map[string]*types.Uint40, err error)
GetSerialsByIdsWithFilter takes a tag.T containing multiple IDs and returns a map of IDs to their corresponding serial numbers, applying a filter function to each event. The function directly creates ID index prefixes for efficient querying.
func (*D) GetSerialsByRange ¶
func (*D) GetSerialsFromFilter ¶
func (*D) GetSubscription ¶
func (d *D) GetSubscription(pubkey []byte) (*Subscription, error)
func (*D) HasMarker ¶ added in v0.6.0
HasMarker checks if a marker exists in the database
func (*D) Import ¶
Import a collection of events in line structured minified JSON format (JSONL).
func (*D) Init ¶
Init initializes the database with the given path.
func (*D) IsFirstTimeUser ¶ added in v0.8.0
IsFirstTimeUser checks if a user is logging in for the first time and marks them as seen
func (*D) Path ¶
Path returns the path where the database files are stored.
func (*D) QueryDeleteEventsByTargetId ¶ added in v0.14.0
func (d *D) QueryDeleteEventsByTargetId(c context.Context, targetEventId []byte) ( evs event.S, err error, )
QueryDeleteEventsByTargetId queries for delete events that target a specific event ID
func (*D) QueryEvents ¶
func (*D) QueryEventsWithOptions ¶ added in v0.14.0
func (*D) QueryForIds ¶
QueryForIds retrieves a list of IdPkTs based on the provided filter. It supports filtering by ranges and tags but disallows filtering by Ids. Results are sorted by timestamp in reverse chronological order by default. When a search query is present, results are ranked by a 50/50 blend of match count (how many distinct search terms matched) and recency. Returns an error if the filter contains Ids or if any operation fails.
func (*D) QueryForSerials ¶
QueryForSerials takes a filter and returns the serials of events that match, sorted in reverse chronological order.
func (*D) RecordPayment ¶
func (*D) SaveEvent ¶
SaveEvent saves an event to the database, generating all the necessary indexes.
func (*D) SetMarker ¶ added in v0.6.0
SetMarker stores an arbitrary marker in the database
func (*D) SetRelayIdentitySecret ¶ added in v0.8.0
SetRelayIdentitySecret stores the relay identity secret key bytes (expects 32 bytes).
func (*D) WouldReplaceEvent ¶ added in v0.10.5
WouldReplaceEvent checks if the provided event would replace existing events based on Nostr's replaceable or parameterized replaceable semantics. It returns true along with the serials of events that should be replaced if the candidate is newer-or-equal. If an existing event is newer, it returns (false, serials, ErrOlderThanExisting). If no conflicts exist, it returns (false, nil, nil).
type Payment ¶
type Range ¶
type Range struct {
Start, End []byte
}
func GetIndexesFromFilter ¶
GetIndexesFromFilter returns encoded indexes based on the given filter.
An error is returned if any input values are invalid during encoding.
The indexes are designed so that only one table needs to be iterated, being a complete set of combinations of all fields in the event, thus there is no need to decode events until they are to be delivered.
Source Files
¶
- count.go
- database.go
- delete-event.go
- delete-expired.go
- export.go
- fetch-event-by-serial.go
- fetch-events-by-serials.go
- get-fullidpubkey-by-serial.go
- get-fullidpubkey-by-serials.go
- get-indexes-for-event.go
- get-indexes-from-filter.go
- get-serial-by-id.go
- get-serials-by-range.go
- identity.go
- import.go
- logger.go
- markers.go
- migrations.go
- process-delete.go
- query-events.go
- query-for-deleted.go
- query-for-ids.go
- query-for-serials.go
- save-event.go
- subscriptions.go
- tokenize.go