Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blobs bundle and related types #16

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions api/deneb/blindedblobsbundle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 deneb

import (
"fmt"

"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/goccy/go-yaml"
)

// BlindedBlobsBundle is the structure used to store the blobs bundle.
type BlindedBlobsBundle struct {
Commitments []deneb.KzgCommitment `ssz-max:"6" ssz-size:"?,48"`
Proofs []deneb.KzgProof `ssz-max:"6" ssz-size:"?,48"`
BlobRoots []phase0.Root `ssz-max:"6" ssz-size:"?,32"`
}

// String returns a string version of the structure.
func (b *BlindedBlobsBundle) String() string {
data, err := yaml.Marshal(b)
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}
return string(data)
}
74 changes: 74 additions & 0 deletions api/deneb/blindedblobsbundle_json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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 deneb

import (
"encoding/json"

"github.com/attestantio/go-eth2-client/codecs"
"github.com/pkg/errors"
)

// blindedBlobsBundleJSON is the spec representation of the struct.
type blindedBlobsBundleJSON struct {
Commitments []string `json:"commitments"`
Proofs []string `json:"proofs"`
BlobRoots []string `json:"blob_roots"`
}

// MarshalJSON implements json.Marshaler.
func (b *BlindedBlobsBundle) MarshalJSON() ([]byte, error) {
blobKzgCommitments := make([]string, len(b.Commitments))
for i := range b.Commitments {
blobKzgCommitments[i] = b.Commitments[i].String()
}

blobKzgProofs := make([]string, len(b.Proofs))
for i := range b.Proofs {
blobKzgProofs[i] = b.Proofs[i].String()
}

blobRoots := make([]string, len(b.BlobRoots))
for i := range b.BlobRoots {
blobRoots[i] = b.BlobRoots[i].String()
}

return json.Marshal(&blindedBlobsBundleJSON{
Commitments: blobKzgCommitments,
Proofs: blobKzgProofs,
BlobRoots: blobRoots,
})
}

// UnmarshalJSON implements json.Unmarshaler.
func (b *BlindedBlobsBundle) UnmarshalJSON(input []byte) error {
raw, err := codecs.RawJSON(&blindedBlobsBundleJSON{}, input)
if err != nil {
return err
}

if err := json.Unmarshal(raw["commitments"], &b.Commitments); err != nil {
return errors.Wrap(err, "commitments")
}

if err := json.Unmarshal(raw["proofs"], &b.Proofs); err != nil {
return errors.Wrap(err, "proofs")
}

if err := json.Unmarshal(raw["blob_roots"], &b.BlobRoots); err != nil {
return errors.Wrap(err, "blob_roots")
}

return nil
}
209 changes: 209 additions & 0 deletions api/deneb/blindedblobsbundle_ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading