diff --git a/pkg/beacon/beacon.go b/pkg/beacon/beacon.go index 1329f19..ba23c12 100644 --- a/pkg/beacon/beacon.go +++ b/pkg/beacon/beacon.go @@ -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. diff --git a/pkg/beacon/fetch.go b/pkg/beacon/fetch.go index 5e9ea54..4dd3d5e 100644 --- a/pkg/beacon/fetch.go +++ b/pkg/beacon/fetch.go @@ -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 {