ethclient

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: GPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrMethodNotAvailable

func IsErrMethodNotAvailable(err error) bool

IsErrMethodNotAvailable returns true if the error indicates that the RPC method is not available on the server. This is useful to handle some endpoints that are not always enabled/configured.

func LoadJWTHexFile

func LoadJWTHexFile(file string) ([]byte, error)

LoadJWTHexFile loads a hex encoded JWT secret from the provided file.

func MockGenesisBlock

func MockGenesisBlock() (*types.Block, error)

MockGenesisBlock returns a deterministic genesis block for testing.

func MockPayloadID

func MockPayloadID(params engine.ExecutableData, beaconRoot *common.Hash) (engine.PayloadID, error)

MockPayloadID returns a deterministic payload id for the given payload.

func NewFuzzer

func NewFuzzer(seed int64) *fuzz.Fuzzer

NewFuzzer returns a new fuzzer for valid ethereum types. If seed is zero, it uses current nano time as the seed.

func WithFarFutureUpgradePlan

func WithFarFutureUpgradePlan() func(mock *engineMock)

func WithMockDelegation added in v0.13.0

func WithMockDelegation(validatorPubkey crypto.PubKey, delegatorAddr common.Address, ether int64) func(*engineMock)

WithMockDelegation returns an option to add a delegation event to the mock from the specified address.

func WithMockEditValidator added in v0.13.0

func WithMockEditValidator(pubkey crypto.PubKey, params *bindings.StakingEditValidatorParams) func(*engineMock)

WithMockEditValidator returns an option to add an edit validator event to the mock.

func WithMockSelfDelegation

func WithMockSelfDelegation(pubkey crypto.PubKey, ether int64) func(*engineMock)

WithMockSelfDelegation returns an option to add a self-delegation Delegate event to the mock.

func WithMockValidatorCreation added in v0.12.0

func WithMockValidatorCreation(pubkey crypto.PubKey) func(*engineMock)

WithMockValidatorCreation returns an option to add a validator creation event to the mock.

func WithPortalRegister

func WithPortalRegister(network netconf.Network) func(*engineMock)

func WithRandomErr

func WithRandomErr(ctx context.Context, _ *testing.T) context.Context

WithRandomErr returns a context that results in random engineMock errors. This must only be used for testing.

Types

type Client

type Client interface {
	ethereum.BlockNumberReader
	ethereum.ChainIDReader
	ethereum.ChainReader
	ethereum.ChainStateReader
	ethereum.ContractCaller
	ethereum.GasEstimator
	ethereum.GasPricer
	ethereum.GasPricer1559
	ethereum.LogFilterer
	ethereum.PendingStateReader
	ethereum.TransactionReader
	ethereum.TransactionSender
	TxReceipt(ctx context.Context, hash common.Hash) (*Receipt, error)
	HeaderByType(ctx context.Context, typ HeadType) (*types.Header, error)
	EtherBalanceAt(ctx context.Context, addr common.Address) (float64, error)
	PeerCount(ctx context.Context) (uint64, error)
	SetHead(ctx context.Context, height uint64) error
	ProgressIfSyncing(ctx context.Context) (*ethereum.SyncProgress, bool, error)
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	Address() string
	Close()
}

Client defines all ethereum interfaces used in omni.

type EngineClient

type EngineClient interface {
	Client

	// NewPayloadV3 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
	NewPayloadV3(ctx context.Context, params engine.ExecutableData, versionedHashes []common.Hash,
		beaconRoot *common.Hash) (engine.PayloadStatusV1, error)

	// ForkchoiceUpdatedV3 is equivalent to V2 with the addition of parent beacon block root in the payload attributes.
	ForkchoiceUpdatedV3(ctx context.Context, update engine.ForkchoiceStateV1,
		payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error)

	// GetPayloadV3 returns a cached payload by id.
	GetPayloadV3(ctx context.Context, payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error)
}

EngineClient defines the Engine API authenticated JSON-RPC endpoints. It extends the normal Client interface with the Engine API.

func NewAuthClient

func NewAuthClient(ctx context.Context, urlAddr string, jwtSecret []byte) (EngineClient, error)

NewAuthClient returns a new authenticated JSON-RPc engineClient.

func NewEngineMock

func NewEngineMock(opts ...func(mock *engineMock)) (EngineClient, error)

NewEngineMock returns a new mock engine API client.

Note only some methods are implemented, it will panic if you call an unimplemented method.

type HeadType

type HeadType string
const (
	HeadLatest    HeadType = "latest"
	HeadEarliest  HeadType = "earliest"
	HeadPending   HeadType = "pending"
	HeadSafe      HeadType = "safe"
	HeadFinalized HeadType = "finalized"
)

func (HeadType) String

func (h HeadType) String() string

func (HeadType) Verify

func (h HeadType) Verify() error

type Receipt added in v0.11.0

type Receipt struct {
	// Consensus fields: These fields are defined by the Yellow Paper
	Type              uint8        `json:"type,omitempty"`
	PostState         []byte       `json:"root"`
	Status            uint64       `json:"status"`
	CumulativeGasUsed uint64       `gencodec:"required"   json:"cumulativeGasUsed"`
	Bloom             types.Bloom  `gencodec:"required"   json:"logsBloom"`
	Logs              []*types.Log `gencodec:"required"   json:"logs"`

	// Implementation fields: These fields are added by geth when processing a transaction or retrieving a receipt.
	// gencodec annotated fields: these are stored in the chain database.
	TxHash            common.Hash    `gencodec:"required"           json:"transactionHash"`
	ContractAddress   common.Address `json:"contractAddress"`
	GasUsed           uint64         `gencodec:"required"           json:"gasUsed"`
	EffectiveGasPrice *big.Int       `json:"effectiveGasPrice"` // required, but tag omitted for backwards compatibility
	BlobGasUsed       uint64         `json:"blobGasUsed,omitempty"`
	BlobGasPrice      *big.Int       `json:"blobGasPrice,omitempty"`

	// Inclusion information: These fields provide information about the inclusion of the
	// transaction corresponding to this receipt.
	BlockHash        common.Hash `json:"blockHash,omitempty"`
	BlockNumber      *big.Int    `json:"blockNumber,omitempty"`
	TransactionIndex uint        `json:"transactionIndex"`

	// Optimism fields: extend receipts with L1 fee info
	OPDepositNonce          *uint64    `json:"depositNonce,omitempty"`
	OPDepositReceiptVersion *uint64    `json:"depositReceiptVersion,omitempty"`
	OPL1GasPrice            *big.Int   `json:"l1GasPrice,omitempty"`          // Present from pre-bedrock. L1 Basefee after Bedrock
	OPL1BlobBaseFee         *big.Int   `json:"l1BlobBaseFee,omitempty"`       // Always nil prior to the Ecotone hardfork
	OPL1GasUsed             *big.Int   `json:"l1GasUsed,omitempty"`           // Present from pre-bedrock, deprecated as of Fjord
	OPL1Fee                 *big.Int   `json:"l1Fee,omitempty"`               // Present from pre-bedrock
	OPL1FeeScalar           *big.Float `json:"l1FeeScalar,omitempty"`         // Present from pre-bedrock to Ecotone. Nil after Ecotone
	OPL1BaseFeeScalar       *uint64    `json:"l1BaseFeeScalar,omitempty"`     // Always nil prior to the Ecotone hardfork
	OPL1BlobBaseFeeScalar   *uint64    `json:"l1BlobBaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
}

Receipt represents the results of a transaction.

func (Receipt) MarshalJSON added in v0.11.0

func (r Receipt) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Receipt) UnmarshalJSON added in v0.11.0

func (r *Receipt) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type Wrapper

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

Wrapper wraps an ethclient.Client adding metrics and wrapped errors.

func Dial

func Dial(chainName string, url string) (Wrapper, error)

Dial connects a client to the given URL.

Note if the URL is http(s), it doesn't return an error if it cannot connect to the URL. It will retry connecting on every call to a wrapped method. It will only return an error if the url is invalid.

func NewClient

func NewClient(cl *rpc.Client, chain, address string) Wrapper

NewClient wraps an *rpc.Client adding metrics and wrapped errors.

func (Wrapper) Address

func (w Wrapper) Address() string

Address returns the underlying RPC address.

func (Wrapper) BalanceAt

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

func (Wrapper) BlockByHash

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

func (Wrapper) BlockByNumber

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

func (Wrapper) BlockNumber

func (w Wrapper) BlockNumber(ctx context.Context) (uint64, error)

func (Wrapper) CallContext added in v0.12.0

func (w Wrapper) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

func (Wrapper) CallContract

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

func (Wrapper) ChainID

func (w Wrapper) ChainID(ctx context.Context) (*big.Int, error)

func (Wrapper) Close

func (w Wrapper) Close()

Close closes the underlying RPC connection.

func (Wrapper) CodeAt

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

func (Wrapper) EstimateGas

func (w Wrapper) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)

func (Wrapper) EtherBalanceAt

func (w Wrapper) EtherBalanceAt(ctx context.Context, addr common.Address) (float64, error)

EtherBalanceAt returns the current balance in ether of the provided account. Note this converts big.Int to float64 so IS NOT accurate. Only use if accuracy is not required, i.e., for display/metrics purposes.

func (Wrapper) FilterLogs

func (w Wrapper) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

func (Wrapper) HeaderByHash

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

func (Wrapper) HeaderByNumber

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

func (Wrapper) HeaderByType

func (w Wrapper) HeaderByType(ctx context.Context, typ HeadType) (*types.Header, error)

HeaderByType returns the block header for the given head type.

func (Wrapper) NonceAt

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

func (Wrapper) PeerCount

func (w Wrapper) PeerCount(ctx context.Context) (uint64, error)

PeerCount returns the number of p2p peers as reported by the net_peerCount method.

func (Wrapper) PendingBalanceAt

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

func (Wrapper) PendingCodeAt

func (w Wrapper) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

func (Wrapper) PendingNonceAt

func (w Wrapper) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (Wrapper) PendingStorageAt

func (w Wrapper) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)

func (Wrapper) PendingTransactionCount

func (w Wrapper) PendingTransactionCount(ctx context.Context) (uint, error)

func (Wrapper) ProgressIfSyncing added in v0.11.0

func (w Wrapper) ProgressIfSyncing(ctx context.Context) (*ethereum.SyncProgress, bool, error)

ProgressIfSyncing returns the sync progress (and true) if the node is syncing else false if node is not syncing or an error.

This wrap SyncProgress which returns nil-nil if the node is not syncing which results in panics.

func (Wrapper) SendTransaction

func (w Wrapper) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (Wrapper) SetHead

func (w Wrapper) SetHead(ctx context.Context, height uint64) error

SetHead sets the current head of the local chain by block number. Note, this is a destructive action and may severely damage your chain. Use with extreme caution.

func (Wrapper) StorageAt

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

func (Wrapper) SubscribeFilterLogs

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

func (Wrapper) SubscribeNewHead

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

func (Wrapper) SuggestGasPrice

func (w Wrapper) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (Wrapper) SuggestGasTipCap

func (w Wrapper) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

func (Wrapper) TransactionByHash

func (w Wrapper) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error)

func (Wrapper) TransactionCount

func (w Wrapper) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)

func (Wrapper) TransactionInBlock

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

func (Wrapper) TransactionReceipt

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

func (Wrapper) TxReceipt added in v0.11.0

func (w Wrapper) TxReceipt(ctx context.Context, txHash common.Hash) (*Receipt, error)

TxReceipt returns the transaction receipt for the given transaction hash. It includes additional fields not present in the geth ethclient, such as OP L1 fee info.

Directories

Path Synopsis
Command genwrap provides a code generator for ethclient.Client wrapper that adds prometheus metrics and error wrapping.
Command genwrap provides a code generator for ethclient.Client wrapper that adds prometheus metrics and error wrapping.
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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