client

package
v0.10.14 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 17 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSubscriberClosed = errors.New("subscriber closed")

Functions

func DialRPCClientWithBackoff

func DialRPCClientWithBackoff(ctx context.Context, log log.Logger, addr string, opts ...rpc.ClientOption) (*rpc.Client, error)

Dials a JSON-RPC endpoint repeatedly, with a backoff, until a client connection is established. Auth is optional.

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 timeout of 10s on CallContext & 20s on BatchCallContext made through it.

func NewBaseRPCClient

func NewBaseRPCClient(c *rpc.Client) *BaseRPCClient

func (*BaseRPCClient) BatchCallContext

func (b *BaseRPCClient) BatchCallContext(ctx context.Context, batch []rpc.BatchElem) error

func (*BaseRPCClient) CallContext

func (b *BaseRPCClient) CallContext(ctx context.Context, result any, method string, args ...any) error

func (*BaseRPCClient) Close

func (b *BaseRPCClient) Close()

func (*BaseRPCClient) EthSubscribe

func (b *BaseRPCClient) EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error)

type Client

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

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

InstrumentedClient is an Ethereum client that tracks Prometheus metrics for each call.

func NewInstrumentedClient

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

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

func (*InstrumentedClient) BlockByHash

func (ic *InstrumentedClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)

func (*InstrumentedClient) BlockByNumber

func (ic *InstrumentedClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

func (*InstrumentedClient) BlockNumber

func (ic *InstrumentedClient) BlockNumber(ctx context.Context) (uint64, error)

func (*InstrumentedClient) CallContract

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

func (*InstrumentedClient) CallContractAtHash

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

func (*InstrumentedClient) ChainID

func (ic *InstrumentedClient) ChainID(ctx context.Context) (*big.Int, error)

func (*InstrumentedClient) Close

func (ic *InstrumentedClient) Close()

func (*InstrumentedClient) CodeAt

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

func (*InstrumentedClient) EstimateGas

func (ic *InstrumentedClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

func (*InstrumentedClient) FilterLogs

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

func (*InstrumentedClient) HeaderByHash

func (ic *InstrumentedClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)

func (*InstrumentedClient) HeaderByNumber

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

func (*InstrumentedClient) NetworkID

func (ic *InstrumentedClient) NetworkID(ctx context.Context) (*big.Int, error)

func (*InstrumentedClient) NonceAt

func (ic *InstrumentedClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)

func (*InstrumentedClient) PeerCount

func (ic *InstrumentedClient) PeerCount(ctx context.Context) (uint64, error)

func (*InstrumentedClient) PendingBalanceAt

func (ic *InstrumentedClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)

func (*InstrumentedClient) PendingCallContract

func (ic *InstrumentedClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)

func (*InstrumentedClient) PendingCodeAt

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

func (*InstrumentedClient) PendingNonceAt

func (ic *InstrumentedClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*InstrumentedClient) PendingStorageAt

func (ic *InstrumentedClient) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)

func (*InstrumentedClient) PendingTransactionCount

func (ic *InstrumentedClient) PendingTransactionCount(ctx context.Context) (uint, error)

func (*InstrumentedClient) SendTransaction

func (ic *InstrumentedClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*InstrumentedClient) StorageAt

func (ic *InstrumentedClient) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)

func (*InstrumentedClient) SubscribeFilterLogs

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

func (*InstrumentedClient) SubscribeNewHead

func (ic *InstrumentedClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

func (*InstrumentedClient) SuggestGasPrice

func (ic *InstrumentedClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*InstrumentedClient) SuggestGasTipCap

func (ic *InstrumentedClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

func (*InstrumentedClient) SyncProgress

func (ic *InstrumentedClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)

func (*InstrumentedClient) TransactionByHash

func (ic *InstrumentedClient) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error)

func (*InstrumentedClient) TransactionCount

func (ic *InstrumentedClient) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)

func (*InstrumentedClient) TransactionInBlock

func (ic *InstrumentedClient) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)

func (*InstrumentedClient) TransactionReceipt

func (ic *InstrumentedClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

func (*InstrumentedClient) TransactionSender

func (ic *InstrumentedClient) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)

type InstrumentedRPCClient

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

InstrumentedRPCClient is an RPC client that tracks Prometheus metrics for each call.

func NewInstrumentedRPC

func NewInstrumentedRPC(c RPC, m *metrics.Metrics) *InstrumentedRPCClient

NewInstrumentedRPC creates a new instrumented RPC client.

func (*InstrumentedRPCClient) BatchCallContext

func (ic *InstrumentedRPCClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

func (*InstrumentedRPCClient) CallContext

func (ic *InstrumentedRPCClient) CallContext(ctx context.Context, result any, method string, args ...any) error

func (*InstrumentedRPCClient) Close

func (ic *InstrumentedRPCClient) Close()

func (*InstrumentedRPCClient) EthSubscribe

func (ic *InstrumentedRPCClient) EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error)

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 (w *PollingClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

func (*PollingClient) CallContext

func (w *PollingClient) CallContext(ctx context.Context, result any, method string, args ...any) error

func (*PollingClient) Close

func (w *PollingClient) Close()

Close closes the PollingClient and the underlying RPC client it talks to.

func (*PollingClient) EthSubscribe

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

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

func NewRPC

func NewRPC(ctx context.Context, lgr log.Logger, addr string, opts ...rpc.ClientOption) (RPC, error)

NewRPC returns the correct client.RPC instance for a given RPC url.

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.

Jump to

Keyboard shortcuts

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