filters

package
v0.0.0-...-92cc422 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

包过滤器为块实现以太坊过滤系统, 事务和日志事件。

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Backend

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

	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
	SubscribeRemovedLogsEvent(ch chan<- core.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创建订阅、处理事件并将其广播到 符合订阅条件的订阅。

func NewEventSystem

func NewEventSystem(mux *event.TypeMux, backend Backend, lightMode bool) *EventSystem

newEventSystem创建一个新的管理器,用于侦听给定mux上的事件, 分析并过滤它们。它使用全部映射来检索过滤器更改。这个 工作循环保存自己的索引,用于将事件转发到筛选器。

返回的管理器有一个需要用stop函数停止的循环 或者停止给定的多路复用器。

func (*EventSystem) SubscribeLogs

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

subscriptLogs创建一个订阅,该订阅将写入与 给定日志通道的给定条件。从和到的默认值 块为“最新”。如果FromBlock>ToBlock,则返回错误。

func (*EventSystem) SubscribeNewHeads

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

SUBSCRIBENEWEADS创建一个订阅,该订阅写入的块头为 进口链。

func (*EventSystem) SubscribePendingTxs

func (es *EventSystem) SubscribePendingTxs(hashes chan []common.Hash) *Subscription

订阅BuffixTxs创建一个订阅事务哈希的订阅。 进入事务池的事务。

type Filter

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

筛选器可用于检索和筛选日志。

func NewBlockFilter

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

newblockfilter创建一个新的过滤器,它直接检查 用来判断它是否有趣的块。

func NewRangeFilter

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

newrangefilter创建一个新的过滤器,它在块上使用bloom过滤器来 找出一个特定的块是否有趣。

func (*Filter) Logs

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

日志在区块链中搜索匹配的日志条目,从 包含匹配项的第一个块,相应地更新筛选器的开头。

type FilterCriteria

type FilterCriteria ethereum.FilterQuery

FilterCriteria表示创建新筛选器的请求。 与ethereum.filterquery相同,但使用unmashaljson()方法。

func (*FilterCriteria) UnmarshalJSON

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

用给定的数据取消标记JSON集合*参数字段。

type PublicFilterAPI

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

publicfilterapi提供创建和管理过滤器的支持。这将允许外部客户端检索 与以太坊协议相关的信息,如ALS块、事务和日志。

func NewPublicFilterAPI

func NewPublicFilterAPI(backend Backend, lightMode bool) *PublicFilterAPI

new publicfilterapi返回新的publicfilterapi实例。

func (*PublicFilterAPI) GetFilterChanges

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

GetFilterChanges返回具有给定ID的筛选器的日志,自 上次打电话的时候。这可以用于轮询。

对于挂起的事务和块筛选器,结果是[]common.hash。 (挂起)日志筛选器返回[]日志。

https://github.com/ethereum/wiki/wiki/json-rpc_eth_getfilterchanges

func (*PublicFilterAPI) GetFilterLogs

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

GetFilterLogs返回具有给定ID的筛选器的日志。 如果找不到筛选器,则返回一个空的日志数组。

https://github.com/ethereum/wiki/wiki/json-rpc_eth_getfilterlogs

func (*PublicFilterAPI) GetLogs

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

GetLogs返回与存储在状态中的给定参数匹配的日志。

https://github.com/ethereum/wiki/wiki/json-rpc eth getlogs

func (*PublicFilterAPI) Logs

日志创建一个订阅,该订阅为所有符合给定筛选条件的新日志激发。

func (*PublicFilterAPI) NewBlockFilter

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

newblockfilter创建一个过滤器,用于获取导入到链中的块。 它是筛选包的一部分,因为轮询与ethgetfilterchanges一起进行。

https://github.com/ethereum/wiki/wiki/json-rpc eth newblockfilter

func (*PublicFilterAPI) NewFilter

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

new filter创建新的筛选器并返回筛选器ID。它可以是 用于在状态更改时检索日志。此方法不能 用于获取已存储在状态中的日志。

“从”和“到”块的默认条件为“最新”。 使用“最新”作为块号将返回已开采块的日志。 使用“挂起”作为块号返回尚未挖掘(挂起)块的日志。 如果日志被删除(链ReRoG),则返回以前返回的日志。 再次,但将移除的属性设置为true。

如果“fromblock”>toblock,则返回错误。

https://github.com/ethereum/wiki/wiki/json-rpc_eth_newfilter

func (*PublicFilterAPI) NewHeads

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

每当新(header)块附加到链时,newheads都会发送通知。

func (*PublicFilterAPI) NewPendingTransactionFilter

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

NewPendingtTransactionFilter创建一个筛选器,用于获取挂起的事务哈希 当事务进入挂起状态时。

它是筛选器包的一部分,因为此筛选器可以通过 “eth”getfilterchanges“轮询方法,也用于日志筛选器。

https://github.com/ethereum/wiki/wiki/json-rpc_eth_newpendingtransactionfilter

func (*PublicFilterAPI) NewPendingTransactions

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

NewPendingtTransactions创建每次事务触发的订阅 进入事务池,并从该节点管理的事务之一签名。

func (*PublicFilterAPI) UninstallFilter

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

uninstallfilter删除具有给定筛选器ID的筛选器。

https://github.com/ethereum/wiki/wiki/json-rpc_eth_卸载过滤器

type Subscription

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

订阅是在客户端为特定事件注册自身时创建的。

func (*Subscription) Err

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

err返回在取消订阅时关闭的通道。

func (*Subscription) Unsubscribe

func (sub *Subscription) Unsubscribe()

取消订阅从事件广播循环中卸载订阅。

type Type

type Type byte

类型确定筛选器的类型,并用于将筛选器放入 添加正确的桶。

const (
	//UnknownSubscription表示未知的订阅类型
	UnknownSubscription Type = iota
	//新日志或已删除日志的日志订阅查询(chain reorg)
	LogsSubscription
	//PendingLogs对挂起块中的日志的订阅查询
	PendingLogsSubscription
	//MinedAndPendingLogs对挖掘和挂起块中的日志的订阅查询。
	MinedAndPendingLogsSubscription
	//PendingtTransactionsSubscription查询待处理的Tx哈希
	//进入挂起状态的事务
	PendingTransactionsSubscription
	//块订阅查询导入块的哈希
	BlocksSubscription
	//LastSubscription跟踪最后一个索引
	LastIndexSubscription
)

Jump to

Keyboard shortcuts

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