filters

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2017 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSubscriptionID = errors.New("invalid id")
)

Functions

This section is empty.

Types

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(mux *event.TypeMux) *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) SubscribeLogs

func (es *EventSystem) SubscribeLogs(crit FilterCriteria, logs chan []Log) *Subscription

SubscribeLogs creates a subscription that will write all logs matching the given criteria to the given logs channel.

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

func (es *EventSystem) SubscribePendingLogs(crit FilterCriteria, logs chan []Log) *Subscription

SubscribePendingLogs creates a subscription that will write pending logs matching the given criteria to the given channel.

func (*EventSystem) SubscribePendingTxEvents

func (es *EventSystem) SubscribePendingTxEvents(hashes chan common.Hash) *Subscription

SubscribePendingTxEvents creates a sbuscription that writes transaction hashes 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 New

func New(db ethdb.Database) *Filter

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

func (*Filter) Find

func (f *Filter) Find() []Log

Run filters logs with the current parameters set

func (*Filter) SetAddresses

func (f *Filter) SetAddresses(addr []common.Address)

SetAddresses matches only logs that are generated from addresses that are included in the given addresses.

func (*Filter) SetBeginBlock

func (f *Filter) SetBeginBlock(begin int64)

SetBeginBlock sets the earliest block for filtering. -1 = latest block (i.e., the current block) hash = particular hash from-to

func (*Filter) SetEndBlock

func (f *Filter) SetEndBlock(end int64)

SetEndBlock sets the latest block for filtering.

func (*Filter) SetTopics

func (f *Filter) SetTopics(topics [][]common.Hash)

SetTopics matches only logs that have topics matching the given topics.

type FilterCriteria

type FilterCriteria struct {
	FromBlock *big.Int
	ToBlock   *big.Int
	Addresses []common.Address
	Topics    [][]common.Hash
}

FilterCriteria represents a request to create a new filter.

func (*FilterCriteria) UnmarshalJSON

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

UnmarshalJSON sets *args fields with given data.

type Log

type Log struct {
	*vm.Log
	Removed bool `json:"removed"`
}

Log is a helper that can hold additional information about vm.Log necessary for the RPC interface.

func (*Log) MarshalJSON

func (l *Log) MarshalJSON() ([]byte, error)

type PublicFilterAPI

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

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

func NewPublicFilterAPI

func NewPublicFilterAPI(chainDb ethdb.Database, mux *event.TypeMux) *PublicFilterAPI

NewPublicFilterAPI returns a new PublicFilterAPI instance.

func (*PublicFilterAPI) GetFilterChanges

func (api *PublicFilterAPI) GetFilterChanges(id rpc.ID) interface{}

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

For pending transaction and block filters the result is []common.Hash. (pending)Log filters return []Log. If the filter could not be found []interface{}{} is returned.

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterchanges

func (*PublicFilterAPI) GetFilterLogs

func (api *PublicFilterAPI) GetFilterLogs(id rpc.ID) []Log

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.

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterlogs

func (*PublicFilterAPI) GetLogs

func (api *PublicFilterAPI) GetLogs(crit FilterCriteria) []Log

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

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs

func (*PublicFilterAPI) Logs

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

func (*PublicFilterAPI) NewBlockFilter

func (api *PublicFilterAPI) 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.

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newblockfilter

func (*PublicFilterAPI) NewFilter

func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) rpc.ID

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.

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter

func (*PublicFilterAPI) NewHeads

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

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

func (*PublicFilterAPI) NewPendingTransactionFilter

func (api *PublicFilterAPI) NewPendingTransactionFilter() rpc.ID

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

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

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newpendingtransactionfilter

func (*PublicFilterAPI) NewPendingTransactions

func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Subscription, error)

NewPendingTransactions creates a subscription that is triggered each time a transaction enters the transaction pool and was signed from one of the transactions this nodes manages.

func (*PublicFilterAPI) UninstallFilter

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

UninstallFilter removes the filter with the given filter id.

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_uninstallfilter

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 unkown subscription type
	UnknownSubscription Type = iota
	// LogsSubscription queries for new or removed (chain reorg) logs
	LogsSubscription
	// PendingLogsSubscription queries for logs for the pending block
	PendingLogsSubscription
	// PendingTransactionsSubscription queries tx hashes for pending
	// transactions entering the pending state
	PendingTransactionsSubscription
	// BlocksSubscription queries hashes for blocks that are imported
	BlocksSubscription
)

Jump to

Keyboard shortcuts

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