-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename BeaconBlockBlobs to BlobSidecars.
- Loading branch information
Showing
18 changed files
with
269 additions
and
470 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright © 2023 Attestant Limited. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package api | ||
|
||
import ( | ||
"github.com/attestantio/go-eth2-client/spec/deneb" | ||
ssz "github.com/ferranbt/fastssz" | ||
) | ||
|
||
// BlobSidecars is an API construct to allow decoding an array of blob sidecars. | ||
type BlobSidecars struct { | ||
Sidecars []*deneb.BlobSidecar `ssz-max:"6"` | ||
} | ||
|
||
// UnmarshalSSZ ssz unmarshals the BlobSidecars object. | ||
// This is a hand-crafted function, as automatic generation does not support immediate arrays. | ||
func (b *BlobSidecars) UnmarshalSSZ(buf []byte) error { | ||
num, err := ssz.DivideInt2(len(buf), 131256, 6) | ||
if err != nil { | ||
return err | ||
} | ||
b.Sidecars = make([]*deneb.BlobSidecar, num) | ||
for ii := 0; ii < num; ii++ { | ||
if b.Sidecars[ii] == nil { | ||
b.Sidecars[ii] = new(deneb.BlobSidecar) | ||
} | ||
if err = b.Sidecars[ii].UnmarshalSSZ(buf[ii*131256 : (ii+1)*131256]); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright © 2023 Attestant Limited. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package http | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
|
||
"github.com/attestantio/go-eth2-client/api" | ||
"github.com/attestantio/go-eth2-client/spec/deneb" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// BlobSidecars fetches the blobs sidecars given options. | ||
func (s *Service) BlobSidecars(ctx context.Context, | ||
opts *api.BlobSidecarsOpts, | ||
) ( | ||
*api.Response[[]*deneb.BlobSidecar], | ||
error, | ||
) { | ||
if opts == nil { | ||
return nil, errors.New("no options specified") | ||
} | ||
if opts.Block == "" { | ||
return nil, errors.New("no block specified") | ||
} | ||
|
||
httpResponse, err := s.get2(ctx, fmt.Sprintf("/eth/v1/beacon/blob_sidecars/%s", opts.Block)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var response *api.Response[[]*deneb.BlobSidecar] | ||
switch httpResponse.contentType { | ||
case ContentTypeSSZ: | ||
response, err = s.blobSidecarsFromSSZ(httpResponse) | ||
case ContentTypeJSON: | ||
response, err = s.blobSidecarsFromJSON(httpResponse) | ||
default: | ||
return nil, fmt.Errorf("unhandled content type %v", httpResponse.contentType) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response, nil | ||
} | ||
|
||
func (s *Service) blobSidecarsFromSSZ(res *httpResponse) (*api.Response[[]*deneb.BlobSidecar], error) { | ||
response := &api.Response[[]*deneb.BlobSidecar]{} | ||
|
||
data := &api.BlobSidecars{} | ||
if err := data.UnmarshalSSZ(res.body); err != nil { | ||
return nil, errors.Wrap(err, "failed to decode blob sidecars") | ||
} | ||
|
||
response.Data = data.Sidecars | ||
|
||
return response, nil | ||
} | ||
|
||
func (s *Service) blobSidecarsFromJSON(res *httpResponse) (*api.Response[[]*deneb.BlobSidecar], error) { | ||
response := &api.Response[[]*deneb.BlobSidecar]{} | ||
|
||
var err error | ||
response.Data, response.Metadata, err = decodeJSONResponse(bytes.NewReader(res.body), []*deneb.BlobSidecar{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.