filters

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterLogs

func FilterLogs(logs []*ethtypes.Log, fromBlock, toBlock *big.Int, addresses []common.Address, topics [][]common.Hash) []*ethtypes.Log

filterLogs creates a slice of logs matching the given criteria. [] -> anything [A] -> A in first position of log topics, anything after [null, B] -> anything in first position, B in second position [A, B] -> A in first position and B in second position [[A, B], [A, B]] -> A or B in first position, A or B in second position

Types

type Backend

type Backend interface {
	GetBlockByNumber(blockNum rpctypes.BlockNumber, fullTx bool) (map[string]interface{}, error)
	HeaderByNumber(blockNr rpctypes.BlockNumber) (*ethtypes.Header, error)
	HeaderByHash(blockHash common.Hash) (*ethtypes.Header, error)
	GetLogs(blockHash common.Hash) ([][]*ethtypes.Log, error)

	GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error)
	BloomStatus() (uint64, uint64)
	ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
	GetSectionBloom(sections []uint64, filter uint) (*evmtypes.QuerySectionBloomRes, error)
}

Backend defines the methods requided by the PublicFilterAPI backend

type EthBackend

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

EthBackend implements the Backend interface

func New

func New(clientCtx clientcontext.Context) *EthBackend

New creates a new EthBackend instance

func (*EthBackend) BlockNumber

func (b *EthBackend) BlockNumber() (hexutil.Uint64, error)

BlockNumber returns the current block number.

func (*EthBackend) BloomStatus

func (b *EthBackend) BloomStatus() (uint64, uint64)

BloomStatus returns the BloomBitsBlocks and the number of processed sections maintained by the chain indexer.

func (*EthBackend) GetBlockByHash

func (b *EthBackend) GetBlockByHash(hash common.Hash, fullTx bool) (map[string]interface{}, error)

GetBlockByHash returns the block identified by hash.

func (*EthBackend) GetBlockByNumber

func (b *EthBackend) GetBlockByNumber(blockNum rpctypes.BlockNumber, fullTx bool) (map[string]interface{}, error)

GetBlockByNumber returns the block identified by number.

func (*EthBackend) GetLogs

func (b *EthBackend) GetLogs(blockHash common.Hash) ([][]*ethtypes.Log, error)

GetLogs returns all the logs from all the ethereum transactions in a block.

func (*EthBackend) GetSectionBloom

func (b *EthBackend) GetSectionBloom(sections []uint64, filter uint) (*evmtypes.QuerySectionBloomRes, error)

GetLogs returns all the logs from all the ethereum transactions in a block.

func (*EthBackend) GetTransactionLogs

func (b *EthBackend) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error)

GetTransactionLogs returns the logs given a transaction hash. It returns an error if there's an encoding error. If no logs are found for the tx hash, the error is nil.

func (*EthBackend) HeaderByHash

func (b *EthBackend) HeaderByHash(blockHash common.Hash) (*ethtypes.Header, error)

HeaderByHash returns the block header identified by hash.

func (*EthBackend) HeaderByNumber

func (b *EthBackend) HeaderByNumber(blockNum rpctypes.BlockNumber) (*ethtypes.Header, error)

HeaderByNumber returns the block header identified by height.

func (*EthBackend) PendingTransactions

func (b *EthBackend) PendingTransactions() ([]*rpctypes.Transaction, error)

PendingTransactions returns the transactions that are in the transaction pool and have a from address that is one of the accounts this node manages.

func (*EthBackend) ServiceFilter

func (b *EthBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

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 using the Tendermint's RPC clients.

func NewEventSystem

func NewEventSystem(client rpcclient.Client) *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) Check added in v1.5.29

func (es *EventSystem) Check(ctx context.Context) bool

func (*EventSystem) SubscribeLogs

func (es *EventSystem) SubscribeLogs(crit filters.FilterCriteria) (*Subscription, context.CancelFunc, 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() (*Subscription, context.CancelFunc, error)

SubscribeNewHeads subscribes to new block headers events.

func (EventSystem) SubscribePendingTxs

func (es EventSystem) SubscribePendingTxs() (*Subscription, context.CancelFunc, error)

SubscribePendingTxs subscribes to new pending transactions events from the mempool.

func (*EventSystem) WithContext

func (es *EventSystem) WithContext(ctx context.Context)

WithContext sets a new context to the EventSystem. This is required to set a timeout context when a new filter is intantiated.

type Filter

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

Filter can be used to retrieve and filter logs.

func NewBlockFilter

func NewBlockFilter(backend Backend, criteria filters.FilterCriteria) *Filter

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

func NewRangeFilter

func NewRangeFilter(backend Backend, 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.

func (*Filter) Logs

func (f *Filter) Logs(ctx context.Context) ([]*ethtypes.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 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 as blocks, transactions and logs.

func NewAPI

func NewAPI(clientCtx clientcontext.Context, backend Backend) *PublicFilterAPI

NewAPI returns a new PublicFilterAPI instance.

func (*PublicFilterAPI) GetFilterChanges

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

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

func (*PublicFilterAPI) GetFilterLogs

func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*ethtypes.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.

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

func (*PublicFilterAPI) GetLogs

func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit filters.FilterCriteria) ([]*ethtypes.Log, error)

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(criteria filters.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.

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 through 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 {
	// contains filtered or unexported fields
}

Subscription defines a wrapper for the private subscription

func (*Subscription) Err

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

Err returns the error channel

func (*Subscription) Event

func (s *Subscription) Event() <-chan coretypes.ResultEvent

Event returns the tendermint result event channel

func (Subscription) ID

func (s Subscription) ID() rpc.ID

ID returns the underlying subscription RPC identifier.

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe(es *EventSystem)

Unsubscribe to the current subscription from Tendermint Websocket. It sends an error to the subscription error channel if unsubscription fails.

Jump to

Keyboard shortcuts

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