filter

package
v1.0.23 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: Unlicense Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func Equal

func Equal(a, b *T) bool

func Present added in v1.0.4

func Present(i *uint) bool

Types

type B

type B = []byte

type Ctx

type Ctx = context.T

type E

type E = error

type N

type N = int

type S

type S = string

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  B            `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 error)

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 E)

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 B) (b B, err error)

func (*T) Matches

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

func (*T) Serialize

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

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 B) (r B, err error)

Jump to

Keyboard shortcuts

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