filters

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Overview

Package filters specifies utilities for building a set of data attribute filters to be used when filtering data through database queries in practice. For example, one can specify a filter query for data by start epoch + end epoch + shard for attestations, build a filter as follows, and respond to it accordingly:

f := filters.NewFilter().SetStartEpoch(3).SetEndEpoch(5)
for k, v := range f.Filters() {
    switch k {
    case filters.StartEpoch:
       // Verify data matches filter criteria...
    case filters.EndEpoch:
       // Verify data matches filter criteria...
    }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterType

type FilterType int

FilterType defines an enum which is used as the keys in a map that tracks set attribute filters for data as part of the `FilterQuery` struct type.

const (
	// ParentRoot defines a filter for parent roots of blocks using Simple Serialize (SSZ).
	ParentRoot FilterType = 0
	// StartSlot is used for range filters of objects by their slot (inclusive).
	StartSlot FilterType = 1
	// EndSlot is used for range filters of objects by their slot (inclusive).
	EndSlot FilterType = 2
	// StartEpoch is used for range filters of objects by their epoch (inclusive).
	StartEpoch FilterType = 3
	// EndEpoch is used for range filters of objects by their epoch (inclusive).
	EndEpoch FilterType = 4
	// HeadBlockRoot defines a filter for the head block root attribute of objects.
	HeadBlockRoot FilterType = 5
	// SourceEpoch defines a filter for the source epoch attribute of objects.
	SourceEpoch FilterType = 6
	// SourceRoot defines a filter for the source root attribute of objects.
	SourceRoot FilterType = 7
	// TargetEpoch defines a filter for the target epoch attribute of objects.
	TargetEpoch FilterType = 8
	// TargetRoot defines a filter for the target root attribute of objects.
	TargetRoot FilterType = 9
	// SlotStep is used for range filters of objects by their slot in step increments.
	SlotStep FilterType = 10
)

type QueryFilter

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

QueryFilter defines a generic interface for type-asserting specific filters to use in querying DB objects.

func NewFilter

func NewFilter() *QueryFilter

NewFilter instantiates a new QueryFilter type used to build filters for certain eth2 data types by attribute.

func (*QueryFilter) Filters

func (q *QueryFilter) Filters() map[FilterType]interface{}

Filters returns and underlying map of FilterType to interface{}, giving us a copy of the currently set filters which can then be iterated over and type asserted for use anywhere.

func (*QueryFilter) SetEndEpoch

func (q *QueryFilter) SetEndEpoch(val uint64) *QueryFilter

SetEndEpoch enables filtering by the EndEpoch attribute of an object (inclusive).

func (*QueryFilter) SetEndSlot

func (q *QueryFilter) SetEndSlot(val uint64) *QueryFilter

SetEndSlot enables filtering by all the items that end at a slot (inclusive).

func (*QueryFilter) SetHeadBlockRoot

func (q *QueryFilter) SetHeadBlockRoot(val []byte) *QueryFilter

SetHeadBlockRoot allows for filtering by the beacon block root data attribute of an object.

func (*QueryFilter) SetParentRoot

func (q *QueryFilter) SetParentRoot(val []byte) *QueryFilter

SetParentRoot allows for filtering by the parent root data attribute of an object.

func (*QueryFilter) SetSlotStep added in v0.3.2

func (q *QueryFilter) SetSlotStep(val uint64) *QueryFilter

SetSlotStep enables filtering by slot for every step interval. For example, a slot range query for blocks from 0 to 9 with a step of 2 would return objects at slot 0, 2, 4, 6, 8.

func (*QueryFilter) SetSourceEpoch

func (q *QueryFilter) SetSourceEpoch(val uint64) *QueryFilter

SetSourceEpoch enables filtering by the source epoch data attribute of an object.

func (*QueryFilter) SetSourceRoot

func (q *QueryFilter) SetSourceRoot(val []byte) *QueryFilter

SetSourceRoot allows for filtering by the source root data attribute of an object.

func (*QueryFilter) SetStartEpoch

func (q *QueryFilter) SetStartEpoch(val uint64) *QueryFilter

SetStartEpoch enables filtering by the StartEpoch attribute of an object (inclusive).

func (*QueryFilter) SetStartSlot

func (q *QueryFilter) SetStartSlot(val uint64) *QueryFilter

SetStartSlot enables filtering by all the items that begin at a slot (inclusive).

func (*QueryFilter) SetTargetEpoch

func (q *QueryFilter) SetTargetEpoch(val uint64) *QueryFilter

SetTargetEpoch enables filtering by the target epoch data attribute of an object.

func (*QueryFilter) SetTargetRoot

func (q *QueryFilter) SetTargetRoot(val []byte) *QueryFilter

SetTargetRoot allows for filtering by the target root data attribute of an object.

Jump to

Keyboard shortcuts

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