github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/blob/blob.go (about)

     1  package blob
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/celestiaorg/celestia-node/blob"
     7  	"github.com/celestiaorg/celestia-node/share"
     8  )
     9  
    10  var _ Module = (*API)(nil)
    11  
    12  // Module defines the API related to interacting with the blobs
    13  //
    14  //go:generate mockgen -destination=mocks/api.go -package=mocks . Module
    15  type Module interface {
    16  	// Submit sends Blobs and reports the height in which they were included.
    17  	// Allows sending multiple Blobs atomically synchronously.
    18  	// Uses default wallet registered on the Node.
    19  	Submit(_ context.Context, _ []*blob.Blob, _ blob.GasPrice) (height uint64, _ error)
    20  	// Get retrieves the blob by commitment under the given namespace and height.
    21  	Get(_ context.Context, height uint64, _ share.Namespace, _ blob.Commitment) (*blob.Blob, error)
    22  	// GetAll returns all blobs at the given height under the given namespaces.
    23  	GetAll(_ context.Context, height uint64, _ []share.Namespace) ([]*blob.Blob, error)
    24  	// GetProof retrieves proofs in the given namespaces at the given height by commitment.
    25  	GetProof(_ context.Context, height uint64, _ share.Namespace, _ blob.Commitment) (*blob.Proof, error)
    26  	// Included checks whether a blob's given commitment(Merkle subtree root) is included at
    27  	// given height and under the namespace.
    28  	Included(_ context.Context, height uint64, _ share.Namespace, _ *blob.Proof, _ blob.Commitment) (bool, error)
    29  }
    30  
    31  type API struct {
    32  	Internal struct {
    33  		Submit   func(context.Context, []*blob.Blob, blob.GasPrice) (uint64, error)                         `perm:"write"`
    34  		Get      func(context.Context, uint64, share.Namespace, blob.Commitment) (*blob.Blob, error)        `perm:"read"`
    35  		GetAll   func(context.Context, uint64, []share.Namespace) ([]*blob.Blob, error)                     `perm:"read"`
    36  		GetProof func(context.Context, uint64, share.Namespace, blob.Commitment) (*blob.Proof, error)       `perm:"read"`
    37  		Included func(context.Context, uint64, share.Namespace, *blob.Proof, blob.Commitment) (bool, error) `perm:"read"`
    38  	}
    39  }
    40  
    41  func (api *API) Submit(ctx context.Context, blobs []*blob.Blob, gasPrice blob.GasPrice) (uint64, error) {
    42  	return api.Internal.Submit(ctx, blobs, gasPrice)
    43  }
    44  
    45  func (api *API) Get(
    46  	ctx context.Context,
    47  	height uint64,
    48  	namespace share.Namespace,
    49  	commitment blob.Commitment,
    50  ) (*blob.Blob, error) {
    51  	return api.Internal.Get(ctx, height, namespace, commitment)
    52  }
    53  
    54  func (api *API) GetAll(ctx context.Context, height uint64, namespaces []share.Namespace) ([]*blob.Blob, error) {
    55  	return api.Internal.GetAll(ctx, height, namespaces)
    56  }
    57  
    58  func (api *API) GetProof(
    59  	ctx context.Context,
    60  	height uint64,
    61  	namespace share.Namespace,
    62  	commitment blob.Commitment,
    63  ) (*blob.Proof, error) {
    64  	return api.Internal.GetProof(ctx, height, namespace, commitment)
    65  }
    66  
    67  func (api *API) Included(
    68  	ctx context.Context,
    69  	height uint64,
    70  	namespace share.Namespace,
    71  	proof *blob.Proof,
    72  	commitment blob.Commitment,
    73  ) (bool, error) {
    74  	return api.Internal.Included(ctx, height, namespace, proof, commitment)
    75  }