Documentation ¶
Index ¶
- Variables
- func CreateHistoryStateReader(tx kv.Tx, txNumsReader rawdbv3.TxNumsReader, blockNumber uint64, txnIndex int, ...) (state.StateReader, error)
- func CreateLatestCachedStateReader(cache kvcache.CacheView, tx kv.Tx) state.StateReader
- func CreateStateReader(ctx context.Context, tx kv.Tx, br services.FullBlockReader, ...) (state.StateReader, error)
- func CreateStateReaderFromBlockNumber(ctx context.Context, tx kv.Tx, txNumsReader rawdbv3.TxNumsReader, ...) (state.StateReader, error)
- func GetBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, tx kv.Tx, ...) (uint64, libcommon.Hash, bool, error)
- func GetCanonicalBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, tx kv.Tx, ...) (uint64, libcommon.Hash, bool, error)
- func GetFinalizedBlockNumber(tx kv.Tx) (uint64, error)
- func GetLatestBlockNumber(tx kv.Tx) (uint64, error)
- func GetLatestExecutedBlockNumber(tx kv.Tx) (uint64, error)
- func GetSafeBlockNumber(tx kv.Tx) (uint64, error)
- func NewLatestStateReader(tx kv.Tx) state.StateReader
- func NewLatestStateWriter(txc wrap.TxContainer, blockReader services.FullBlockReader, blockNum uint64) state.StateWriter
- type ApiBackend
- type Filters
- func (ff *Filters) AddLogs(id LogsSubID, log *types.Log)
- func (ff *Filters) AddPendingBlock(id HeadsSubID, block *types.Header)
- func (ff *Filters) AddPendingTxs(id PendingTxsSubID, txs []types.Transaction)
- func (ff *Filters) HandlePendingBlock(reply *txpool.OnPendingBlockReply)
- func (ff *Filters) HandlePendingLogs(reply *txpool.OnPendingLogsReply)
- func (ff *Filters) LastPendingBlock() *types.Block
- func (ff *Filters) OnNewEvent(event *remote.SubscribeReply)
- func (ff *Filters) OnNewLogs(reply *remote.SubscribeLogsReply)
- func (ff *Filters) OnNewTx(reply *txpool.OnAddReply)
- func (ff *Filters) ReadLogs(id LogsSubID) ([]*types.Log, bool)
- func (ff *Filters) ReadPendingBlocks(id HeadsSubID) ([]*types.Header, bool)
- func (ff *Filters) ReadPendingTxs(id PendingTxsSubID) ([][]types.Transaction, bool)
- func (ff *Filters) SubscribeLogs(size int, criteria filters.FilterCriteria) (<-chan *types.Log, LogsSubID)
- func (ff *Filters) SubscribeNewHeads(size int) (<-chan *types.Header, HeadsSubID)
- func (ff *Filters) SubscribePendingBlock(size int) (<-chan *types.Block, PendingBlockSubID)
- func (ff *Filters) SubscribePendingLogs(size int) (<-chan types.Logs, PendingLogsSubID)
- func (ff *Filters) SubscribePendingTxs(size int) (<-chan []types.Transaction, PendingTxsSubID)
- func (ff *Filters) UnsubscribeHeads(id HeadsSubID) bool
- func (ff *Filters) UnsubscribeLogs(id LogsSubID) bool
- func (ff *Filters) UnsubscribePendingBlock(id PendingBlockSubID)
- func (ff *Filters) UnsubscribePendingLogs(id PendingLogsSubID)
- func (ff *Filters) UnsubscribePendingTxs(id PendingTxsSubID) bool
- type FiltersConfig
- type HeadsSubID
- type LogsFilter
- type LogsFilterAggregator
- type LogsSubID
- type PendingBlockSubID
- type PendingLogsSubID
- type PendingTxsSubID
- type Sub
- type SubscriptionID
Constants ¶
This section is empty.
Variables ¶
var DefaultFiltersConfig = FiltersConfig{
RpcSubscriptionFiltersMaxLogs: 0,
RpcSubscriptionFiltersMaxHeaders: 0,
RpcSubscriptionFiltersMaxTxs: 0,
RpcSubscriptionFiltersMaxAddresses: 0,
RpcSubscriptionFiltersMaxTopics: 0,
}
DefaultFiltersConfig defines the default settings for filter configurations. These default values set no limits on the number of logs, block headers, transactions, addresses, or topics that can be stored per subscription.
var UnknownBlockError = &rpc.CustomError{
Code: -39001,
Message: "Unknown block",
}
Functions ¶
func CreateHistoryStateReader ¶
func CreateHistoryStateReader(tx kv.Tx, txNumsReader rawdbv3.TxNumsReader, blockNumber uint64, txnIndex int, chainName string) (state.StateReader, error)
func CreateStateReader ¶
func GetBlockNumber ¶
func GetCanonicalBlockNumber ¶
func NewLatestStateReader ¶
func NewLatestStateReader(tx kv.Tx) state.StateReader
func NewLatestStateWriter ¶
func NewLatestStateWriter(txc wrap.TxContainer, blockReader services.FullBlockReader, blockNum uint64) state.StateWriter
Types ¶
type ApiBackend ¶
type ApiBackend interface { Etherbase(ctx context.Context) (libcommon.Address, error) NetVersion(ctx context.Context) (uint64, error) NetPeerCount(ctx context.Context) (uint64, error) ProtocolVersion(ctx context.Context) (uint64, error) ClientVersion(ctx context.Context) (string, error) Subscribe(ctx context.Context, cb func(*remote.SubscribeReply)) error SubscribeLogs(ctx context.Context, cb func(*remote.SubscribeLogsReply), requestor *atomic.Value) error BlockWithSenders(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (block *types.Block, senders []libcommon.Address, err error) NodeInfo(ctx context.Context, limit uint32) ([]p2p.NodeInfo, error) Peers(ctx context.Context) ([]*p2p.PeerInfo, error) AddPeer(ctx context.Context, url *remote.AddPeerRequest) (*remote.AddPeerReply, error) PendingBlock(ctx context.Context) (*types.Block, error) }
ApiBackend - interface which must be used by API layer implementation can work with local Ethereum object or with Remote (grpc-based) one this is reason why all methods are accepting context and returning error
type Filters ¶
type Filters struct {
// contains filtered or unexported fields
}
Filters holds the state for managing subscriptions to various Ethereum events. It allows for the subscription and management of events such as new blocks, pending transactions, logs, and other Ethereum-related activities.
func New ¶
func New(ctx context.Context, config FiltersConfig, ethBackend ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient, onNewSnapshot func(), logger log.Logger) *Filters
New creates a new Filters instance, initializes it, and starts subscription goroutines for Ethereum events. It requires a context, Ethereum backend, transaction pool client, mining client, snapshot callback function, and a logger for logging events.
func (*Filters) AddPendingBlock ¶
func (ff *Filters) AddPendingBlock(id HeadsSubID, block *types.Header)
AddPendingBlock adds a pending block header to the store associated with the given subscription ID.
func (*Filters) AddPendingTxs ¶
func (ff *Filters) AddPendingTxs(id PendingTxsSubID, txs []types.Transaction)
AddPendingTxs adds pending transactions to the store associated with the given subscription ID.
func (*Filters) HandlePendingBlock ¶
func (ff *Filters) HandlePendingBlock(reply *txpool.OnPendingBlockReply)
HandlePendingBlock handles a new pending block received from the mining client. It updates the internal state and notifies subscribers about the new block.
func (*Filters) HandlePendingLogs ¶
func (ff *Filters) HandlePendingLogs(reply *txpool.OnPendingLogsReply)
HandlePendingLogs handles new pending logs received from the mining client. It updates the internal state and notifies subscribers about the new logs.
func (*Filters) LastPendingBlock ¶
LastPendingBlock returns the last pending block that was received.
func (*Filters) OnNewEvent ¶
func (ff *Filters) OnNewEvent(event *remote.SubscribeReply)
OnNewEvent is called when there is a new event from the remote and processes it.
func (*Filters) OnNewLogs ¶
func (ff *Filters) OnNewLogs(reply *remote.SubscribeLogsReply)
OnNewLogs handles a new log event from the remote and processes it.
func (*Filters) OnNewTx ¶
func (ff *Filters) OnNewTx(reply *txpool.OnAddReply)
OnNewTx handles a new transaction event from the transaction pool and processes it.
func (*Filters) ReadLogs ¶
ReadLogs reads logs from the store associated with the given subscription ID. It returns the logs and a boolean indicating whether the logs were found.
func (*Filters) ReadPendingBlocks ¶
func (ff *Filters) ReadPendingBlocks(id HeadsSubID) ([]*types.Header, bool)
ReadPendingBlocks reads pending block headers from the store associated with the given subscription ID. It returns the block headers and a boolean indicating whether the headers were found.
func (*Filters) ReadPendingTxs ¶
func (ff *Filters) ReadPendingTxs(id PendingTxsSubID) ([][]types.Transaction, bool)
ReadPendingTxs reads pending transactions from the store associated with the given subscription ID. It returns the transactions and a boolean indicating whether the transactions were found.
func (*Filters) SubscribeLogs ¶
func (ff *Filters) SubscribeLogs(size int, criteria filters.FilterCriteria) (<-chan *types.Log, LogsSubID)
SubscribeLogs subscribes to logs using the specified filter criteria and returns a channel to receive the logs and a subscription ID to manage the subscription.
func (*Filters) SubscribeNewHeads ¶
func (ff *Filters) SubscribeNewHeads(size int) (<-chan *types.Header, HeadsSubID)
SubscribeNewHeads subscribes to new block headers and returns a channel to receive the headers and a subscription ID to manage the subscription.
func (*Filters) SubscribePendingBlock ¶
func (ff *Filters) SubscribePendingBlock(size int) (<-chan *types.Block, PendingBlockSubID)
SubscribePendingBlock subscribes to pending blocks and returns a channel to receive the blocks and a subscription ID to manage the subscription.
func (*Filters) SubscribePendingLogs ¶
func (ff *Filters) SubscribePendingLogs(size int) (<-chan types.Logs, PendingLogsSubID)
SubscribePendingLogs subscribes to pending logs and returns a channel to receive the logs and a subscription ID to manage the subscription. It uses the specified filter criteria.
func (*Filters) SubscribePendingTxs ¶
func (ff *Filters) SubscribePendingTxs(size int) (<-chan []types.Transaction, PendingTxsSubID)
SubscribePendingTxs subscribes to pending transactions and returns a channel to receive the transactions and a subscription ID to manage the subscription.
func (*Filters) UnsubscribeHeads ¶
func (ff *Filters) UnsubscribeHeads(id HeadsSubID) bool
UnsubscribeHeads unsubscribes from new block headers using the given subscription ID. It returns true if the unsubscription was successful, otherwise false.
func (*Filters) UnsubscribeLogs ¶
UnsubscribeLogs unsubscribes from logs using the given subscription ID. It returns true if the unsubscription was successful, otherwise false.
func (*Filters) UnsubscribePendingBlock ¶
func (ff *Filters) UnsubscribePendingBlock(id PendingBlockSubID)
UnsubscribePendingBlock unsubscribes from pending blocks using the given subscription ID.
func (*Filters) UnsubscribePendingLogs ¶
func (ff *Filters) UnsubscribePendingLogs(id PendingLogsSubID)
UnsubscribePendingLogs unsubscribes from pending logs using the given subscription ID.
func (*Filters) UnsubscribePendingTxs ¶
func (ff *Filters) UnsubscribePendingTxs(id PendingTxsSubID) bool
UnsubscribePendingTxs unsubscribes from pending transactions using the given subscription ID. It returns true if the unsubscription was successful, otherwise false.
type FiltersConfig ¶
type FiltersConfig struct { RpcSubscriptionFiltersMaxLogs int // Maximum number of logs to store per subscription. Default: 0 (no limit) RpcSubscriptionFiltersMaxHeaders int // Maximum number of block headers to store per subscription. Default: 0 (no limit) RpcSubscriptionFiltersMaxTxs int // Maximum number of transactions to store per subscription. Default: 0 (no limit) RpcSubscriptionFiltersMaxAddresses int // Maximum number of addresses per subscription to filter logs by. Default: 0 (no limit) RpcSubscriptionFiltersMaxTopics int // Maximum number of topics per subscription to filter logs by. Default: 0 (no limit) }
FiltersConfig defines the configuration settings for RPC subscription filters. Each field represents a limit on the number of respective items that can be stored per subscription.
type HeadsSubID ¶
type HeadsSubID SubscriptionID
type LogsFilter ¶
type LogsFilter struct {
// contains filtered or unexported fields
}
LogsFilter is used for both representing log filter for a specific subscriber (RPC daemon usually) and "aggregated" log filter representing a union of all subscribers. Therefore, the values in the mappings are counters (of type int) and they get deleted when counter goes back to 0. Also, addAddr and allTopic are int instead of bool because they are also counters, counting how many subscribers have this set on.
func (*LogsFilter) Close ¶
func (l *LogsFilter) Close()
Close closes the sender associated with the LogsFilter. It is used to properly clean up and release resources associated with the sender.
func (*LogsFilter) Send ¶
func (l *LogsFilter) Send(lg *types2.Log)
Send sends a log to the subscriber represented by the LogsFilter. It forwards the log to the subscriber's sender.
type LogsFilterAggregator ¶
type LogsFilterAggregator struct {
// contains filtered or unexported fields
}
func NewLogsFilterAggregator ¶
func NewLogsFilterAggregator() *LogsFilterAggregator
NewLogsFilterAggregator creates and returns a new instance of LogsFilterAggregator. It initializes the aggregated log filter and the map of individual log filters.
type LogsSubID ¶
type LogsSubID SubscriptionID
type PendingBlockSubID ¶
type PendingBlockSubID SubscriptionID
type PendingLogsSubID ¶
type PendingLogsSubID SubscriptionID
type PendingTxsSubID ¶
type PendingTxsSubID SubscriptionID
type Sub ¶
type Sub[T any] interface { Send(T) Close() }
a simple interface for subscriptions for rpc helper
type SubscriptionID ¶
type SubscriptionID string