prysm-pulse/validator/client/beacon-api/registration.go
Radosław Kapka d0bf03e863
Simplify error handling for JsonRestHandler (#13369)
* Simplify error handling for `JsonRestHandler`

* POST

* reduce complexity

* review feedback

* uncomment route

* fix rest of tests
2023-12-22 22:39:20 +00:00

29 lines
910 B
Go

package beacon_api
import (
"bytes"
"context"
"encoding/json"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
)
func (c *beaconApiValidatorClient) submitValidatorRegistrations(ctx context.Context, registrations []*ethpb.SignedValidatorRegistrationV1) error {
const endpoint = "/eth/v1/validator/register_validator"
jsonRegistration := make([]*shared.SignedValidatorRegistration, len(registrations))
for index, registration := range registrations {
jsonRegistration[index] = shared.SignedValidatorRegistrationFromConsensus(registration)
}
marshalledJsonRegistration, err := json.Marshal(jsonRegistration)
if err != nil {
return errors.Wrap(err, "failed to marshal registration")
}
return c.jsonRestHandler.Post(ctx, endpoint, nil, bytes.NewBuffer(marshalledJsonRegistration), nil)
}