filter

package
v1.2.31 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Unlicense Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	IDs     = by("ids")
	Kinds   = by("kinds")
	Authors = by("authors")
	Since   = by("since")
	Until   = by("until")
	Limit   = by("limit")
	Search  = by("search")
)

Functions

func Equal

func Equal(a, b *T) bo

func Present added in v1.0.4

func Present(i *uint) bo

Types

type T

type T struct {
	IDs     *tag.T       `json:"ids,omitempty"`
	Kinds   *kinds.T     `json:"kinds,omitempty"`
	Authors *tag.T       `json:"authors,omitempty"`
	Tags    *tags.T      `json:"-,omitempty"`
	Since   *timestamp.T `json:"since,omitempty"`
	Until   *timestamp.T `json:"until,omitempty"`
	Search  by           `json:"search,omitempty"`
	Limit   *uint        `json:"limit,omitempty"`
}

T is the primary query form for requesting events from a nostr relay.

The ordering of fields of filters is not specified as in the protocol there is no requirement to generate a hash for fast recognition of identical filters. However, for internal use in a relay, by applying a consistent sort order, this library will produce an identical JSON from the same *set* of fields no matter what order they were provided.

This is to facilitate the deduplication of filters so an effective identical match is not performed on an identical filter.

func GenFilter

func GenFilter() (f *T, err er)

func New

func New() (f *T)

func (*T) Clone

func (f *T) Clone() (clone *T)

Clone creates a new filter with all the same elements in them, because they are immutable, basically, except setting the Limit field as 1, because it is used in the subscription management code to act as a reference counter, and making a clone implicitly means 1 reference.

func (*T) Fingerprint

func (f *T) Fingerprint() (fp uint64, err er)

Fingerprint returns an 8 byte truncated sha256 hash of the filter in the canonical form created by MarshalJSON.

This hash is generated via the JSON encoded form of the filter, with the Limit field removed. This value should be set to zero after all results from a query of stored events, as per NIP-01.

func (*T) MarshalJSON

func (f *T) MarshalJSON(dst by) (b by, err er)

func (*T) Matches

func (f *T) Matches(ev *event.T) bo

func (*T) Serialize

func (f *T) Serialize() (b by)

func (*T) Sort

func (f *T) Sort()

Sort the fields of a filter so a fingerprint on a filter that has the same set of content produces the same fingerprint.

func (*T) UnmarshalJSON

func (f *T) UnmarshalJSON(b by) (r by, err er)

Jump to

Keyboard shortcuts

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