Skip to content

Commit

Permalink
Merge pull request #145 from attestantio/per-call-ssz
Browse files Browse the repository at this point in the history
Support SSZ on a per-call basis.
  • Loading branch information
mcdee authored Jun 11, 2024
2 parents 770ba2b + 2d6d5b4 commit ec55dc8
Show file tree
Hide file tree
Showing 30 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion http/aggregateattestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *Service) AggregateAttestation(ctx context.Context,

endpoint := "/eth/v1/validator/aggregate_attestation"
query := fmt.Sprintf("slot=%d&attestation_data_root=%#x", opts.Slot, opts.AttestationDataRoot)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/attestationdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *Service) AttestationData(ctx context.Context,

endpoint := "/eth/v1/validator/attestation_data"
query := fmt.Sprintf("slot=%d&committee_index=%d", opts.Slot, opts.CommitteeIndex)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/attestationpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *Service) AttestationPool(ctx context.Context,

endpoint := "/eth/v1/beacon/pool/attestations"
query := fmt.Sprintf("slot=%d", opts.Slot)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/beaconblockheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *Service) BeaconBlockHeader(ctx context.Context,
}

endpoint := fmt.Sprintf("/eth/v1/beacon/headers/%s", opts.Block)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/beaconblockroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *Service) BeaconBlockRoot(ctx context.Context,
}

endpoint := fmt.Sprintf("/eth/v1/beacon/blocks/%s/root", opts.Block)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/beaconcommittees.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Service) BeaconCommittees(ctx context.Context,
query = fmt.Sprintf("epoch=%d", *opts.Epoch)
}

httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/beaconstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *Service) BeaconState(ctx context.Context,
}

endpoint := fmt.Sprintf("/eth/v2/debug/beacon/states/%s", opts.State)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/beaconstaterandao.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Service) BeaconStateRandao(ctx context.Context, opts *api.BeaconStateRa
}

endpoint := fmt.Sprintf("/eth/v1/beacon/states/%s/randao", opts.State)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/beaconstateroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Service) BeaconStateRoot(ctx context.Context, opts *api.BeaconStateRoot
}

endpoint := fmt.Sprintf("/eth/v1/beacon/states/%s/root", opts.State)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/blindedproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *Service) BlindedProposal(ctx context.Context,
query = fmt.Sprintf("%s&skip_randao_verification", query)
}

res, err := s.get(ctx, endpoint, query, &opts.Common)
res, err := s.get(ctx, endpoint, query, &opts.Common, true)
if err != nil {
return nil, errors.Join(errors.New("failed to request blinded beacon block proposal"), err)
}
Expand Down
2 changes: 1 addition & 1 deletion http/blobsidecars.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Service) BlobSidecars(ctx context.Context,
}

endpoint := fmt.Sprintf("/eth/v1/beacon/blob_sidecars/%s", opts.Block)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/depositcontract.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Service) DepositContract(ctx context.Context,

// Up to us to fetch the information.
endpoint := "/eth/v1/config/deposit_contract"
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/finality.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *Service) Finality(ctx context.Context,
}

endpoint := fmt.Sprintf("/eth/v1/beacon/states/%s/finality_checkpoints", opts.State)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Service) Fork(ctx context.Context,
}

endpoint := fmt.Sprintf("/eth/v1/beacon/states/%s/fork", opts.State)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *Service) ForkChoice(ctx context.Context,
}

endpoint := "/eth/v1/debug/fork_choice"
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/forkschedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Service) ForkSchedule(ctx context.Context,

// Up to us to fetch the information.
endpoint := "/eth/v1/config/fork_schedule"
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *Service) Genesis(ctx context.Context,

// Up to us to fetch the information.
endpoint := "/eth/v1/beacon/genesis"
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, errors.Join(errors.New("failed to request genesis"), err)
}
Expand Down
5 changes: 4 additions & 1 deletion http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,13 @@ type httpResponse struct {
}

// get sends an HTTP get request and returns the response.
//
//nolint:revive
func (s *Service) get(ctx context.Context,
endpoint string,
query string,
opts *api.CommonOpts,
supportsSSZ bool,
) (
*httpResponse,
error,
Expand Down Expand Up @@ -318,7 +321,7 @@ func (s *Service) get(ctx context.Context,
}

s.addExtraHeaders(req)
if s.enforceJSON {
if s.enforceJSON || !supportsSSZ {
// JSON only.
req.Header.Set("Accept", "application/json")
} else {
Expand Down
2 changes: 1 addition & 1 deletion http/nodepeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *Service) NodePeers(ctx context.Context, opts *api.NodePeersOpts) (*api.
query = strings.Join(additionalFields, "&")
}

httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/nodesyncing.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *Service) NodeSyncing(ctx context.Context, opts *api.NodeSyncingOpts) (*
}

endpoint := "/eth/v1/node/syncing"
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/nodeversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *Service) NodeVersion(ctx context.Context,

// Up to us to fetch the information.
endpoint := "/eth/v1/node/version"
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s *Service) Proposal(ctx context.Context,
query = fmt.Sprintf("%s&builder_boost_factor=%d", query, *opts.BuilderBoostFactor)
}

httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, true)
if err != nil {
return nil, errors.Join(errors.New("failed to request beacon block proposal"), err)
}
Expand Down
2 changes: 1 addition & 1 deletion http/proposerduties.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *Service) ProposerDuties(ctx context.Context,
}

endpoint := fmt.Sprintf("/eth/v1/validator/duties/proposer/%d", opts.Epoch)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/signedbeaconblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *Service) SignedBeaconBlock(ctx context.Context,
}

endpoint := fmt.Sprintf("/eth/v2/beacon/blocks/%s", opts.Block)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *Service) Spec(ctx context.Context,

// Up to us to fetch the information.
endpoint := "/eth/v1/config/spec"
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/synccommittee.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Service) SyncCommittee(ctx context.Context,
query = fmt.Sprintf("epoch=%d", *opts.Epoch)
}

httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/synccommitteecontribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Service) SyncCommitteeContribution(ctx context.Context,
opts.SubcommitteeIndex,
opts.BeaconBlockRoot,
)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/validatorbalances.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *Service) ValidatorBalances(ctx context.Context,
query = "id=" + strings.Join(ids, ",")
}

httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (s *Service) Validators(ctx context.Context,
}
}

httpResponse, err := s.get(ctx, endpoint, query, &opts.Common)
httpResponse, err := s.get(ctx, endpoint, query, &opts.Common, false)
if err != nil {
return nil, errors.Join(errors.New("failed to request validators"), err)
}
Expand Down
2 changes: 1 addition & 1 deletion http/voluntaryexitpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *Service) VoluntaryExitPool(ctx context.Context,
}

endpoint := "/eth/v1/beacon/pool/voluntary_exits"
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common)
httpResponse, err := s.get(ctx, endpoint, "", &opts.Common, false)
if err != nil {
return nil, errors.Join(errors.New("failed to request voluntary exit pool"), err)
}
Expand Down

0 comments on commit ec55dc8

Please sign in to comment.