http

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 49 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIncorrectType = errors.New("incorrect response type")

ErrIncorrectType is returned when the multi client obtain a response type it is not expecting.

Functions

func New

func New(ctx context.Context, params ...Parameter) (client.Service, error)

New creates a new Ethereum 2 client service, connecting with a standard HTTP.

Types

type ContentType

type ContentType int

ContentType defines the builder spec version.

const (
	// ContentTypeUnknown implies an unknown content type.
	ContentTypeUnknown ContentType = iota
	// ContentTypeSSZ implies an SSZ content type.
	ContentTypeSSZ
	// ContentTypeJSON implies a JSON content type.
	ContentTypeJSON
)

func ParseFromMediaType

func ParseFromMediaType(input string) (ContentType, error)

ParseFromMediaType parses a content type string as per http://www.iana.org/assignments/media-types/media-types.xhtml

func (*ContentType) MarshalJSON

func (c *ContentType) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (ContentType) MediaType

func (c ContentType) MediaType() string

MediaType returns the IANA name of the media type.

func (ContentType) String

func (c ContentType) String() string

String returns a string representation of the struct.

func (*ContentType) UnmarshalJSON

func (c *ContentType) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

type HookFunc

type HookFunc func(ctx context.Context, s *Service)

HookFunc is a function called when a hook is triggered.

type Hooks

type Hooks struct {
	OnActive   HookFunc
	OnInactive HookFunc
	OnSynced   HookFunc
	OnDesynced HookFunc
}

Hooks provides hooks that will be called when certain events occur.

type Parameter

type Parameter interface {
	// contains filtered or unexported methods
}

Parameter is the interface for service parameters.

func WithAddress

func WithAddress(address string) Parameter

WithAddress provides the address for the endpoint.

func WithAllowDelayedStart

func WithAllowDelayedStart(allowDelayedStart bool) Parameter

WithAllowDelayedStart allows the service to start even if the client is unavailable.

func WithCustomSpecSupport

func WithCustomSpecSupport(customSpecSupport bool) Parameter

WithCustomSpecSupport switches from the built in static SSZ library to a new dynamic SSZ library, which is able to handle non-mainnet presets. Dynamic SSZ en-/decoding is much slower than the static one, so this should only be used if required.

func WithEnforceJSON

func WithEnforceJSON(enforceJSON bool) Parameter

WithEnforceJSON forces all requests and responses to be in JSON, not sending or requesting SSZ.

func WithExtraHeaders

func WithExtraHeaders(headers map[string]string) Parameter

WithExtraHeaders sets additional headers to be sent with each HTTP request.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Parameter

WithHTTPClient provides a custom HTTP client for communication with the HTTP server. If not supplied then a standard HTTP client is used.

func WithHooks

func WithHooks(hooks *Hooks) Parameter

WithHooks sets the hooks for client activation and sync events.

func WithIndexChunkSize

func WithIndexChunkSize(indexChunkSize int) Parameter

WithIndexChunkSize sets the maximum number of indices to send for individual validator requests.

func WithLogLevel

func WithLogLevel(logLevel zerolog.Level) Parameter

WithLogLevel sets the log level for the module.

func WithMonitor

func WithMonitor(monitor metrics.Service) Parameter

WithMonitor sets the monitor for the service.

func WithPubKeyChunkSize

func WithPubKeyChunkSize(pubKeyChunkSize int) Parameter

WithPubKeyChunkSize sets the maximum number of public keys to send for individual validator requests.

func WithReducedMemoryUsage

func WithReducedMemoryUsage(reducedMemoryUsage bool) Parameter

WithReducedMemoryUsage reduces memory usage by disabling certain actions that may take significant amount of memory. Enabling this may result in longer response times.

func WithTimeout

func WithTimeout(timeout time.Duration) Parameter

WithTimeout sets the maximum duration for all requests to the endpoint.

type Service

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

Service is an Ethereum 2 client service.

func (*Service) Address

func (s *Service) Address() string

Address provides the address for the connection.

func (*Service) AggregateAttestation

func (s *Service) AggregateAttestation(ctx context.Context,
	opts *api.AggregateAttestationOpts,
) (
	*api.Response[*spec.VersionedAttestation],
	error,
)

AggregateAttestation fetches the aggregate attestation for the given options.

func (*Service) AgnosticBeaconState added in v0.1.2

func (s *Service) AgnosticBeaconState(ctx context.Context,
	opts *api.BeaconStateOpts,
) (
	*api.Response[*all.BeaconState],
	error,
)

AgnosticBeaconState fetches a beacon state and decodes it directly into a fork-agnostic *all.BeaconState. The Version is set from the consensus version header before unmarshaling so the union type's view-aware codec dispatches into the correct fork's schema. No intermediate copy.

func (*Service) AgnosticSignedBeaconBlock added in v0.1.2

func (s *Service) AgnosticSignedBeaconBlock(ctx context.Context,
	opts *api.SignedBeaconBlockOpts,
) (
	*api.Response[*all.SignedBeaconBlock],
	error,
)

AgnosticSignedBeaconBlock fetches a signed beacon block and decodes it directly into a fork-agnostic *all.SignedBeaconBlock. The Version is set from the consensus version header before unmarshaling so the union type's view-aware codec dispatches into the correct fork's schema. No intermediate copy.

func (*Service) AgnosticSignedExecutionPayloadEnvelope added in v0.1.2

func (s *Service) AgnosticSignedExecutionPayloadEnvelope(ctx context.Context,
	opts *api.SignedExecutionPayloadEnvelopeOpts,
) (
	*api.Response[*all.SignedExecutionPayloadEnvelope],
	error,
)

AgnosticSignedExecutionPayloadEnvelope fetches a signed execution payload envelope and decodes it directly into a fork-agnostic *all.SignedExecutionPayloadEnvelope. The Version is set from the consensus version header before unmarshaling so the union type's view-aware codec dispatches into the correct fork's schema. No intermediate copy.

func (*Service) AttestationData

func (s *Service) AttestationData(ctx context.Context,
	opts *api.AttestationDataOpts,
) (
	*api.Response[*phase0.AttestationData],
	error,
)

AttestationData obtains attestation data given the options.

func (*Service) AttestationPool

func (s *Service) AttestationPool(ctx context.Context,
	opts *api.AttestationPoolOpts,
) (
	*api.Response[[]*spec.VersionedAttestation],
	error,
)

AttestationPool obtains the attestation pool for the given options.

func (*Service) AttestationRewards

func (s *Service) AttestationRewards(ctx context.Context,
	opts *api.AttestationRewardsOpts,
) (
	*api.Response[*apiv1.AttestationRewards],
	error,
)

AttestationRewards provides rewards to the given validators for attesting.

func (*Service) AttesterDuties

func (s *Service) AttesterDuties(ctx context.Context,
	opts *api.AttesterDutiesOpts,
) (
	*api.Response[[]*apiv1.AttesterDuty],
	error,
)

AttesterDuties obtains attester duties.

func (*Service) BeaconBlockHeader

func (s *Service) BeaconBlockHeader(ctx context.Context,
	opts *api.BeaconBlockHeaderOpts,
) (
	*api.Response[*apiv1.BeaconBlockHeader],
	error,
)

BeaconBlockHeader provides the block header given the opts.

func (*Service) BeaconBlockRoot

func (s *Service) BeaconBlockRoot(ctx context.Context,
	opts *api.BeaconBlockRootOpts,
) (
	*api.Response[*phase0.Root],
	error,
)

BeaconBlockRoot fetches a block's root given a set of options.

func (*Service) BeaconCommitteeSelections added in v0.1.0

func (s *Service) BeaconCommitteeSelections(ctx context.Context,
	opts *api.BeaconCommitteeSelectionsOpts,
) (
	*api.Response[[]*apiv1.BeaconCommitteeSelection],
	error,
)

BeaconCommitteeSelections obtains beacon committee selections.

func (*Service) BeaconCommittees

func (s *Service) BeaconCommittees(ctx context.Context,
	opts *api.BeaconCommitteesOpts,
) (
	*api.Response[[]*apiv1.BeaconCommittee],
	error,
)

BeaconCommittees fetches all beacon committees for the epoch at the given state.

func (*Service) BeaconState

func (s *Service) BeaconState(ctx context.Context,
	opts *api.BeaconStateOpts,
) (
	*api.Response[*spec.VersionedBeaconState],
	error,
)

BeaconState fetches a beacon state given a state ID and decodes it directly into the per-fork view stored on a *spec.VersionedBeaconState. No intermediate copy.

func (*Service) BeaconStateRandao

func (s *Service) BeaconStateRandao(ctx context.Context, opts *api.BeaconStateRandaoOpts) (*api.Response[*phase0.Root], error)

BeaconStateRandao fetches the beacon state RANDAO given a set of options.

func (*Service) BeaconStateRoot

func (s *Service) BeaconStateRoot(ctx context.Context, opts *api.BeaconStateRootOpts) (*api.Response[*phase0.Root], error)

BeaconStateRoot fetches the beacon state root given a set of options.

func (*Service) BlindedProposal deprecated

func (s *Service) BlindedProposal(ctx context.Context,
	opts *api.BlindedProposalOpts,
) (
	*api.Response[*api.VersionedBlindedProposal],
	error,
)

BlindedProposal fetches a proposal for signing.

Deprecated: use `Proposal` instead.

func (*Service) BlobSidecars

func (s *Service) BlobSidecars(ctx context.Context,
	opts *api.BlobSidecarsOpts,
) (
	*api.Response[[]*deneb.BlobSidecar],
	error,
)

BlobSidecars fetches the blobs sidecars given options.

func (*Service) Blobs

func (s *Service) Blobs(ctx context.Context,
	opts *api.BlobsOpts,
) (
	*api.Response[apiv1.Blobs],
	error,
)

Blobs fetches the blobs given options.

func (*Service) BlockRewards

func (s *Service) BlockRewards(ctx context.Context,
	opts *api.BlockRewardsOpts,
) (
	*api.Response[*apiv1.BlockRewards],
	error,
)

BlockRewards provides rewards for proposing a block.

func (*Service) CheckConnectionState

func (s *Service) CheckConnectionState(ctx context.Context)

CheckConnectionState checks the connection state for the client, potentially updating its activation and sync states. This will call hooks supplied when creating the client if the state changes.

func (*Service) DepositContract

func (s *Service) DepositContract(ctx context.Context,
	opts *api.DepositContractOpts,
) (
	*api.Response[*apiv1.DepositContract],
	error,
)

DepositContract provides details of the execution deposit contract for the chain.

func (*Service) Domain

func (s *Service) Domain(ctx context.Context, domainType phase0.DomainType, epoch phase0.Epoch) (phase0.Domain, error)

Domain provides a domain for a given domain type at a given epoch.

func (*Service) EpochFromStateID

func (s *Service) EpochFromStateID(ctx context.Context, stateID string) (phase0.Epoch, error)

EpochFromStateID parses the state ID and returns the relevant epoch.

func (*Service) Events

func (s *Service) Events(ctx context.Context, opts *api.EventsOpts) error

Events feeds requested events with the given topics to the supplied handler.

func (*Service) FarFutureEpoch

func (*Service) FarFutureEpoch(_ context.Context) (phase0.Epoch, error)

FarFutureEpoch provides the values for FAR_FUTURE_EPOCH of the chain.

func (*Service) Finality

func (s *Service) Finality(ctx context.Context,
	opts *api.FinalityOpts,
) (
	*api.Response[*apiv1.Finality],
	error,
)

Finality provides the finality given a state ID.

func (*Service) Fork

func (s *Service) Fork(ctx context.Context,
	opts *api.ForkOpts,
) (
	*api.Response[*phase0.Fork],
	error,
)

Fork fetches fork information for the given options.

func (*Service) ForkChoice

func (s *Service) ForkChoice(ctx context.Context,
	opts *api.ForkChoiceOpts,
) (
	*api.Response[*apiv1.ForkChoice],
	error,
)

ForkChoice fetches all current fork choice context.

func (*Service) ForkSchedule

func (s *Service) ForkSchedule(ctx context.Context,
	opts *api.ForkScheduleOpts,
) (
	*api.Response[[]*phase0.Fork],
	error,
)

ForkSchedule provides details of past and future changes in the chain's fork version.

func (*Service) Genesis

func (s *Service) Genesis(ctx context.Context,
	opts *api.GenesisOpts,
) (
	*api.Response[*apiv1.Genesis],
	error,
)

Genesis provides the genesis information of the chain.

func (*Service) GenesisDomain

func (s *Service) GenesisDomain(ctx context.Context, domainType phase0.DomainType) (phase0.Domain, error)

GenesisDomain returns the domain for the given domain type at genesis. N.B. this is not always the same as the domain at epoch 0. It is possible for a chain's fork schedule to have multiple forks at genesis. In this situation, GenesisDomain() will return the first, and Domain() will return the last.

func (*Service) GenesisTime

func (s *Service) GenesisTime(ctx context.Context) (time.Time, error)

GenesisTime provides the genesis time of the chain.

func (*Service) IsActive

func (s *Service) IsActive() bool

IsActive returns true if the client is active.

func (*Service) IsSynced

func (s *Service) IsSynced() bool

IsSynced returns true if the client is synced.

func (*Service) Name

func (*Service) Name() string

Name provides the name of the service.

func (*Service) NodeClient

func (s *Service) NodeClient(ctx context.Context) (*api.Response[string], error)

NodeClient provides the client for the node.

func (*Service) NodePeers

func (s *Service) NodePeers(ctx context.Context, opts *api.NodePeersOpts) (*api.Response[[]*apiv1.Peer], error)

NodePeers obtains the peers of a node.

func (*Service) NodeSyncing

func (s *Service) NodeSyncing(ctx context.Context, opts *api.NodeSyncingOpts) (*api.Response[*apiv1.SyncState], error)

NodeSyncing provides the syncing information for the node.

func (*Service) NodeVersion

func (s *Service) NodeVersion(ctx context.Context,
	opts *api.NodeVersionOpts,
) (
	*api.Response[string],
	error,
)

NodeVersion provides the version information of the node.

func (*Service) PendingConsolidations

func (s *Service) PendingConsolidations(ctx context.Context,
	opts *api.PendingConsolidationsOpts,
) (
	*api.Response[[]*electra.PendingConsolidation],
	error,
)

PendingConsolidations returns the pending consolidations for a given state.

func (*Service) PendingDeposits

func (s *Service) PendingDeposits(ctx context.Context,
	opts *api.PendingDepositsOpts,
) (
	*api.Response[[]*electra.PendingDeposit],
	error,
)

PendingDeposits returns the pending deposits for a given state.

func (*Service) PendingPartialWithdrawals

func (s *Service) PendingPartialWithdrawals(ctx context.Context,
	opts *api.PendingPartialWithdrawalsOpts,
) (
	*api.Response[[]*electra.PendingPartialWithdrawal],
	error,
)

PendingPartialWithdrawals returns the pending partial withdrawals for a given state.

func (*Service) Proposal

func (s *Service) Proposal(ctx context.Context,
	opts *api.ProposalOpts,
) (
	*api.Response[*api.VersionedProposal],
	error,
)

Proposal fetches a potential beacon block for signing.

func (*Service) ProposerDuties

func (s *Service) ProposerDuties(ctx context.Context,
	opts *api.ProposerDutiesOpts,
) (
	*api.Response[[]*apiv1.ProposerDuty],
	error,
)

ProposerDuties obtains proposer duties for the given options.

func (*Service) SignedBeaconBlock

func (s *Service) SignedBeaconBlock(ctx context.Context,
	opts *api.SignedBeaconBlockOpts,
) (
	*api.Response[*spec.VersionedSignedBeaconBlock],
	error,
)

SignedBeaconBlock fetches a signed beacon block given a block ID and decodes it directly into the per-fork view stored on a *spec.VersionedSignedBeaconBlock. No intermediate copy.

func (*Service) SignedExecutionPayloadEnvelope

SignedExecutionPayloadEnvelope fetches a signed execution payload envelope given a block ID and decodes it directly into the per-fork view stored on a *spec.VersionedSignedExecutionPayloadEnvelope. No intermediate copy.

func (*Service) SlotDuration

func (s *Service) SlotDuration(ctx context.Context) (time.Duration, error)

SlotDuration provides the duration of a slot for the chain.

func (*Service) SlotFromStateID

func (*Service) SlotFromStateID(_ context.Context, stateID string) (phase0.Slot, error)

SlotFromStateID parses the state ID and returns the relevant slot.

func (*Service) SlotsPerEpoch

func (s *Service) SlotsPerEpoch(ctx context.Context) (uint64, error)

SlotsPerEpoch provides the number of slots per epoch for the chain.

func (*Service) Spec

func (s *Service) Spec(ctx context.Context,
	opts *api.SpecOpts,
) (
	*api.Response[map[string]any],
	error,
)

Spec provides the spec information of the chain.

func (*Service) SubmitAggregateAttestations

func (s *Service) SubmitAggregateAttestations(ctx context.Context, opts *api.SubmitAggregateAttestationsOpts) error

SubmitAggregateAttestations submits aggregate attestations.

func (*Service) SubmitAttestations

func (s *Service) SubmitAttestations(ctx context.Context, opts *api.SubmitAttestationsOpts) error

SubmitAttestations submits versioned attestations.

func (*Service) SubmitAttesterSlashing

func (s *Service) SubmitAttesterSlashing(ctx context.Context, slashing *phase0.AttesterSlashing) error

SubmitAttesterSlashing submits an attester slashing.

func (*Service) SubmitBLSToExecutionChanges

func (s *Service) SubmitBLSToExecutionChanges(ctx context.Context,
	blsToExecutionChanges []*capella.SignedBLSToExecutionChange,
) error

SubmitBLSToExecutionChanges submits BLS to execution address change operations.

func (*Service) SubmitBeaconBlock deprecated

func (s *Service) SubmitBeaconBlock(ctx context.Context, block *spec.VersionedSignedBeaconBlock) error

SubmitBeaconBlock submits a beacon block.

Deprecated: this will not work from the deneb hard-fork onwards. Use SubmitProposal() instead.

func (*Service) SubmitBeaconCommitteeSubscriptions

func (s *Service) SubmitBeaconCommitteeSubscriptions(ctx context.Context,
	subscriptions []*apiv1.BeaconCommitteeSubscription,
) error

SubmitBeaconCommitteeSubscriptions subscribes to beacon committees.

func (*Service) SubmitBlindedBeaconBlock deprecated

func (s *Service) SubmitBlindedBeaconBlock(ctx context.Context, block *api.VersionedSignedBlindedBeaconBlock) error

SubmitBlindedBeaconBlock submits a blinded beacon block.

Deprecated: this will not work from the deneb hard-fork onwards. Use SubmitBlindedProposal() instead.

func (*Service) SubmitBlindedProposal

func (s *Service) SubmitBlindedProposal(ctx context.Context,
	opts *api.SubmitBlindedProposalOpts,
) error

SubmitBlindedProposal submits a blinded proposal.

func (*Service) SubmitProposal

func (s *Service) SubmitProposal(ctx context.Context,
	opts *api.SubmitProposalOpts,
) error

SubmitProposal submits a proposal.

func (*Service) SubmitProposalPreparations

func (s *Service) SubmitProposalPreparations(ctx context.Context, preparations []*apiv1.ProposalPreparation) error

SubmitProposalPreparations provides the beacon node with information required if a proposal for the given validators shows up in the next epoch.

func (*Service) SubmitProposalSlashing

func (s *Service) SubmitProposalSlashing(ctx context.Context, slashing *phase0.ProposerSlashing) error

SubmitProposalSlashing submits a proposal slashing.

func (*Service) SubmitSyncCommitteeContributions

func (s *Service) SubmitSyncCommitteeContributions(ctx context.Context,
	contributionAndProofs []*altair.SignedContributionAndProof,
) error

SubmitSyncCommitteeContributions submits sync committee contributions.

func (*Service) SubmitSyncCommitteeMessages

func (s *Service) SubmitSyncCommitteeMessages(ctx context.Context, messages []*altair.SyncCommitteeMessage) error

SubmitSyncCommitteeMessages submits sync committee messages.

func (*Service) SubmitSyncCommitteeSubscriptions

func (s *Service) SubmitSyncCommitteeSubscriptions(ctx context.Context, subscriptions []*apiv1.SyncCommitteeSubscription) error

SubmitSyncCommitteeSubscriptions subscribes to sync committees.

func (*Service) SubmitValidatorRegistrations

func (s *Service) SubmitValidatorRegistrations(ctx context.Context,
	registrations []*api.VersionedSignedValidatorRegistration,
) error

SubmitValidatorRegistrations submits a validator registration.

func (*Service) SubmitVoluntaryExit

func (s *Service) SubmitVoluntaryExit(ctx context.Context, voluntaryExit *phase0.SignedVoluntaryExit) error

SubmitVoluntaryExit submits a voluntary exit.

func (*Service) SyncCommittee

func (s *Service) SyncCommittee(ctx context.Context,
	opts *api.SyncCommitteeOpts,
) (
	*api.Response[*apiv1.SyncCommittee],
	error,
)

SyncCommittee fetches the sync committee for epoch at the given state.

func (*Service) SyncCommitteeContribution

func (s *Service) SyncCommitteeContribution(ctx context.Context,
	opts *api.SyncCommitteeContributionOpts,
) (
	*api.Response[*altair.SyncCommitteeContribution],
	error,
)

SyncCommitteeContribution provides a sync committee contribution.

func (*Service) SyncCommitteeDuties

func (s *Service) SyncCommitteeDuties(ctx context.Context,
	opts *api.SyncCommitteeDutiesOpts,
) (
	*api.Response[[]*apiv1.SyncCommitteeDuty],
	error,
)

SyncCommitteeDuties obtains sync committee duties.

func (*Service) SyncCommitteeRewards

func (s *Service) SyncCommitteeRewards(ctx context.Context,
	opts *api.SyncCommitteeRewardsOpts,
) (
	*api.Response[[]*apiv1.SyncCommitteeReward],
	error,
)

SyncCommitteeRewards provides rewards to the given validators for being members of a sync committee.

func (*Service) TargetAggregatorsPerCommittee

func (s *Service) TargetAggregatorsPerCommittee(ctx context.Context) (uint64, error)

TargetAggregatorsPerCommittee provides the target aggregators per committee of the chain.

func (*Service) ValidatorBalances

func (s *Service) ValidatorBalances(ctx context.Context,
	opts *api.ValidatorBalancesOpts,
) (
	*api.Response[map[phase0.ValidatorIndex]phase0.Gwei],
	error,
)

ValidatorBalances provides the validator balances for the given options.

func (*Service) ValidatorLiveness

func (s *Service) ValidatorLiveness(
	ctx context.Context,
	opts *api.ValidatorLivenessOpts,
) (
	*api.Response[[]*apiv1.ValidatorLiveness],
	error,
)

ValidatorLiveness provides the liveness data to the given validators.

func (*Service) Validators

func (s *Service) Validators(ctx context.Context,
	opts *api.ValidatorsOpts,
) (
	*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator],
	error,
)

Validators provides the validators, with their balance and status, for the given options.

func (*Service) VoluntaryExitPool

func (s *Service) VoluntaryExitPool(ctx context.Context,
	opts *api.VoluntaryExitPoolOpts,
) (
	*api.Response[[]*phase0.SignedVoluntaryExit],
	error,
)

VoluntaryExitPool obtains the voluntary exit pool.

Jump to

Keyboard shortcuts

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