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

feat(blob): introduce structure of blob #2012

Merged
Merged
Changes from 1 commit
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
55 changes: 55 additions & 0 deletions blob/blob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package blob

import (
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/nmt/namespace"
)

// Commitment is a Merkle Root of the subtree built from shares of the Blob.
// It is computed by splitting the blob into shares and building the Merkle subtree to be included after Submit.
type Commitment []byte
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved

// Proof is a collection of nmt.Proofs that verifies the inclusion of the data.
type Proof []nmt.Proof

// Blob represents any application-specific binary data that anyone can submit to Celestia.
type Blob struct {
*types.Blob
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be a pointer here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no


commitment Commitment
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
}

// NewBlob constructs a new blob from the provided namespace.ID and data.
func NewBlob(nID namespace.ID, data []byte) (*Blob, error) {
blob, err := types.NewBlob(nID, data)
if err != nil {
return nil, err
}

com, err := types.CreateCommitment(blob)
if err != nil {
return nil, err
}
return &Blob{Blob: blob, commitment: com}, nil
}

// NamespaceID returns blobs namespaceId.
func (b *Blob) NamespaceID() []byte {
return b.Blob.NamespaceId
}

// Data returns blobs raw data.
func (b *Blob) Data() []byte {
return b.Blob.Data
}

// Commitment returns the commitment of current blob.
func (b *Blob) Commitment() Commitment {
return b.commitment
}

// Version is the format that was used to encode Blob data and namespaceID into shares.
func (b *Blob) Version() uint32 {
return b.Blob.ShareVersion
}
Comment on lines +52 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users should be able to set the version and constructor of the Blob does not reflect that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it requires additional changes on the app side, bc now they are using DefaultShareVersion by default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should communicate this to the app team then. They requested the ability to configure the version in the Blob discussion