Documentation ¶
Overview ¶
Package filters implements a Klaytn filtering system for blocks, transactions and log events.
Source Files
- api.go : provides public filter API functions to generate filters and use them to filter the result
- filter.go : implements basic filtering system based on bloom filter
- filter_system.go : provides subscription scheme to register and filter the specific events
Index ¶
- Variables
- func RPCMarshalHeader(head *types.Header, isEnabledEthTxTypeFork bool) map[string]interface{}
- type Backend
- type EventSystem
- type Filter
- type FilterCriteria
- type PublicFilterAPI
- func (api *PublicFilterAPI) Events() *EventSystem
- func (api *PublicFilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error)
- func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*types.Log, error)
- func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error)
- func (api *PublicFilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subscription, error)
- func (api *PublicFilterAPI) NewBlockFilter() rpc.ID
- func (api *PublicFilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error)
- func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error)
- func (api *PublicFilterAPI) NewPendingTransactionFilter() rpc.ID
- func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Subscription, error)
- func (api *PublicFilterAPI) UninstallFilter(id rpc.ID) bool
- type Subscription
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( GetLogsDeadline = 10 * time.Second // execution deadlines for getLogs and getFilterLogs APIs GetLogsMaxItems = int(10000) // maximum allowed number of return items for getLogs and getFilterLogs APIs )
var (
ErrInvalidSubscriptionID = errors.New("invalid id")
)
Functions ¶
Types ¶
type Backend ¶
type Backend interface { ChainDB() database.DBManager EventMux() *event.TypeMux HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) GetBlockReceipts(ctx context.Context, blockHash common.Hash) types.Receipts GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) SubscribeNewTxsEvent(chan<- blockchain.NewTxsEvent) event.Subscription SubscribeChainEvent(ch chan<- blockchain.ChainEvent) event.Subscription SubscribeRemovedLogsEvent(ch chan<- blockchain.RemovedLogsEvent) event.Subscription SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription BloomStatus() (uint64, uint64) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) ChainConfig() *params.ChainConfig }
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, backend Backend, lightMode bool) *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 klaytn.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(hashes chan []common.Hash) *Subscription
SubscribePendingTxs creates a subscription 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.
type FilterCriteria ¶
type FilterCriteria klaytn.FilterQuery
FilterCriteria represents a request to create a new filter. Same as klaytn.FilterQuery but with UnmarshalJSON() method.
func (*FilterCriteria) UnmarshalJSON ¶
func (args *FilterCriteria) UnmarshalJSON(data []byte) error
UnmarshalJSON sets *args fields with given data.
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 Klaytn protocol such als blocks, transactions and logs.
func NewPublicFilterAPI ¶
func NewPublicFilterAPI(backend Backend, lightMode bool) *PublicFilterAPI
NewPublicFilterAPI returns a new PublicFilterAPI instance.
func (*PublicFilterAPI) Events ¶ added in v1.8.0
func (api *PublicFilterAPI) Events() *EventSystem
Events return private field events of PublicFilterAPI.
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.
func (*PublicFilterAPI) GetFilterLogs ¶
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 (*PublicFilterAPI) GetLogs ¶
func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error)
GetLogs returns logs matching the given argument that are stored within the state.
func (*PublicFilterAPI) Logs ¶
func (api *PublicFilterAPI) 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 (*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.
func (*PublicFilterAPI) NewFilter ¶
func (api *PublicFilterAPI) 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 (*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 `klay_getFilterChanges` polling method that is also used for log filters.
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.
type Subscription ¶
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 // PendingLogsSubscription queries for logs in pending blocks PendingLogsSubscription // MinedAndPendingLogsSubscription queries for logs in mined and pending blocks. MinedAndPendingLogsSubscription // PendingTransactionsSubscription queries tx hashes for pending // transactions entering the pending state PendingTransactionsSubscription // BlocksSubscription queries hashes for blocks that are imported BlocksSubscription // LastSubscription keeps track of the last index LastIndexSubscription )