rpc

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func IsPermanentRPCError

func IsPermanentRPCError(err error) bool

IsPermanentRPCError checks if an error represents a permanent failure of the RPC that should not be retried.

func IsPermanentTxError

func IsPermanentTxError(err error) bool

IsPermanentTxError checks if an error represents a permanent failure that should not be retried.

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

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

BlobBaseFee retrieves the base fee for blob transactions on the blockchain.

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

func (c *Client) CallSimulation(ctx context.Context, result any, simReq any, blockTag string) error

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) ([]gethtypes.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) HeaderByHash

func (c *Client) HeaderByHash(ctx context.Context, blockHash common.Hash) (*gethtypes.Header, error)

HeaderByHash method wraps the HeaderByHash 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.

func (*Client) HeaderByNumber

func (c *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*gethtypes.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 *gethtypes.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<- gethtypes.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.

func (*Client) TransactionByHash

func (c *Client) TransactionByHash(ctx context.Context, txHash common.Hash) (*gethtypes.Transaction, error)

TransactionByHash method wraps the TransactionByHash 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.

func (*Client) TransactionReceipt

func (c *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*gethtypes.Receipt, error)

TransactionReceipt method wraps the TransactionReceipt 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.

type RPCError

type RPCError struct {
	Code    int           `json:"code"`
	Message string        `json:"message"`
	Data    hexutil.Bytes `json:"data"`
}

RPCError is the error returned by the RPC server

func ParseError

func ParseError(err error) *RPCError

ParseError tries to extract Data and Code from error, to reconstruct a *RPCError.

func (*RPCError) Error

func (e *RPCError) Error() string

func (*RPCError) ErrorCode

func (e *RPCError) ErrorCode() int

func (*RPCError) ErrorData

func (e *RPCError) ErrorData() any

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. It records the time when the endpoint was disabled for cooldown tracking.

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. It also checks for disabled endpoints that have passed their cooldown period and re-enables them.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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