Skip to content

Commit

Permalink
fix(blob): use proper share.MaxShareVersion const (#64)
Browse files Browse the repository at this point in the history
We were comparing against incorrect const (`math.MaxUint8`) but error message refers to the proper (`share.MaxShareVersion`).

Sadly we cannot import `shares` package in `blob` due to cyclic dependency, adding comment for the future. Also, removed useless `fmt` alias for `fmt` package.
  • Loading branch information
cristaloleg authored Jun 3, 2024
1 parent c6540fc commit be3c280
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ package blob
import (
"bytes"
"errors"
fmt "fmt"
math "math"
"fmt"
"sort"

"github.com/celestiaorg/go-square/namespace"
Expand All @@ -24,6 +23,9 @@ const ProtoBlobTxTypeID = "BLOB"
// decoding binaries that are not actually IndexWrappers.
const ProtoIndexWrapperTypeID = "INDX"

// MaxShareVersion is the maximum value a share version can be. See: [shares.MaxShareVersion].
const MaxShareVersion = 127

// New creates a new coretypes.Blob from the provided data after performing
// basic stateless checks over it.
func New(ns namespace.Namespace, blob []byte, shareVersion uint8) *Blob {
Expand Down Expand Up @@ -51,7 +53,7 @@ func (b *Blob) Validate() error {
if len(b.NamespaceId) != namespace.NamespaceIDSize {
return fmt.Errorf("namespace id must be %d bytes", namespace.NamespaceIDSize)
}
if b.ShareVersion > math.MaxUint8 {
if b.ShareVersion > MaxShareVersion {
return errors.New("share version can not be greater than MaxShareVersion")
}
if b.NamespaceVersion > namespace.NamespaceVersionMax {
Expand Down

0 comments on commit be3c280

Please sign in to comment.