2022-12-19 12:58:52 +00:00
|
|
|
package beacon_api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2023-01-06 03:32:13 +00:00
|
|
|
"context"
|
2022-12-19 12:58:52 +00:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2023-01-06 03:32:13 +00:00
|
|
|
func (c beaconApiValidatorClient) proposeExit(ctx context.Context, signedVoluntaryExit *ethpb.SignedVoluntaryExit) (*ethpb.ProposeExitResponse, error) {
|
2022-12-19 12:58:52 +00:00
|
|
|
if signedVoluntaryExit == nil {
|
|
|
|
return nil, errors.New("signed voluntary exit is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if signedVoluntaryExit.Exit == nil {
|
|
|
|
return nil, errors.New("exit is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonSignedVoluntaryExit := apimiddleware.SignedVoluntaryExitJson{
|
|
|
|
Exit: &apimiddleware.VoluntaryExitJson{
|
|
|
|
Epoch: strconv.FormatUint(uint64(signedVoluntaryExit.Exit.Epoch), 10),
|
|
|
|
ValidatorIndex: strconv.FormatUint(uint64(signedVoluntaryExit.Exit.ValidatorIndex), 10),
|
|
|
|
},
|
|
|
|
Signature: hexutil.Encode(signedVoluntaryExit.Signature),
|
|
|
|
}
|
|
|
|
|
|
|
|
marshalledSignedVoluntaryExit, err := json.Marshal(jsonSignedVoluntaryExit)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to marshal signed voluntary exit")
|
|
|
|
}
|
|
|
|
|
2023-01-06 03:32:13 +00:00
|
|
|
if _, err := c.jsonRestHandler.PostRestJson(ctx, "/eth/v1/beacon/pool/voluntary_exits", nil, bytes.NewBuffer(marshalledSignedVoluntaryExit), nil); err != nil {
|
2022-12-19 12:58:52 +00:00
|
|
|
return nil, errors.Wrap(err, "failed to send POST data to REST endpoint")
|
|
|
|
}
|
|
|
|
|
|
|
|
exitRoot, err := signedVoluntaryExit.Exit.HashTreeRoot()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to compute exit root")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ðpb.ProposeExitResponse{
|
|
|
|
ExitRoot: exitRoot[:],
|
|
|
|
}, nil
|
|
|
|
}
|