Skip to content

Commit f467e72

Browse files
committed
refactor: use slices.Contains to simplify code
Signed-off-by: slightsharp <slightsharp@outlook.com>
1 parent 9a91394 commit f467e72

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

pkg/rpc/server/da_visualization.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"html/template"
1010
"net/http"
11+
"slices"
1112
"sync"
1213
"time"
1314

@@ -199,15 +200,12 @@ func (s *DAVisualizationServer) handleDABlobDetails(w http.ResponseWriter, r *ht
199200
if !found {
200201
s.mutex.RLock()
201202
for _, submission := range s.submissions {
202-
for _, subBlobID := range submission.BlobIDs {
203-
if subBlobID == blobID {
204-
if submission.Namespace != "" {
205-
if ns, err := hex.DecodeString(submission.Namespace); err == nil {
206-
namespace = ns
207-
found = true
208-
}
203+
if slices.Contains(submission.BlobIDs, blobID) {
204+
if submission.Namespace != "" {
205+
if ns, err := hex.DecodeString(submission.Namespace); err == nil {
206+
namespace = ns
207+
found = true
209208
}
210-
break
211209
}
212210
}
213211
if found {

tools/local-da/rpc.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"net/http"
7+
"slices"
78
"time"
89

910
libshare "github.com/celestiaorg/go-square/v3/share"
@@ -93,11 +94,8 @@ func (s *blobServer) GetAll(_ context.Context, height uint64, namespaces []libsh
9394

9495
out := make([]*jsonrpc.Blob, 0, len(blobs))
9596
for _, b := range blobs {
96-
for _, ns := range namespaces {
97-
if b.Namespace().Equals(ns) {
98-
out = append(out, b)
99-
break
100-
}
97+
if b != nil && slices.ContainsFunc(namespaces, b.Namespace().Equals) {
98+
out = append(out, b)
10199
}
102100
}
103101

0 commit comments

Comments
 (0)