filter

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: CC0-1.0 Imports: 16 Imported by: 1

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

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  B            `json:"search,omitempty"`
	Limit   int          `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 added in v0.1.6

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

func (f *T) String() (r S)

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