filters

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: GPL-3.0, LGPL-3.0 Imports: 19 Imported by: 8

Documentation

Overview

Package filters implements an ethereum filtering system for block, transactions and log events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	ChainDb() ethdb.Database
	HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)
	HeaderByHash(ctx context.Context, blockHash common.Hash) (*types.Header, error)
	GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error)
	GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
	GetLogs(ctx context.Context, blockHash common.Hash, number uint64) ([][]*types.Log, error)

	CurrentHeader() *types.Header
	ChainConfig() *params.ChainConfig
	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
	SubscribeChainAcceptedEvent(ch chan<- core.ChainEvent) event.Subscription
	SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
	SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
	SubscribeAcceptedLogsEvent(ch chan<- []*types.Log) event.Subscription

	SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription

	SubscribeAcceptedTransactionEvent(ch chan<- core.NewTxsEvent) event.Subscription

	BloomStatus() (uint64, uint64)
	ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

	// Added to the backend interface to support limiting of logs requests
	IsAllowUnfinalizedQueries() bool
	LastAcceptedBlock() *types.Block
	GetMaxBlocksPerRequest() int64
}

type Config added in v0.9.0

type Config struct {
	Timeout time.Duration // how long filters stay active (default: 5min)
}

Config represents the configuration of the filter system.

type EventSystem

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

EventSystem creates subscriptions, processes events and broadcasts them to the subscription which match the subscription criteria.

func NewEventSystem

func NewEventSystem(sys *FilterSystem) *EventSystem

NewEventSystem creates a new manager that listens for event on the given mux, parses and filters them. It uses the all map to retrieve filter changes. The work loop holds its own index that is used to forward events to filters.

The returned manager has a loop that needs to be stopped with the Stop function or by stopping the given mux.

func (*EventSystem) SubscribeAcceptedHeads added in v0.4.2

func (es *EventSystem) SubscribeAcceptedHeads(headers chan *types.Header) *Subscription

SubscribeAcceptedHeads creates a subscription that writes the header of an accepted block that is imported in the chain.

func (*EventSystem) SubscribeAcceptedLogs added in v0.4.2

func (es *EventSystem) SubscribeAcceptedLogs(crit interfaces.FilterQuery, logs chan []*types.Log) (*Subscription, error)

func (*EventSystem) SubscribeAcceptedTxs added in v0.5.0

func (es *EventSystem) SubscribeAcceptedTxs(txs chan []*types.Transaction) *Subscription

SubscribeAcceptedTxs creates a subscription that writes transactions for transactions have been accepted.

func (*EventSystem) SubscribeLogs

func (es *EventSystem) SubscribeLogs(crit interfaces.FilterQuery, logs chan []*types.Log) (*Subscription, error)

SubscribeLogs creates a subscription that will write all logs matching the given criteria to the given logs channel. Default value for the from and to block is "latest". If the fromBlock > toBlock an error is returned.

func (*EventSystem) SubscribeNewHeads

func (es *EventSystem) SubscribeNewHeads(headers chan *types.Header) *Subscription

SubscribeNewHeads creates a subscription that writes the header of a block that is imported in the chain.

func (*EventSystem) SubscribePendingTxs

func (es *EventSystem) SubscribePendingTxs(txs chan []*types.Transaction) *Subscription

SubscribePendingTxs creates a subscription that writes transactions for transactions that enter the transaction pool.

type Filter

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

Filter can be used to retrieve and filter logs.

func (*Filter) Logs

func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error)

Logs searches the blockchain for matching log entries, returning all from the first block that contains matches, updating the start of the filter accordingly.

type FilterAPI added in v0.8.14

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

FilterAPI offers support to create and manage filters. This will allow external clients to retrieve various information related to the Ethereum protocol such as blocks, transactions and logs.

func NewFilterAPI added in v0.8.14

func NewFilterAPI(system *FilterSystem) *FilterAPI

NewFilterAPI returns a new FilterAPI instance.

func (*FilterAPI) GetFilterChanges added in v0.8.14

func (api *FilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error)

GetFilterChanges returns the logs for the filter with the given id since last time it was called. This can be used for polling.

For pending transaction and block filters the result is []common.Hash. (pending)Log filters return []Log.

func (*FilterAPI) GetFilterLogs added in v0.8.14

func (api *FilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Log, error)

GetFilterLogs returns the logs for the filter with the given id. If the filter could not be found an empty array of logs is returned.

func (*FilterAPI) GetLogs added in v0.8.14

func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error)

GetLogs returns logs matching the given argument that are stored within the state.

func (*FilterAPI) Logs added in v0.8.14

func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subscription, error)

Logs creates a subscription that fires for all new log that match the given filter criteria.

func (*FilterAPI) NewAcceptedTransactions added in v0.8.14

func (api *FilterAPI) NewAcceptedTransactions(ctx context.Context, fullTx *bool) (*rpc.Subscription, error)

NewAcceptedTransactions creates a subscription that is triggered each time a transaction is accepted. If fullTx is true the full tx is sent to the client, otherwise the hash is sent.

func (*FilterAPI) NewBlockFilter added in v0.8.14

func (api *FilterAPI) NewBlockFilter() rpc.ID

NewBlockFilter creates a filter that fetches blocks that are imported into the chain. It is part of the filter package since polling goes with eth_getFilterChanges.

func (*FilterAPI) NewFilter added in v0.8.14

func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error)

NewFilter creates a new filter and returns the filter id. It can be used to retrieve logs when the state changes. This method cannot be used to fetch logs that are already stored in the state.

Default criteria for the from and to block are "latest". Using "latest" as block number will return logs for mined blocks. Using "pending" as block number returns logs for not yet mined (pending) blocks. In case logs are removed (chain reorg) previously returned logs are returned again but with the removed property set to true.

In case "fromBlock" > "toBlock" an error is returned.

func (*FilterAPI) NewHeads added in v0.8.14

func (api *FilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error)

NewHeads send a notification each time a new (header) block is appended to the chain.

func (*FilterAPI) NewPendingTransactionFilter added in v0.8.14

func (api *FilterAPI) NewPendingTransactionFilter(fullTx *bool) rpc.ID

NewPendingTransactionFilter creates a filter that fetches pending transactions as transactions enter the pending state.

It is part of the filter package because this filter can be used through the `eth_getFilterChanges` polling method that is also used for log filters.

func (*FilterAPI) NewPendingTransactions added in v0.8.14

func (api *FilterAPI) NewPendingTransactions(ctx context.Context, fullTx *bool) (*rpc.Subscription, error)

NewPendingTransactions creates a subscription that is triggered each time a transaction enters the transaction pool. If fullTx is true the full tx is sent to the client, otherwise the hash is sent.

func (*FilterAPI) UninstallFilter added in v0.8.14

func (api *FilterAPI) UninstallFilter(id rpc.ID) bool

UninstallFilter removes the filter with the given filter id.

type FilterCriteria

type FilterCriteria interfaces.FilterQuery

FilterCriteria represents a request to create a new filter. Same as interfaces.FilterQuery but with UnmarshalJSON() method.

func (*FilterCriteria) UnmarshalJSON

func (args *FilterCriteria) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *args fields with given data.

type FilterSystem added in v0.9.0

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

FilterSystem holds resources shared by all filters.

func NewFilterSystem added in v0.9.0

func NewFilterSystem(backend Backend, config Config) *FilterSystem

NewFilterSystem creates a filter system.

func (*FilterSystem) NewBlockFilter added in v0.9.0

func (sys *FilterSystem) NewBlockFilter(block common.Hash, addresses []common.Address, topics [][]common.Hash) *Filter

NewBlockFilter creates a new filter which directly inspects the contents of a block to figure out whether it is interesting or not.

func (*FilterSystem) NewRangeFilter added in v0.9.0

func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Address, topics [][]common.Hash) *Filter

NewRangeFilter creates a new filter which uses a bloom filter on blocks to figure out whether a particular block is interesting or not.

type Subscription

type Subscription struct {
	ID rpc.ID
	// contains filtered or unexported fields
}

Subscription is created when the client registers itself for a particular event.

func (*Subscription) Err

func (sub *Subscription) Err() <-chan error

Err returns a channel that is closed when unsubscribed.

func (*Subscription) Unsubscribe

func (sub *Subscription) Unsubscribe()

Unsubscribe uninstalls the subscription from the event broadcast loop.

type Type

type Type byte

Type determines the kind of filter and is used to put the filter in to the correct bucket when added.

const (
	// UnknownSubscription indicates an unknown subscription type
	UnknownSubscription Type = iota
	// LogsSubscription queries for new or removed (chain reorg) logs
	LogsSubscription
	// AcceptedLogsSubscription queries for new or removed (chain reorg) logs
	AcceptedLogsSubscription
	// PendingLogsSubscription queries for logs in pending blocks
	PendingLogsSubscription
	// MinedAndPendingLogsSubscription queries for logs in mined and pending blocks.
	MinedAndPendingLogsSubscription
	// PendingTransactionsSubscription queries for pending transactions entering
	// the pending state
	PendingTransactionsSubscription
	// AcceptedTransactionsSubscription queries for accepted transactions
	AcceptedTransactionsSubscription
	// BlocksSubscription queries hashes for blocks that are imported
	BlocksSubscription
	// AcceptedBlocksSubscription queries hashes for blocks that are accepted
	AcceptedBlocksSubscription
	// LastIndexSubscription keeps track of the last index
	LastIndexSubscription
)

Jump to

Keyboard shortcuts

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