Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(beacon): add fetch validators #31

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type Node interface {
FetchBeaconStateRoot(ctx context.Context, stateID string) (phase0.Root, error)
// FetchRawBeaconState fetches the raw, unparsed beacon state for the given state id.
FetchRawBeaconState(ctx context.Context, stateID string, contentType string) ([]byte, error)
// FetchValidators fetches the validators for the given state id and validator ids.
FetchValidators(ctx context.Context, state string, indices []phase0.ValidatorIndex, pubKeys []phase0.BLSPubKey) (map[phase0.ValidatorIndex]*v1.Validator, error)
// FetchFinality fetches the finality checkpoint for the state id.
FetchFinality(ctx context.Context, stateID string) (*v1.Finality, error)
// FetchGenesis fetches the genesis configuration.
Expand Down
18 changes: 18 additions & 0 deletions pkg/beacon/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ func (n *node) FetchBeaconStateRoot(ctx context.Context, state string) (phase0.R
return *rsp.Data, nil
}

func (n *node) FetchValidators(ctx context.Context, state string, indices []phase0.ValidatorIndex, pubKeys []phase0.BLSPubKey) (map[phase0.ValidatorIndex]*v1.Validator, error) {
provider, isProvider := n.client.(eth2client.ValidatorsProvider)
if !isProvider {
return nil, errors.New("client does not implement eth2client.ValidatorsProvider")
}

rsp, err := provider.Validators(ctx, &api.ValidatorsOpts{
State: state,
Indices: indices,
PubKeys: pubKeys,
})
if err != nil {
return nil, err
}

return rsp.Data, nil
}

func (n *node) FetchBeaconCommittees(ctx context.Context, state string, epoch *phase0.Epoch) ([]*v1.BeaconCommittee, error) {
provider, isProvider := n.client.(eth2client.BeaconCommitteesProvider)
if !isProvider {
Expand Down
Loading