Documentation ¶
Overview ¶
Package clients provides tools for managing and interacting with Ethereum clients.
The package offers a ClientPool structure that manages a pool of Ethereum clients for different networks and types. The ClientPool allows for retrieving clients based on various criteria, such as group and type, in a round-robin fashion. It also provides functionality to close all clients in the pool.
Additionally, the package provides a Client structure that wraps the Ethereum client with additional context and options. This structure offers methods to retrieve various details about the client, such as its network ID, group, type, and endpoint.
The package is designed to be flexible and efficient, ensuring that Ethereum clients can be easily managed and accessed based on the specific needs of the application.
Index ¶
- Variables
- type Client
- type ClientPool
- func (c *ClientPool) Close()
- func (c *ClientPool) GetClient(group, typ string) *Client
- func (c *ClientPool) GetClientByGroup(group string) *Client
- func (c *ClientPool) GetClientByGroupAndType(group, typ string) *Client
- func (c *ClientPool) GetClientDescriptionByNetworkId(networkId *big.Int) (string, string)
- func (c *ClientPool) GetClients() map[string][]*Client
- func (c *ClientPool) Len() int
- func (c *ClientPool) RegisterClient(ctx context.Context, networkId uint64, group, typ, endpoint string, ...) error
- type Node
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrClientURLNotSet = errors.New("configuration client URL not set")
ErrClientURLNotSet is returned when the client URL in the configuration is not set.
var ErrConcurrentClientsNotSet = errors.New("configuration amount of concurrent clients is not set")
ErrConcurrentClientsNotSet is returned when the number of concurrent clients in the configuration is not set.
var ErrNodesNotSet = errors.New("configuration nodes not set")
ErrNodesNotSet is returned when the configuration nodes are not set.
var ErrOptionsNotSet = errors.New("configuration options not set")
ErrOptionsNotSet is returned when the configuration options are not set.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client wraps the Ethereum client with additional context and options. It provides methods to retrieve client-specific configurations and to close the client connection.
func NewClient ¶
NewClient initializes a new Ethereum client with the given options. It returns an error if the endpoint URL is not set, if there's an issue initializing the Ethereum client, or if there's a mismatch between the provided network ID and the actual network ID.
func (*Client) Close ¶
func (c *Client) Close()
Close gracefully closes the Ethereum client connection.
func (*Client) GetEndpoint ¶
GetEndpoint retrieves the endpoint URL of the client.
func (*Client) GetFailoverGroup ¶
GetFailoverGroup retrieves the failover group associated with the client.
func (*Client) GetFailoverType ¶
GetFailoverType retrieves the type of failover for the client.
func (*Client) GetNetworkID ¶
GetNetworkID retrieves the network ID for the client.
func (*Client) GetRpcClient ¶ added in v0.3.2
GetRpcClient retrieves the RPC client associated with the client.
type ClientPool ¶
type ClientPool struct {
// contains filtered or unexported fields
}
ClientPool manages a pool of Ethereum clients for different networks and types. It provides methods to retrieve clients based on various criteria and to close all clients in the pool.
func NewClientPool ¶
func NewClientPool(ctx context.Context, opts *Options) (*ClientPool, error)
NewClientPool initializes a new ClientPool with the given options. It returns an error if the options are not set, if there are no nodes specified in the options, or if there's an issue with any of the nodes' configurations.
func (*ClientPool) Close ¶
func (c *ClientPool) Close()
Close gracefully closes all the clients in the pool.
func (*ClientPool) GetClient ¶
func (c *ClientPool) GetClient(group, typ string) *Client
GetClient retrieves a client based on the group and type in a round-robin fashion.
func (*ClientPool) GetClientByGroup ¶
func (c *ClientPool) GetClientByGroup(group string) *Client
GetClientByGroup retrieves a client based on the group in a round-robin fashion. It aggregates all clients within the specified group and returns one of them.
func (*ClientPool) GetClientByGroupAndType ¶
func (c *ClientPool) GetClientByGroupAndType(group, typ string) *Client
GetClientByGroupAndType retrieves a client based on the group and type in a round-robin fashion. This method is functionally equivalent to GetClient and is provided for clarity.
func (*ClientPool) GetClientDescriptionByNetworkId ¶
func (c *ClientPool) GetClientDescriptionByNetworkId(networkId *big.Int) (string, string)
GetClientDescriptionByNetworkId retrieves the group and type of a client based on the network ID. It returns an empty string for both group and type if no match is found.
func (*ClientPool) GetClients ¶ added in v0.3.3
func (c *ClientPool) GetClients() map[string][]*Client
GetClients returns all clients in the pool.
func (*ClientPool) Len ¶
func (c *ClientPool) Len() int
Len returns the number of clients in the pool.
func (*ClientPool) RegisterClient ¶ added in v0.3.3
func (c *ClientPool) RegisterClient(ctx context.Context, networkId uint64, group, typ, endpoint string, concurrentClientsNumber int) error
RegisterClient adds a new client to the pool. It takes the group and type of the client as well as the necessary parameters to create the client.
type Node ¶
type Node struct { // Group represents the group name of the node. Group string `mapstructure:"group" yaml:"group" json:"group"` // Type represents the type of the node. Type string `mapstructure:"type" yaml:"type" json:"type"` // FailoverGroup represents the failover group name of the node. FailoverGroup string `mapstructure:"failoverGroup" yaml:"failoverGroup" json:"failoverGroup"` // FailoverType represents the type of failover for the node. FailoverType string `mapstructure:"failoverType" yaml:"failoverType" json:"failoverType"` // NetworkId represents the network ID of the node. NetworkId int `mapstructure:"networkId" yaml:"networkId" json:"networkId"` // Endpoint represents the network endpoint of the node. Endpoint string `mapstructure:"endpoint" yaml:"endpoint" json:"endpoint"` // ConcurrentClients represents the number of concurrent clients for the node. ConcurrentClients int `mapstructure:"concurrentClients" yaml:"concurrentClients" json:"concurrentClients"` }
Node represents the configuration and details of a network node.
func (*Node) GetConcurrentClientsNumber ¶
GetConcurrentClientsNumber returns the number of concurrent clients for the node.
func (*Node) GetEndpoint ¶
GetEndpoint returns the network endpoint of the node.
func (*Node) GetFailoverGroup ¶
GetFailoverGroup returns the failover group name of the node.
func (*Node) GetFailoverType ¶
GetFailoverType returns the type of failover for the node.
func (*Node) GetNetworkID ¶
GetNetworkID returns the network ID of the node.