rpc

package
v0.0.0-...-ef1bc62 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxWeb3ClientRetries is the default number of retries to connect to
	// a web3 provider.
	DefaultMaxWeb3ClientRetries = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client struct implements bind.ContractBackend interface for a web3 pool with an specific chainID. It allows to interact with the blockchain using the methods provided by the interface balancing the load between the available endpoints in the pool for the chainID.

func (*Client) BalanceAt

func (c *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)

BalanceAt method wraps the BalanceAt method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. This method is required by internal logic, it is not required by the bind.ContractBackend interface.

func (*Client) BlockNumber

func (c *Client) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber method wraps the BlockNumber method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. This method is required by internal logic, it is not required by the bind.ContractBackend interface.

func (*Client) CallContract

func (c *Client) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract method wraps the CallContract method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) CodeAt

func (c *Client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)

CodeAt method wraps the CodeAt method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) EstimateGas

func (c *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

EstimateGas method wraps the EstimateGas method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) EthClient

func (c *Client) EthClient() (*ethclient.Client, error)

EthClient method returns the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool.

func (*Client) FilterLogs

func (c *Client) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)

FilterLogs method wraps the FilterLogs method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) HeaderByNumber

func (c *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber method wraps the HeaderByNumber method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) PendingCodeAt

func (c *Client) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

PendingCodeAt method wraps the PendingCodeAt method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) PendingNonceAt

func (c *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt method wraps the PendingNonceAt method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) SendTransaction

func (c *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction method wraps the SendTransaction method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) SubscribeFilterLogs

func (c *Client) SubscribeFilterLogs(ctx context.Context,
	query ethereum.FilterQuery, ch chan<- types.Log,
) (ethereum.Subscription, error)

SubscribeFilterLogs method wraps the SubscribeFilterLogs method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) SuggestGasPrice

func (c *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice method wraps the SuggestGasPrice method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

func (*Client) SuggestGasTipCap

func (c *Client) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

SuggestGasTipCap method wraps the SuggestGasTipCap method from the ethclient.Client for the chainID of the Client instance. It returns an error if the chainID is not found in the pool or if the method fails. Required by the bind.ContractBackend interface.

type Web3Endpoint

type Web3Endpoint struct {
	ChainID   uint64 `json:"chainId"`
	URI       string
	IsArchive bool
	// contains filtered or unexported fields
}

Web3Endpoint struct contains all the required information about a web3 provider based on its URI. It includes its chain ID, its name (and shortName) and the URI.

type Web3Iterator

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

Web3Iterator struct is a pool of Web3Endpoint that allows to get the next available endpoint in a round-robin fashion. It also allows to disable an endpoint if it fails. It allows to manage multiple endpoints safely.

func NewWeb3Iterator

func NewWeb3Iterator(endpoints ...*Web3Endpoint) *Web3Iterator

NewWeb3Iterator creates a new Web3Iterator with the given endpoints.

func (*Web3Iterator) Add

func (w3pp *Web3Iterator) Add(endpoint ...*Web3Endpoint)

Add adds a new endpoint to the pool, making it available for the next requests.

func (*Web3Iterator) Available

func (w3pp *Web3Iterator) Available() int

Available returns the number of available endpoints.

func (*Web3Iterator) Disable

func (w3pp *Web3Iterator) Disable(uri string)

Disable method disables an endpoint, moving it from the available list to the the disabled list.

func (*Web3Iterator) Disabled

func (w3pp *Web3Iterator) Disabled() int

Disabled returns the number of disabled endpoints.

func (*Web3Iterator) Next

func (w3pp *Web3Iterator) Next() (*Web3Endpoint, error)

Next returns the next available endpoint in a round-robin fashion. If there are no registered endpoints, it will return an error. If there are no available endpoints, it will reset the disabled endpoints and return the first available endpoint.

type Web3Pool

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

Web3Pool struct contains a map of chainID-[]*Web3Endpoint, where the key is the chainID and the value is a list of Web3Endpoint. It also contains a list of all the Web3Endpoint metadata. It provides methods to add, remove and get endpoints, as well as to get the chainID by short name. It allows to support multiple endpoints for the same chainID and switch between them looking for the available one.

func NewAutomaticWeb3Pool

func NewAutomaticWeb3Pool() (*Web3Pool, error)

NewWeb3Pool method returns a new *Web3Pool instance, initialized with the endpoints list available in https://chainid.network. It returns an error if the metadata cannot be retrieved or decoded.

func NewWeb3Pool

func NewWeb3Pool() *Web3Pool

NewWeb3Pool method returns a new *Web3Pool instance.

func (*Web3Pool) AddEndpoint

func (nm *Web3Pool) AddEndpoint(uri string) (uint64, error)

AddEndpoint method adds a new web3 provider URI to the Web3Pool. It returns the chainID of the endpoint added to the pool.

func (*Web3Pool) Client

func (nm *Web3Pool) Client(chainID uint64) (*Client, error)

Client method returns a new *Client instance for the chainID provided. It returns an error if the endpoint is not found.

func (*Web3Pool) CurrentBlockNumbers

func (nm *Web3Pool) CurrentBlockNumbers(ctx context.Context) (map[uint64]uint64, error)

CurrentBlockNumbers method returns a map of uint64-uint64, where the key is the chainID and the value is the current block number of the network.

func (*Web3Pool) DelEndoint

func (nm *Web3Pool) DelEndoint(uri string)

DelEndpoint method removes a web3 provider URI from the *Web3Pool instance. It closes the client and removes the endpoint from the list of endpoints for the chainID where it was found.

func (*Web3Pool) DisableEndpoint

func (nm *Web3Pool) DisableEndpoint(chainID uint64, uri string)

DisableEndpoint method sets the available flag to false for the URI provided in the chainID provided.

func (*Web3Pool) Endpoint

func (nm *Web3Pool) Endpoint(chainID uint64) (*Web3Endpoint, error)

Endpoint method returns the Web3Endpoint configured for the chainID provided. It returns the first available endpoint. If no available endpoint is found, returns an error.

func (*Web3Pool) NetworkInfoByChainID

func (nm *Web3Pool) NetworkInfoByChainID(chainID uint64) *Web3Endpoint

NetworkInfoByChainID method returns the Web3Endpoint metadata for the chainID provided. It returns nil if the chainID is not found.

func (*Web3Pool) NumberOfEndpoints

func (nm *Web3Pool) NumberOfEndpoints(chainID uint64, onlyAvailable bool) int

NumberOfEndpoints method returns the total number (or just the available ones) of endpoints for the chainID provided.

func (*Web3Pool) SupportedNetworks

func (nm *Web3Pool) SupportedNetworks() []*Web3Endpoint

SupportedNetworks method returns a list of all the supported Web3Endpoint metadata. It returns the chainID, name and shortName of unique supported chains.

Jump to

Keyboard shortcuts

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