eth

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	ChainID(ctx context.Context) (*big.Int, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*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)
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
	FeeHistory(
		ctx context.Context,
		blockCount uint64,
		lastBlock *big.Int,
		rewardPercentiles []float64,
	) (*ethereum.FeeHistory, error)
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
	NetworkID(ctx context.Context) (*big.Int, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	PeerCount(ctx context.Context) (uint64, error)
	PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
	PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
	PendingTransactionCount(ctx context.Context) (uint, error)
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
	SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
	TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err 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)
	TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
}

func NewClient

func NewClient(rpcAddress string) (Client, error)

type InstrumentedClient

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

InstrumentedClient is a wrapper around the geth ethclient that instruments all the calls made to it. It counts each eth_ call made to it, and records the duration of each call, and exposes these as prometheus metrics

TODO: ideally this should be done at the rpcclient level, not the ethclient level, which would make our life much easier... but geth implemented the gethclient using an rpcClient struct instead of interface... see https://github.com/ethereum/go-ethereum/issues/28267

func NewInstrumentedClient

func NewInstrumentedClient(rpcAddress string, rpcCallsCollector *rpccalls.Collector) (*InstrumentedClient, error)

func NewInstrumentedClientFromClient

func NewInstrumentedClientFromClient(
	client *ethclient.Client,
	rpcCallsCollector *rpccalls.Collector,
) *InstrumentedClient

func (*InstrumentedClient) BalanceAt

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

func (*InstrumentedClient) BlockByHash

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

func (*InstrumentedClient) BlockByNumber

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

func (*InstrumentedClient) BlockNumber

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

func (*InstrumentedClient) CallContract

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

func (*InstrumentedClient) CallContractAtHash

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

func (*InstrumentedClient) ChainID

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

func (*InstrumentedClient) CodeAt

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

func (*InstrumentedClient) EstimateGas

func (iec *InstrumentedClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)

func (*InstrumentedClient) FeeHistory

func (iec *InstrumentedClient) FeeHistory(
	ctx context.Context,
	blockCount uint64,
	lastBlock *big.Int,
	rewardPercentiles []float64,
) (*ethereum.FeeHistory, error)

func (*InstrumentedClient) FilterLogs

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

func (*InstrumentedClient) HeaderByHash

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

func (*InstrumentedClient) HeaderByNumber

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

func (*InstrumentedClient) NetworkID

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

func (*InstrumentedClient) NonceAt

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

func (*InstrumentedClient) PeerCount

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

func (*InstrumentedClient) PendingBalanceAt

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

func (*InstrumentedClient) PendingCallContract

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

func (*InstrumentedClient) PendingCodeAt

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

func (*InstrumentedClient) PendingNonceAt

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

func (*InstrumentedClient) PendingStorageAt

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

func (*InstrumentedClient) PendingTransactionCount

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

func (*InstrumentedClient) SendTransaction

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

func (*InstrumentedClient) StorageAt

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

func (*InstrumentedClient) SubscribeFilterLogs

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

func (*InstrumentedClient) SubscribeNewHead

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

func (*InstrumentedClient) SuggestGasPrice

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

func (*InstrumentedClient) SuggestGasTipCap

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

func (*InstrumentedClient) SyncProgress

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

func (*InstrumentedClient) TransactionByHash

func (iec *InstrumentedClient) TransactionByHash(
	ctx context.Context,
	hash common.Hash,
) (tx *types.Transaction, isPending bool, err error)

We write the instrumentation of this function directly because instrumentFunction[] generic fct only takes a single return value

func (*InstrumentedClient) TransactionCount

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

func (*InstrumentedClient) TransactionInBlock

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

func (*InstrumentedClient) TransactionReceipt

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

func (*InstrumentedClient) TransactionSender

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

func (*InstrumentedClient) WaitForTransactionReceipt

func (iec *InstrumentedClient) WaitForTransactionReceipt(ctx context.Context, txHash common.Hash) *types.Receipt

TODO(samlaf): feels weird that we have to write this function ourselves

perhaps the gethClient interface should be the instrumented client,
and then ethclient can take an instrumentedGethClient?

Jump to

Keyboard shortcuts

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