mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 11:11:20 +00:00
a0ca4a67b0
* remove api/gateway/apimiddleware * fix errors in api/gateway * remove beacon-chain/rpc/apimiddleware * fix errors in api/client/beacon * fix errors in validator/client/beacon-api * fix errors in beacon-chain/node * fix errors in validator/node * fix errors in cmd/prysmctl/validator * fix errors in testing/endtoend * fix all other code * remove comment * fix tests --------- Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
60 lines
1.6 KiB
Go
60 lines
1.6 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/v4/beacon-chain/rpc/eth/shared"
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
func (c beaconApiValidatorClient) proposeExit(ctx context.Context, signedVoluntaryExit *ethpb.SignedVoluntaryExit) (*ethpb.ProposeExitResponse, error) {
|
|
if signedVoluntaryExit == nil {
|
|
return nil, errors.New("signed voluntary exit is nil")
|
|
}
|
|
|
|
if signedVoluntaryExit.Exit == nil {
|
|
return nil, errors.New("exit is nil")
|
|
}
|
|
|
|
jsonSignedVoluntaryExit := shared.SignedVoluntaryExit{
|
|
Message: &shared.VoluntaryExit{
|
|
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")
|
|
}
|
|
|
|
errJson, err := c.jsonRestHandler.Post(
|
|
ctx,
|
|
"/eth/v1/beacon/pool/voluntary_exits",
|
|
nil,
|
|
bytes.NewBuffer(marshalledSignedVoluntaryExit),
|
|
nil,
|
|
)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, msgUnexpectedError)
|
|
}
|
|
if errJson != nil {
|
|
return nil, errJson
|
|
}
|
|
|
|
exitRoot, err := signedVoluntaryExit.Exit.HashTreeRoot()
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to compute exit root")
|
|
}
|
|
|
|
return ðpb.ProposeExitResponse{
|
|
ExitRoot: exitRoot[:],
|
|
}, nil
|
|
}
|