2023-01-18 21:21:07 +00:00
|
|
|
package beacon_api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
2023-01-18 21:21:07 +00:00
|
|
|
)
|
|
|
|
|
2024-03-08 18:08:35 +00:00
|
|
|
func (c beaconApiValidatorClient) subscribeCommitteeSubnets(ctx context.Context, in *ethpb.CommitteeSubnetsSubscribeRequest, duties []*ethpb.DutiesResponse_Duty) error {
|
2023-01-18 21:21:07 +00:00
|
|
|
if in == nil {
|
|
|
|
return errors.New("committee subnets subscribe request is nil")
|
|
|
|
}
|
|
|
|
|
2024-03-08 18:08:35 +00:00
|
|
|
if len(in.CommitteeIds) != len(in.Slots) || len(in.CommitteeIds) != len(in.IsAggregator) || len(in.CommitteeIds) != len(duties) {
|
|
|
|
return errors.New("arrays `in.CommitteeIds`, `in.Slots`, `in.IsAggregator` and `duties` don't have the same length")
|
2023-01-18 21:21:07 +00:00
|
|
|
}
|
|
|
|
|
2024-02-03 11:57:01 +00:00
|
|
|
jsonCommitteeSubscriptions := make([]*structs.BeaconCommitteeSubscription, len(in.CommitteeIds))
|
2023-01-18 21:21:07 +00:00
|
|
|
for index := range in.CommitteeIds {
|
2024-02-03 11:57:01 +00:00
|
|
|
jsonCommitteeSubscriptions[index] = &structs.BeaconCommitteeSubscription{
|
2024-03-08 18:08:35 +00:00
|
|
|
CommitteeIndex: strconv.FormatUint(uint64(in.CommitteeIds[index]), 10),
|
|
|
|
CommitteesAtSlot: strconv.FormatUint(duties[index].CommitteesAtSlot, 10),
|
|
|
|
Slot: strconv.FormatUint(uint64(in.Slots[index]), 10),
|
|
|
|
IsAggregator: in.IsAggregator[index],
|
|
|
|
ValidatorIndex: strconv.FormatUint(uint64(duties[index].ValidatorIndex), 10),
|
2023-01-18 21:21:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
committeeSubscriptionsBytes, err := json.Marshal(jsonCommitteeSubscriptions)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to marshal committees subscriptions")
|
|
|
|
}
|
|
|
|
|
2023-12-22 22:39:20 +00:00
|
|
|
return c.jsonRestHandler.Post(
|
2023-11-21 16:42:55 +00:00
|
|
|
ctx,
|
|
|
|
"/eth/v1/validator/beacon_committee_subscriptions",
|
|
|
|
nil,
|
|
|
|
bytes.NewBuffer(committeeSubscriptionsBytes),
|
|
|
|
nil,
|
|
|
|
)
|
2023-01-18 21:21:07 +00:00
|
|
|
}
|