2023-01-06 19:46:09 +00:00
|
|
|
package beacon_api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2024-02-03 11:57:01 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/api/server/structs"
|
2023-03-17 18:52:56 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2023-01-06 19:46:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *beaconApiValidatorClient) submitValidatorRegistrations(ctx context.Context, registrations []*ethpb.SignedValidatorRegistrationV1) error {
|
|
|
|
const endpoint = "/eth/v1/validator/register_validator"
|
|
|
|
|
2024-02-03 11:57:01 +00:00
|
|
|
jsonRegistration := make([]*structs.SignedValidatorRegistration, len(registrations))
|
2023-01-06 19:46:09 +00:00
|
|
|
|
|
|
|
for index, registration := range registrations {
|
2024-02-03 11:57:01 +00:00
|
|
|
jsonRegistration[index] = structs.SignedValidatorRegistrationFromConsensus(registration)
|
2023-01-06 19:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
marshalledJsonRegistration, err := json.Marshal(jsonRegistration)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to marshal registration")
|
|
|
|
}
|
|
|
|
|
2023-12-22 22:39:20 +00:00
|
|
|
return c.jsonRestHandler.Post(ctx, endpoint, nil, bytes.NewBuffer(marshalledJsonRegistration), nil)
|
2023-01-06 19:46:09 +00:00
|
|
|
}
|