rpcclient

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Default retry configuration for RPC calls
	RPCDefaultRetryAttempts = 1
	RPCDefaultRetryDelay    = 1000 * time.Millisecond
	RPCDefaultRetryTimeout  = 10 * time.Second

	// Default retry configuration for dialing RPC endpoints
	RPCDefaultDialRetryAttempts = 1
	RPCDefaultDialRetryDelay    = 1000 * time.Millisecond
	RPCDefaultDialTimeout       = 10 * time.Second

	// Default timeout for health checks
	RPCDefaultHealthCheckTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiClient

type MultiClient struct {
	*ethclient.Client
	Backups     []*ethclient.Client
	RetryConfig RetryConfig
	// contains filtered or unexported fields
}

MultiClient is a client that can manage multiple RPC endpoints with a failover mechanism and retry logic.

func NewMultiClient

func NewMultiClient(lggr logger.Logger, rpcsCfg RPCConfig, opts ...func(client *MultiClient)) (*MultiClient, error)

NewMultiClient creates a new MultiClient with failover capabilities.

func (*MultiClient) BalanceAt

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

BalanceAt is a wrapper around the ethclient.BalanceAt method that retries on failure.

func (*MultiClient) CallContract

func (mc *MultiClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract is a wrapper around the ethclient.CallContract method that retries on failure.

func (*MultiClient) CallContractAtHash

func (mc *MultiClient) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)

CallContractAtHash is a wrapper around the ethclient.CallContractAtHash method that retries on failure.

func (*MultiClient) CodeAt

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

CodeAt is a wrapper around the ethclient.CodeAt method that retries on failure.

func (*MultiClient) CodeAtHash

func (mc *MultiClient) CodeAtHash(ctx context.Context, account common.Address, blockHash common.Hash) ([]byte, error)

CodeAtHash is a wrapper around the ethclient.CodeAtHash method that retries on failure.

func (*MultiClient) EstimateGas

func (mc *MultiClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)

EstimateGas is a wrapper around the ethclient.EstimateGas method that retries on failure.

func (*MultiClient) FilterLogs

func (mc *MultiClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

FilterLogs is a wrapper around the ethclient.FilterLogs method that retries on failure.

func (*MultiClient) HeaderByNumber

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

HeaderByNumber is a wrapper around the ethclient.HeaderByNumber method that retries on failure.

func (*MultiClient) NonceAt

func (mc *MultiClient) NonceAt(ctx context.Context, account common.Address, block *big.Int) (uint64, error)

NonceAt is a wrapper around the ethclient.NonceAt method that retries on failure.

func (*MultiClient) NonceAtHash

func (mc *MultiClient) NonceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (uint64, error)

NonceAtHash is a wrapper around the ethclient.NonceAtHash method that retries on failure.

func (*MultiClient) PendingCodeAt

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

PendingCodeAt is a wrapper around the ethclient.PendingCodeAt method that retries on failure.

func (*MultiClient) PendingNonceAt

func (mc *MultiClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt is a wrapper around the ethclient.PendingNonceAt method that retries on failure.

func (*MultiClient) SendTransaction

func (mc *MultiClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction is a wrapper around the ethclient.SendTransaction method that retries on failure.

func (*MultiClient) SubscribeFilterLogs

func (mc *MultiClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs is a wrapper around the ethclient.SubscribeFilterLogs method that retries on failure.

func (*MultiClient) SuggestGasPrice

func (mc *MultiClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice is a wrapper around the ethclient.SuggestGasPrice method that retries on failure.

func (*MultiClient) SuggestGasTipCap

func (mc *MultiClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

SuggestGasTipCap is a wrapper around the ethclient.SuggestGasTipCap method that retries on failure.

func (*MultiClient) WaitMined

func (mc *MultiClient) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)

WaitMined waits for a transaction to be mined and returns the receipt. Note: retryConfig timeout settings are not used for this operation, a timeout can be set in the context.

type RPC

type RPC struct {
	Name               string
	WSURL              string
	HTTPURL            string
	PreferredURLScheme URLSchemePreference
}

RPC represents a single RPC endpoint configuration.

func (RPC) ToEndpoint

func (r RPC) ToEndpoint() (string, error)

ToEndpoint returns the correct endpoint based on the preferred URL scheme If the preferred URL scheme is not set, it will return the WS URL If the preferred URL scheme is set to WS, it will return the WS URL If the preferred URL scheme is set to HTTP, it will return the HTTP URL

type RPCConfig

type RPCConfig struct {
	ChainSelector uint64
	RPCs          []RPC
}

RPCConfig is a configuration for a chain. It contains a chain selector and a list of RPCs

type RetryConfig

type RetryConfig struct {
	Attempts     uint
	Delay        time.Duration
	Timeout      time.Duration
	DialAttempts uint
	DialDelay    time.Duration
	DialTimeout  time.Duration
}

RetryConfig configures retry behavior for RPC operations.

type URLSchemePreference

type URLSchemePreference int

URLSchemePreference defines URL scheme preferences for RPC connections.

const (
	URLSchemePreferenceNone URLSchemePreference = iota
	URLSchemePreferenceWS
	URLSchemePreferenceHTTP
)

func URLSchemePreferenceFromString

func URLSchemePreferenceFromString(s string) (URLSchemePreference, error)

URLSchemePreferenceFromString converts a string to URLSchemePreference.

func (*URLSchemePreference) UnmarshalText

func (u *URLSchemePreference) UnmarshalText(text []byte) error

UnmarshalText unmarshals the URLSchemePreference from a text.

Jump to

Keyboard shortcuts

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