Documentation
¶
Index ¶
- Constants
- Variables
- func CheckAndDial(ctx context.Context, log log.Logger, addr string, options ...rpc.ClientOption) (*rpc.Client, error)
- func IsURLAvailable(ctx context.Context, address string) bool
- type BaseRPCClient
- func (b *BaseRPCClient) BatchCallContext(ctx context.Context, batch []rpc.BatchElem) error
- func (b *BaseRPCClient) CallContext(ctx context.Context, result any, method string, args ...any) error
- func (b *BaseRPCClient) Close()
- func (b *BaseRPCClient) Subscribe(ctx context.Context, namespace string, channel any, args ...any) (ethereum.Subscription, error)
- type BasicHTTPClient
- type BasicHTTPClientOption
- type BasicHTTPClientOptionFn
- type HTTP
- type PollingClient
- func (w *PollingClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
- func (w *PollingClient) CallContext(ctx context.Context, result any, method string, args ...any) error
- func (w *PollingClient) Close()
- func (w *PollingClient) Subscribe(ctx context.Context, namespace string, channel any, args ...any) (ethereum.Subscription, error)
- type RPC
- type RPCOption
- func WithBatchCallTimeout(d time.Duration) RPCOption
- func WithCallTimeout(d time.Duration) RPCOption
- func WithDialAttempts(attempts int) RPCOption
- func WithFixedDialBackoff(d time.Duration) RPCOption
- func WithGethRPCOptions(gethRPCOptions ...rpc.ClientOption) RPCOption
- func WithHttpPollInterval(duration time.Duration) RPCOption
- func WithLazyDial() RPCOption
- func WithRPCRecorder(recorder rpc.Recorder) RPCOption
- func WithRateLimit(rateLimit float64, burst int) RPCOption
- type RateLimitingClient
- func (b *RateLimitingClient) BatchCallContext(ctx context.Context, batch []rpc.BatchElem) error
- func (b *RateLimitingClient) CallContext(ctx context.Context, result any, method string, args ...any) error
- func (b *RateLimitingClient) Close()
- func (b *RateLimitingClient) Subscribe(ctx context.Context, namespace string, channel any, args ...any) (ethereum.Subscription, error)
- type WrappedHTTPClientOption
Constants ¶
const (
DefaultTimeoutSeconds = 30
)
Variables ¶
var ErrNoEndpoint = errors.New("no endpoint is configured")
var ErrSubscriberClosed = errors.New("subscriber closed")
Functions ¶
func CheckAndDial ¶
Types ¶
type BaseRPCClient ¶
type BaseRPCClient struct {
// contains filtered or unexported fields
}
BaseRPCClient is a wrapper around a concrete *rpc.Client instance to make it compliant with the client.RPC interface. It sets a default timeout of 10s on CallContext & 20s on BatchCallContext made through it.
func (*BaseRPCClient) BatchCallContext ¶
func (*BaseRPCClient) CallContext ¶
func (*BaseRPCClient) Close ¶
func (b *BaseRPCClient) Close()
type BasicHTTPClient ¶
type BasicHTTPClient struct {
// contains filtered or unexported fields
}
func NewBasicHTTPClient ¶
func NewBasicHTTPClient(endpoint string, log log.Logger, opts ...BasicHTTPClientOption) *BasicHTTPClient
type BasicHTTPClientOption ¶
type BasicHTTPClientOption interface {
Apply(c *BasicHTTPClient)
}
func WithHeader ¶
func WithHeader(h http.Header) BasicHTTPClientOption
func WithTransport ¶
func WithTransport(t http.RoundTripper) BasicHTTPClientOption
type BasicHTTPClientOptionFn ¶
type BasicHTTPClientOptionFn func(*BasicHTTPClient)
func (BasicHTTPClientOptionFn) Apply ¶
func (fn BasicHTTPClientOptionFn) Apply(c *BasicHTTPClient)
type PollingClient ¶
type PollingClient struct {
// contains filtered or unexported fields
}
PollingClient is an RPC client that provides newHeads subscriptions via a polling loop. It's designed for HTTP endpoints, but WS will work too.
func NewPollingClient ¶
func NewPollingClient(ctx context.Context, lgr log.Logger, c RPC, opts ...WrappedHTTPClientOption) *PollingClient
NewPollingClient returns a new PollingClient. Canceling the passed-in context will close the client. Callers are responsible for closing the client in order to prevent resource leaks.
func (*PollingClient) BatchCallContext ¶
func (*PollingClient) CallContext ¶
func (*PollingClient) Close ¶
func (w *PollingClient) Close()
Close closes the PollingClient and the underlying RPC client it talks to.
func (*PollingClient) Subscribe ¶
func (w *PollingClient) Subscribe(ctx context.Context, namespace string, channel any, args ...any) (ethereum.Subscription, error)
Subscribe supports eth_subscribe of block headers, by creating a new newHeads subscription. It takes identical arguments to Geth's native Subscribe method. It will return an error, however, if the passed in channel is not a *types.Headers channel or the subscription type is not newHeads. Or if the namespace is not "eth".
type RPC ¶
type RPC interface {
Close()
CallContext(ctx context.Context, result any, method string, args ...any) error
BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
Subscribe(ctx context.Context, namespace string, channel any, args ...any) (ethereum.Subscription, error)
}
type RPCOption ¶
type RPCOption func(cfg *rpcConfig)
func WithBatchCallTimeout ¶
func WithCallTimeout ¶
func WithDialAttempts ¶
WithDialAttempts configures the number of attempts for the initial dial to the RPC, attempts are executed with an exponential backoff strategy by default.
func WithFixedDialBackoff ¶
WithFixedDialBackoff makes the RPC client use a fixed delay between dial attempts of 2 seconds instead of exponential
func WithGethRPCOptions ¶
func WithGethRPCOptions(gethRPCOptions ...rpc.ClientOption) RPCOption
WithGethRPCOptions passes the list of go-ethereum RPC options to the internal RPC instance.
func WithHttpPollInterval ¶
WithHttpPollInterval configures the RPC to poll at the given rate, in case RPC subscriptions are not available.
func WithLazyDial ¶
func WithLazyDial() RPCOption
WithLazyDial makes the RPC client initialization defer the initial connection attempt, and defer to later RPC requests upon subsequent dial errors. Any dial-backoff option will be ignored if this option is used.
func WithRPCRecorder ¶
WithRPCRecorder makes the RPC client use the given RPC recorder. Warning: this overwrites any previous recorder choice.
func WithRateLimit ¶
WithRateLimit configures the RPC to target the given rate limit (in requests / second). See NewRateLimitingClient for more details.
type RateLimitingClient ¶
type RateLimitingClient struct {
// contains filtered or unexported fields
}
RateLimitingClient is a wrapper around a pure RPC that implements a global rate-limit on requests.
func NewRateLimitingClient ¶
func NewRateLimitingClient(c RPC, limit rate.Limit, burst int) *RateLimitingClient
NewRateLimitingClient implements a global rate-limit for all RPC requests. A limit of N will ensure that over a long enough time-frame the given number of tokens per second is targeted. Burst limits how far off we can be from the target, by specifying how many requests are allowed at once.
func (*RateLimitingClient) BatchCallContext ¶
func (*RateLimitingClient) CallContext ¶
func (*RateLimitingClient) Close ¶
func (b *RateLimitingClient) Close()
type WrappedHTTPClientOption ¶
type WrappedHTTPClientOption func(w *PollingClient)
func WithPollRate ¶
func WithPollRate(duration time.Duration) WrappedHTTPClientOption
WithPollRate specifies the rate at which the PollingClient will poll for new heads. Setting this to zero disables polling altogether, which is useful for testing.