prysm-pulse/validator/client/beacon-api/sync_committee_selections.go
Dhruv Bodani e100fb0c08
Add support for sync committee selections (#13633)
* add support for sync committee selections

* go mod tidy

* remove unused fields

* fix build

* fix build

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2024-02-23 13:53:42 +00:00

36 lines
1019 B
Go

package beacon_api
import (
"bytes"
"context"
"encoding/json"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/validator/client/iface"
)
type aggregatedSyncSelectionResponse struct {
Data []iface.SyncCommitteeSelection `json:"data"`
}
func (c *beaconApiValidatorClient) getAggregatedSyncSelections(ctx context.Context, selections []iface.SyncCommitteeSelection) ([]iface.SyncCommitteeSelection, error) {
body, err := json.Marshal(selections)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal selections")
}
var resp aggregatedSyncSelectionResponse
err = c.jsonRestHandler.Post(ctx, "/eth/v1/validator/sync_committee_selections", nil, bytes.NewBuffer(body), &resp)
if err != nil {
return nil, errors.Wrap(err, "error calling post endpoint")
}
if len(resp.Data) == 0 {
return nil, errors.New("no aggregated sync selections returned")
}
if len(selections) != len(resp.Data) {
return nil, errors.New("mismatching number of sync selections")
}
return resp.Data, nil
}