2023-01-09 21:18:42 +00:00
|
|
|
package beacon_api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2023-01-09 21:18:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *beaconApiValidatorClient) submitSignedAggregateSelectionProof(ctx context.Context, in *ethpb.SignedAggregateSubmitRequest) (*ethpb.SignedAggregateSubmitResponse, error) {
|
|
|
|
body, err := json.Marshal([]*apimiddleware.SignedAggregateAttestationAndProofJson{jsonifySignedAggregateAndProof(in.SignedAggregateAndProof)})
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to marshal SignedAggregateAttestationAndProof")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := c.jsonRestHandler.PostRestJson(ctx, "/eth/v1/validator/aggregate_and_proofs", nil, bytes.NewBuffer(body), nil); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to send POST data to REST endpoint")
|
|
|
|
}
|
|
|
|
|
|
|
|
attestationDataRoot, err := in.SignedAggregateAndProof.Message.Aggregate.Data.HashTreeRoot()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to compute attestation data root")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ðpb.SignedAggregateSubmitResponse{AttestationDataRoot: attestationDataRoot[:]}, nil
|
|
|
|
}
|