Skip to content

Commit c7fa8a0

Browse files
committed
use variables
1 parent de14e07 commit c7fa8a0

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

core/da/namespace.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
// Implemented in accordance to https://celestiaorg.github.io/celestia-app/namespace.html
1111

1212
const (
13+
// NamespaceVersionIndex is the index of the namespace version in the byte slice
14+
NamespaceVersionIndex = 0
1315
// NamespaceVersionSize is the size of the namespace version in bytes
1416
NamespaceVersionSize = 1
1517
// NamespaceIDSize is the size of the namespace ID in bytes
@@ -37,8 +39,8 @@ type Namespace struct {
3739
// Bytes returns the namespace as a byte slice
3840
func (n Namespace) Bytes() []byte {
3941
result := make([]byte, NamespaceSize)
40-
result[0] = n.Version
41-
copy(result[1:], n.ID[:])
42+
result[NamespaceVersionIndex] = n.Version
43+
copy(result[NamespaceVersionSize:], n.ID[:])
4244
return result
4345
}
4446

@@ -49,7 +51,7 @@ func (n Namespace) IsValidForVersion0() bool {
4951
return false
5052
}
5153

52-
for i := 0; i < NamespaceVersionZeroPrefixSize; i++ {
54+
for i := range NamespaceVersionZeroPrefixSize {
5355
if n.ID[i] != 0 {
5456
return false
5557
}
@@ -84,9 +86,9 @@ func NamespaceFromBytes(b []byte) (*Namespace, error) {
8486
}
8587

8688
ns := &Namespace{
87-
Version: b[0],
89+
Version: b[NamespaceVersionIndex],
8890
}
89-
copy(ns.ID[:], b[1:])
91+
copy(ns.ID[:], b[NamespaceVersionSize:])
9092

9193
// Validate if it's version 0
9294
if ns.Version == NamespaceVersionZero && !ns.IsValidForVersion0() {

core/da/namespace_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestNamespaceV0Creation(t *testing.T) {
6464
}
6565

6666
// Verify first 18 bytes of ID are zeros
67-
for i := 0; i < NamespaceVersionZeroPrefixSize; i++ {
67+
for i := range NamespaceVersionZeroPrefixSize {
6868
if ns.ID[i] != byte(0) {
6969
t.Errorf("First 18 bytes should be zero, but byte %d is %d", i, ns.ID[i])
7070
}

0 commit comments

Comments
 (0)