Documentation ¶
Index ¶
- Constants
- Variables
- func IsURLAvailable(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) EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error)
- type BasicHTTPClient
- type BasicHTTPClientOption
- type BasicHTTPClientOptionFn
- type Client
- type HTTP
- type InstrumentedClient
- func (ic *InstrumentedClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
- func (ic *InstrumentedClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
- func (ic *InstrumentedClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
- func (ic *InstrumentedClient) BlockNumber(ctx context.Context) (uint64, error)
- func (ic *InstrumentedClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
- func (ic *InstrumentedClient) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
- func (ic *InstrumentedClient) ChainID(ctx context.Context) (*big.Int, error)
- func (ic *InstrumentedClient) Close()
- func (ic *InstrumentedClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
- func (ic *InstrumentedClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
- func (ic *InstrumentedClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
- func (ic *InstrumentedClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
- func (ic *InstrumentedClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
- func (ic *InstrumentedClient) NetworkID(ctx context.Context) (*big.Int, error)
- func (ic *InstrumentedClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
- func (ic *InstrumentedClient) PeerCount(ctx context.Context) (uint64, error)
- func (ic *InstrumentedClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
- func (ic *InstrumentedClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
- func (ic *InstrumentedClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
- func (ic *InstrumentedClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
- func (ic *InstrumentedClient) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
- func (ic *InstrumentedClient) PendingTransactionCount(ctx context.Context) (uint, error)
- func (ic *InstrumentedClient) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (ic *InstrumentedClient) StorageAt(ctx context.Context, account common.Address, key common.Hash, ...) ([]byte, error)
- func (ic *InstrumentedClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
- func (ic *InstrumentedClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
- func (ic *InstrumentedClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)
- func (ic *InstrumentedClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
- func (ic *InstrumentedClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
- func (ic *InstrumentedClient) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error)
- func (ic *InstrumentedClient) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
- func (ic *InstrumentedClient) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
- func (ic *InstrumentedClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
- func (ic *InstrumentedClient) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
- type InstrumentedRPCClient
- func (ic *InstrumentedRPCClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
- func (ic *InstrumentedRPCClient) CallContext(ctx context.Context, result any, method string, args ...any) error
- func (ic *InstrumentedRPCClient) Close()
- func (ic *InstrumentedRPCClient) EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error)
- 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) EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error)
- type RPC
- type 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) EthSubscribe(ctx context.Context, 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 IsURLAvailable ¶ added in v1.2.0
Types ¶
type BaseRPCClient ¶ added in v1.2.0
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 timeout of 10s on CallContext & 20s on BatchCallContext made through it.
func NewBaseRPCClient ¶ added in v1.2.0
func NewBaseRPCClient(c *rpc.Client) *BaseRPCClient
func (*BaseRPCClient) BatchCallContext ¶ added in v1.2.0
func (*BaseRPCClient) CallContext ¶ added in v1.2.0
func (*BaseRPCClient) Close ¶ added in v1.2.0
func (b *BaseRPCClient) Close()
func (*BaseRPCClient) EthSubscribe ¶ added in v1.2.0
type BasicHTTPClient ¶ added in v1.4.3
type BasicHTTPClient struct {
// contains filtered or unexported fields
}
func NewBasicHTTPClient ¶ added in v1.4.3
func NewBasicHTTPClient(endpoint string, log log.Logger, opts ...BasicHTTPClientOption) *BasicHTTPClient
type BasicHTTPClientOption ¶ added in v1.7.0
type BasicHTTPClientOption interface {
Apply(c *BasicHTTPClient)
}
func WithHeader ¶ added in v1.7.0
func WithHeader(h http.Header) BasicHTTPClientOption
type BasicHTTPClientOptionFn ¶ added in v1.7.0
type BasicHTTPClientOptionFn func(*BasicHTTPClient)
func (BasicHTTPClientOptionFn) Apply ¶ added in v1.7.0
func (fn BasicHTTPClientOptionFn) Apply(c *BasicHTTPClient)
type Client ¶ added in v1.2.0
type Client interface { Close() ChainID(ctx context.Context) (*big.Int, error) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) BlockNumber(ctx context.Context) (uint64, error) PeerCount(ctx context.Context) (uint64, error) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) NetworkID(ctx context.Context) (*big.Int, error) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) PendingTransactionCount(ctx context.Context) (uint, error) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) SuggestGasPrice(ctx context.Context) (*big.Int, error) SuggestGasTipCap(ctx context.Context) (*big.Int, error) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) SendTransaction(ctx context.Context, tx *types.Transaction) error }
type InstrumentedClient ¶ added in v1.2.0
type InstrumentedClient struct {
// contains filtered or unexported fields
}
InstrumentedClient is an Ethereum client that tracks Prometheus metrics for each call.
func NewInstrumentedClient ¶ added in v1.2.0
func NewInstrumentedClient(c *rpc.Client, m *metrics.Metrics) *InstrumentedClient
NewInstrumentedClient creates a new instrumented client. It takes a concrete *rpc.Client to prevent people from passing in an already instrumented client.
func (*InstrumentedClient) BlockByHash ¶ added in v1.2.0
func (*InstrumentedClient) BlockByNumber ¶ added in v1.2.0
func (*InstrumentedClient) BlockNumber ¶ added in v1.2.0
func (ic *InstrumentedClient) BlockNumber(ctx context.Context) (uint64, error)
func (*InstrumentedClient) CallContract ¶ added in v1.2.0
func (*InstrumentedClient) CallContractAtHash ¶ added in v1.2.0
func (*InstrumentedClient) Close ¶ added in v1.2.0
func (ic *InstrumentedClient) Close()
func (*InstrumentedClient) EstimateGas ¶ added in v1.2.0
func (ic *InstrumentedClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
func (*InstrumentedClient) FilterLogs ¶ added in v1.2.0
func (*InstrumentedClient) HeaderByHash ¶ added in v1.2.0
func (*InstrumentedClient) HeaderByNumber ¶ added in v1.2.0
func (*InstrumentedClient) PeerCount ¶ added in v1.2.0
func (ic *InstrumentedClient) PeerCount(ctx context.Context) (uint64, error)
func (*InstrumentedClient) PendingBalanceAt ¶ added in v1.2.0
func (*InstrumentedClient) PendingCallContract ¶ added in v1.2.0
func (ic *InstrumentedClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
func (*InstrumentedClient) PendingCodeAt ¶ added in v1.2.0
func (*InstrumentedClient) PendingNonceAt ¶ added in v1.2.0
func (*InstrumentedClient) PendingStorageAt ¶ added in v1.2.0
func (*InstrumentedClient) PendingTransactionCount ¶ added in v1.2.0
func (ic *InstrumentedClient) PendingTransactionCount(ctx context.Context) (uint, error)
func (*InstrumentedClient) SendTransaction ¶ added in v1.2.0
func (ic *InstrumentedClient) SendTransaction(ctx context.Context, tx *types.Transaction) error
func (*InstrumentedClient) SubscribeFilterLogs ¶ added in v1.2.0
func (*InstrumentedClient) SubscribeNewHead ¶ added in v1.2.0
func (*InstrumentedClient) SuggestGasPrice ¶ added in v1.2.0
func (*InstrumentedClient) SuggestGasTipCap ¶ added in v1.2.0
func (*InstrumentedClient) SyncProgress ¶ added in v1.2.0
func (ic *InstrumentedClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
func (*InstrumentedClient) TransactionByHash ¶ added in v1.2.0
func (ic *InstrumentedClient) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error)
func (*InstrumentedClient) TransactionCount ¶ added in v1.2.0
func (*InstrumentedClient) TransactionInBlock ¶ added in v1.2.0
func (ic *InstrumentedClient) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
func (*InstrumentedClient) TransactionReceipt ¶ added in v1.2.0
func (*InstrumentedClient) TransactionSender ¶ added in v1.2.0
type InstrumentedRPCClient ¶ added in v1.2.0
type InstrumentedRPCClient struct {
// contains filtered or unexported fields
}
InstrumentedRPCClient is an RPC client that tracks Prometheus metrics for each call.
func NewInstrumentedRPC ¶ added in v1.2.0
func NewInstrumentedRPC(c RPC, m *metrics.Metrics) *InstrumentedRPCClient
NewInstrumentedRPC creates a new instrumented RPC client.
func (*InstrumentedRPCClient) BatchCallContext ¶ added in v1.2.0
func (*InstrumentedRPCClient) CallContext ¶ added in v1.2.0
func (*InstrumentedRPCClient) Close ¶ added in v1.2.0
func (ic *InstrumentedRPCClient) Close()
func (*InstrumentedRPCClient) EthSubscribe ¶ added in v1.2.0
type PollingClient ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
func (*PollingClient) CallContext ¶ added in v1.2.0
func (*PollingClient) Close ¶ added in v1.2.0
func (w *PollingClient) Close()
Close closes the PollingClient and the underlying RPC client it talks to.
func (*PollingClient) EthSubscribe ¶ added in v1.2.0
func (w *PollingClient) EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error)
EthSubscribe creates a new newHeads subscription. It takes identical arguments to Geth's native EthSubscribe 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.
type RPC ¶ added in v1.2.0
type RPC interface { Close() CallContext(ctx context.Context, result any, method string, args ...any) error BatchCallContext(ctx context.Context, b []rpc.BatchElem) error EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error) }
type RPCOption ¶ added in v1.2.0
type RPCOption func(cfg *rpcConfig) error
func WithDialBackoff ¶ added in v1.2.0
WithDialBackoff configures the number of attempts for the initial dial to the RPC, attempts are executed with an exponential backoff strategy.
func WithGethRPCOptions ¶ added in v1.2.0
func WithGethRPCOptions(gethRPCOptions ...rpc.ClientOption) RPCOption
WithGethRPCOptions passes the list of go-ethereum RPC options to the internal RPC instance.
func WithHttpPollInterval ¶ added in v1.2.0
WithHttpPollInterval configures the RPC to poll at the given rate, in case RPC subscriptions are not available.
func WithRateLimit ¶ added in v1.2.0
WithRateLimit configures the RPC to target the given rate limit (in requests / second). See NewRateLimitingClient for more details.
type RateLimitingClient ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
func (*RateLimitingClient) CallContext ¶ added in v1.2.0
func (*RateLimitingClient) Close ¶ added in v1.2.0
func (b *RateLimitingClient) Close()
func (*RateLimitingClient) EthSubscribe ¶ added in v1.2.0
type WrappedHTTPClientOption ¶ added in v1.2.0
type WrappedHTTPClientOption func(w *PollingClient)
func WithPollRate ¶ added in v1.2.0
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.