rpchelper

package
v3.0.0-alpha5.0...-c974331 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: LGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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 CreateLatestCachedStateReader

func CreateLatestCachedStateReader(cache kvcache.CacheView, tx kv.Tx) state.StateReader

func CreateStateReader

func CreateStateReader(ctx context.Context, tx kv.Tx, br services.FullBlockReader, blockNrOrHash rpc.BlockNumberOrHash, txnIndex int, filters *Filters, stateCache kvcache.Cache, chainName string) (state.StateReader, error)

func CreateStateReaderFromBlockNumber

func CreateStateReaderFromBlockNumber(ctx context.Context, tx kv.Tx, txNumsReader rawdbv3.TxNumsReader, blockNumber uint64, latest bool, txnIndex int, stateCache kvcache.Cache, chainName string) (state.StateReader, error)

func GetBlockNumber

func GetBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, tx kv.Tx, br services.FullBlockReader, filters *Filters) (uint64, libcommon.Hash, bool, error)

func GetCanonicalBlockNumber

func GetCanonicalBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, tx kv.Tx, br services.FullBlockReader, filters *Filters) (uint64, libcommon.Hash, bool, error)

func GetFinalizedBlockNumber

func GetFinalizedBlockNumber(tx kv.Tx) (uint64, error)

func GetLatestBlockNumber

func GetLatestBlockNumber(tx kv.Tx) (uint64, error)

func GetLatestExecutedBlockNumber

func GetLatestExecutedBlockNumber(tx kv.Tx) (uint64, error)

func GetSafeBlockNumber

func GetSafeBlockNumber(tx kv.Tx) (uint64, error)

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) AddLogs

func (ff *Filters) AddLogs(id LogsSubID, log *types.Log)

AddLogs adds logs to the store associated with the given subscription ID.

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

func (ff *Filters) LastPendingBlock() *types.Block

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

func (ff *Filters) ReadLogs(id LogsSubID) ([]*types.Log, bool)

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

func (ff *Filters) UnsubscribeLogs(id LogsSubID) bool

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

Jump to

Keyboard shortcuts

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