mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
700f5fee8c
* add context to beacon APIs * add TODO to merge GET and POST methods * fix linter action Co-authored-by: kasey <489222+kasey@users.noreply.github.com> Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package beacon_api
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"strconv"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/apimiddleware"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
func (c *beaconApiValidatorClient) prepareBeaconProposer(ctx context.Context, recipients []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer) error {
|
|
jsonRecipients := make([]*apimiddleware.FeeRecipientJson, len(recipients))
|
|
for index, recipient := range recipients {
|
|
jsonRecipients[index] = &apimiddleware.FeeRecipientJson{
|
|
FeeRecipient: hexutil.Encode(recipient.FeeRecipient),
|
|
ValidatorIndex: strconv.FormatUint(uint64(recipient.ValidatorIndex), 10),
|
|
}
|
|
}
|
|
|
|
marshalledJsonRecipients, err := json.Marshal(jsonRecipients)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to marshal recipients")
|
|
}
|
|
|
|
if _, err := c.jsonRestHandler.PostRestJson(ctx, "/eth/v1/validator/prepare_beacon_proposer", nil, bytes.NewBuffer(marshalledJsonRecipients), nil); err != nil {
|
|
return errors.Wrap(err, "failed to send POST data to REST endpoint")
|
|
}
|
|
|
|
return nil
|
|
}
|