Documentation ¶
Index ¶
- Constants
- Variables
- type Backend
- type EventSystem
- type Filter
- type FilterApi
- func (filter *FilterApi) GetFilterChanges(id ID) (interface{}, error)
- func (filter *FilterApi) GetFilterLogs(id ID) ([]*types.Log, error)
- func (filter *FilterApi) GetLogs(crit FilterQuery) ([]*types.Log, error)
- func (filter *FilterApi) NewBlockFilter() ID
- func (filter *FilterApi) NewFilter(crit FilterQuery) (ID, error)
- func (filter *FilterApi) NewPendingTransactionFilter() ID
- func (filter *FilterApi) UninstallFilter(id ID) bool
- type FilterConfig
- type FilterQuery
- type FilterService
- func (service *FilterService) Api() []app.API
- func (service *FilterService) BloomStatus() (uint64, uint64)
- func (service *FilterService) CommandFlags() ([]cli.Command, []cli.Flag)
- func (service *FilterService) DefaultConfig() *FilterConfig
- func (service *FilterService) GetFilterChanges(id ID) (interface{}, error)
- func (service *FilterService) GetFilterLogs(ctx context.Context, id ID) ([]*types.Log, error)
- func (service *FilterService) GetLogs(ctx context.Context, crit FilterQuery) ([]*types.Log, error)
- func (service *FilterService) GetLogsByHash(ctx context.Context, blockHash crypto.Hash) ([][]*types.Log, error)
- func (service *FilterService) GetReceipts(ctx context.Context, blockHash crypto.Hash) (types.Receipts, error)
- func (service *FilterService) HeaderByHash(ctx context.Context, blockHash crypto.Hash) (*types.BlockHeader, error)
- func (service *FilterService) HeaderByNumber(ctx context.Context, blockNr common.BlockNumber) (*types.BlockHeader, error)
- func (service *FilterService) Init(executeContext *app.ExecuteContext) error
- func (service *FilterService) Name() string
- func (service *FilterService) NewBlockFilter() ID
- func (service *FilterService) NewFilter(crit FilterQuery) (ID, error)
- func (service *FilterService) NewPendingTransactionFilter() ID
- func (service *FilterService) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
- func (service *FilterService) Start(executeContext *app.ExecuteContext) error
- func (service *FilterService) Stop(executeContext *app.ExecuteContext) error
- func (service *FilterService) SubscribeChainEvent(ch chan<- *types.ChainEvent) event.Subscription
- func (service *FilterService) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
- func (service *FilterService) SubscribeNewTxsEvent(ch chan<- types.NewTxsEvent) event.Subscription
- func (service *FilterService) SubscribeRemovedLogsEvent(ch chan<- types.RemovedLogsEvent) event.Subscription
- func (service *FilterService) UninstallFilter(id ID) bool
- type FilterServiceInterface
- type ID
- type ServiceDatabase
- type Subscription
- type Type
Constants ¶
const (
MODULENAME = "filter"
)
Variables ¶
var ( DefaultConfig = &FilterConfig{ Enable: true, } )
var (
EnableFilterFlag = cli.BoolFlag{
Name: "enableFilter",
Usage: "enable Filter",
}
)
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface { HeaderByNumber(ctx context.Context, blockNr common.BlockNumber) (*types.BlockHeader, error) HeaderByHash(ctx context.Context, blockHash crypto.Hash) (*types.BlockHeader, error) GetReceipts(ctx context.Context, blockHash crypto.Hash) (types.Receipts, error) GetLogsByHash(ctx context.Context, blockHash crypto.Hash) ([][]*types.Log, error) SubscribeNewTxsEvent(chan<- types.NewTxsEvent) event.Subscription SubscribeChainEvent(ch chan<- *types.ChainEvent) event.Subscription SubscribeRemovedLogsEvent(ch chan<- types.RemovedLogsEvent) event.Subscription SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription BloomStatus() (uint64, uint64) 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.
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 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.BlockHeader) *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 []crypto.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
}
func NewBlockFilter ¶
func NewBlockFilter(backend Backend, block crypto.Hash, addresses []crypto.CommonAddress, topics [][]crypto.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 NewRangeFilter ¶
func NewRangeFilter(backend Backend, begin, end int64, addresses []crypto.CommonAddress, topics [][]crypto.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 FilterApi ¶
type FilterApi struct {
// contains filtered or unexported fields
}
func (*FilterApi) GetFilterChanges ¶
name: getFilterChanges usage: Polling method for a filter, which returns an array of logs which occurred since last poll. params: 1. QUANTITY - the filter id. return: Array - Array of log objects, or an empty array if nothing has changed since last poll. example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"filter_getFilterChanges","params":["0x16"], "id": 3}' -H "Content-Type:application/json" response:
{ "jsonrpc": "2.0", "id": 3, "result": [{ "logIndex": "0x1", // 1 "blockNumber":"0x1b4", // 436 "blockHash": "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d", "transactionHash": "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf", "transactionIndex": "0x0", // 0 "address": "0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d", "data":"0x0000000000000000000000000000000000000000000000000000000000000000", "topics": ["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"] },{ ... }] } }
func (*FilterApi) GetFilterLogs ¶
name: getFilterLogs usage: Returns an array of all logs matching filter with given id. params: 1. QUANTITY - The filter id. return: Array - Array of log objects, or an empty array if nothing has changed since last poll. example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"filter_getFilterLogs","params":["0x16"], "id": 3}' -H "Content-Type:application/json" response:
{ "jsonrpc": "2.0", "id": 3, "result": [{ "logIndex": "0x1", // 1 "blockNumber":"0x1b4", // 436 "blockHash": "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d", "transactionHash": "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf", "transactionIndex": "0x0", // 0 "address": "0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d", "data":"0x0000000000000000000000000000000000000000000000000000000000000000", "topics": ["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"] },{ ... }] } }
func (*FilterApi) GetLogs ¶
func (filter *FilterApi) GetLogs(crit FilterQuery) ([]*types.Log, error)
name: getLogs usage: Returns an array of all logs matching a given filter object. params: 1. Object - The filter options: fromBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions. toBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions. address: DATA|Array, 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate. topics: Array of DATA, - (optional) Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options. blockhash: DATA, 32 Bytes - (optional) , blockHash is a new filter option which restricts the logs returned to the single block with the 32-byte hash blockHash. Using blockHash is equivalent to fromBlock = toBlock = the block number with hash blockHash. If blockHash is present in the filter criteria, then neither fromBlock nor toBlock are allowed. return: Array - Array of log objects, or an empty array if nothing has changed since last poll. example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"filter_getLogs","params":[{"topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]}], "id": 3}' -H "Content-Type:application/json" response:
{ "jsonrpc": "2.0", "id": 3, "result": [{ "logIndex": "0x1", // 1 "blockNumber":"0x1b4", // 436 "blockHash": "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d", "transactionHash": "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf", "transactionIndex": "0x0", // 0 "address": "0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d", "data":"0x0000000000000000000000000000000000000000000000000000000000000000", "topics": ["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"] },{ ... }] } }
func (*FilterApi) NewBlockFilter ¶
name: newBlockFilter usage: Creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call filter_getFilterChanges. params: None return: QUANTITY - A filter id. example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"filter_newBlockFilter","params":[], "id": 3}' -H "Content-Type:application/json" response:
{ "jsonrpc": "2.0", "id": 3, "result": "0x1" } }
func (*FilterApi) NewFilter ¶
func (filter *FilterApi) NewFilter(crit FilterQuery) (ID, error)
name: newFilter usage: Creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call filter_getFilterChanges. params: 1. Object - The filter options: fromBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions. toBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions. address: DATA|Array, 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate. topics: Array of DATA, - (optional) Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options. return: QUANTITY - A filter id. example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"filter_newFilter","params":[{"topics":["0x0000000000000000000000000000000000000000000000000000000012341234"]}], "id": 3}' -H "Content-Type:application/json" response:
{ "jsonrpc": "2.0", "id": 3, "result": "0x1" } }
func (*FilterApi) NewPendingTransactionFilter ¶
name: newPendingTransactionFilter usage: Creates a filter in the node, to notify when new pending transactions arrive. To check if the state has changed, call filter_getFilterChanges. params: None return: QUANTITY - A filter id. example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"filter_newPendingTransactionFilter","params":[], "id": 3}' -H "Content-Type:application/json" response:
{ "jsonrpc": "2.0", "id": 3, "result": "0x1" } }
func (*FilterApi) UninstallFilter ¶
name: uninstallFilter usage: Uninstalls a filter with given id. Should always be called when watch is no longer needed. Additonally Filters timeout when they aren't requested with filter_getFilterChanges for a period of time. params: 1. QUANTITY - The filter id. return: Boolean - true if the filter was successfully uninstalled, otherwise false. example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"filter_uninstallFilter","params":["0xb"], "id": 3}' -H "Content-Type:application/json" response:
{ "jsonrpc": "2.0", "id": 3, "result": "0x1" } }
type FilterConfig ¶
type FilterConfig struct {
Enable bool `json:"enable"`
}
type FilterQuery ¶
type FilterQuery struct { BlockHash *crypto.Hash // used by eth_getLogs, return logs only from block with this hash FromBlock *big.Int // beginning of the queried range, nil means genesis block ToBlock *big.Int // end of the range, nil means latest block Addresses []crypto.CommonAddress // restricts matches to events created by specific contracts // The Topic list restricts matches to particular event topics. Each event has a list // of topics. Topics matches a prefix of that list. An empty element slice matches any // topic. Non-empty elements represent an alternative that matches any of the // contained topics. // // Examples: // {} or nil matches any topic list // {{A}} matches topic A in first position // {{}, {B}} matches any topic in first position AND B in second position // {{A}, {B}} matches topic A in first position AND B in second position // {{A, B}, {C, D}} matches topic (A OR B) in first position AND (C OR D) in second position Topics [][]crypto.Hash }
FilterQuery contains options for contract log filtering.
func (*FilterQuery) UnmarshalJSON ¶
func (args *FilterQuery) UnmarshalJSON(data []byte) error
UnmarshalJSON sets *args fields with given data.
type FilterService ¶
type FilterService struct { DatabaseService *database.DatabaseService `service:"database"` Notifier blockmgr.IBlockNotify `service:"blockmgr"` ChainService chain.ChainServiceInterface `service:"chain"` ChainIndexerService chain_indexer.ChainIndexerServiceInterface `service:"chain_indexer"` Config *FilterConfig // contains filtered or unexported fields }
func (*FilterService) Api ¶
func (service *FilterService) Api() []app.API
func (*FilterService) BloomStatus ¶
func (service *FilterService) BloomStatus() (uint64, uint64)
func (*FilterService) CommandFlags ¶
func (service *FilterService) CommandFlags() ([]cli.Command, []cli.Flag)
func (*FilterService) DefaultConfig ¶
func (service *FilterService) DefaultConfig() *FilterConfig
func (*FilterService) GetFilterChanges ¶
func (service *FilterService) GetFilterChanges(id 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 (*FilterService) 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.
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterlogs
func (*FilterService) GetLogs ¶
func (service *FilterService) GetLogs(ctx context.Context, crit FilterQuery) ([]*types.Log, error)
GetLogs returns logs matching the given argument that are stored within the state.
func (*FilterService) GetLogsByHash ¶
func (*FilterService) GetReceipts ¶
func (*FilterService) HeaderByHash ¶
func (service *FilterService) HeaderByHash(ctx context.Context, blockHash crypto.Hash) (*types.BlockHeader, error)
func (*FilterService) HeaderByNumber ¶
func (service *FilterService) HeaderByNumber(ctx context.Context, blockNr common.BlockNumber) (*types.BlockHeader, error)
func (*FilterService) Init ¶
func (service *FilterService) Init(executeContext *app.ExecuteContext) error
func (*FilterService) Name ¶
func (service *FilterService) Name() string
implement Service interface
func (*FilterService) NewBlockFilter ¶
func (service *FilterService) NewBlockFilter() 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 (*FilterService) NewFilter ¶
func (service *FilterService) NewFilter(crit FilterQuery) (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 (*FilterService) NewPendingTransactionFilter ¶
func (service *FilterService) NewPendingTransactionFilter() 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 (*FilterService) ServiceFilter ¶
func (service *FilterService) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
func (*FilterService) Start ¶
func (service *FilterService) Start(executeContext *app.ExecuteContext) error
func (*FilterService) Stop ¶
func (service *FilterService) Stop(executeContext *app.ExecuteContext) error
func (*FilterService) SubscribeChainEvent ¶
func (service *FilterService) SubscribeChainEvent(ch chan<- *types.ChainEvent) event.Subscription
func (*FilterService) SubscribeLogsEvent ¶
func (service *FilterService) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
func (*FilterService) SubscribeNewTxsEvent ¶
func (service *FilterService) SubscribeNewTxsEvent(ch chan<- types.NewTxsEvent) event.Subscription
func (*FilterService) SubscribeRemovedLogsEvent ¶
func (service *FilterService) SubscribeRemovedLogsEvent(ch chan<- types.RemovedLogsEvent) event.Subscription
func (*FilterService) UninstallFilter ¶
func (service *FilterService) UninstallFilter(id ID) bool
UninstallFilter removes the filter with the given filter id.
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_uninstallfilter
type FilterServiceInterface ¶
type ServiceDatabase ¶
type Subscription ¶
type Subscription struct { ID 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 // 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 )