Skip to content

Commit

Permalink
feat(beacon): add fetch validators
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Jan 12, 2025
1 parent 138511b commit c80e01d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit c80e01d

Please sign in to comment.