clients

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 14

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

Constants

This section is empty.

Variables

View Source
var ErrClientURLNotSet = errors.New("configuration client URL not set")

ErrClientURLNotSet is returned when the client URL in the configuration is not set.

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

View Source
var ErrNodesNotSet = errors.New("configuration nodes not set")

ErrNodesNotSet is returned when the configuration nodes are not set.

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

type Client struct {
	*ethclient.Client
	// contains filtered or unexported fields
}

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

func NewClient(ctx context.Context, opts *Node) (*Client, error)

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

func (c *Client) GetEndpoint() string

GetEndpoint retrieves the endpoint URL of the client.

func (*Client) GetFailoverGroup

func (c *Client) GetFailoverGroup() string

GetFailoverGroup retrieves the failover group associated with the client.

func (*Client) GetFailoverType

func (c *Client) GetFailoverType() string

GetFailoverType retrieves the type of failover for the client.

func (*Client) GetGroup

func (c *Client) GetGroup() string

GetGroup retrieves the group associated with the client.

func (*Client) GetNetworkID

func (c *Client) GetNetworkID() int64

GetNetworkID retrieves the network ID for the client.

func (*Client) GetRpcClient added in v0.3.2

func (c *Client) GetRpcClient() *rpc.Client

GetRpcClient retrieves the RPC client associated with the client.

func (*Client) GetType

func (c *Client) GetType() string

GetType retrieves the type of 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

func (n *Node) GetConcurrentClientsNumber() int

GetConcurrentClientsNumber returns the number of concurrent clients for the node.

func (*Node) GetEndpoint

func (n *Node) GetEndpoint() string

GetEndpoint returns the network endpoint of the node.

func (*Node) GetFailoverGroup

func (n *Node) GetFailoverGroup() string

GetFailoverGroup returns the failover group name of the node.

func (*Node) GetFailoverType

func (n *Node) GetFailoverType() string

GetFailoverType returns the type of failover for the node.

func (*Node) GetGroup

func (n *Node) GetGroup() string

GetGroup returns the group name of the node.

func (*Node) GetNetworkID

func (n *Node) GetNetworkID() int64

GetNetworkID returns the network ID of the node.

func (*Node) GetType

func (n *Node) GetType() string

GetType returns the type of the node.

type Options

type Options struct {
	// Nodes is a slice of Node representing the network nodes.
	Nodes []Node `mapstructure:"nodes" yaml:"nodes" json:"nodes"`
}

Options represents the configuration options for network nodes.

func (*Options) GetNodes

func (o *Options) GetNodes() []Node

GetNodes returns the slice of network nodes from the Options.

Jump to

Keyboard shortcuts

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