From f467e72ed8b876e7aade294ee817b344edff0969 Mon Sep 17 00:00:00 2001 From: slightsharp Date: Fri, 23 Jan 2026 17:43:13 +0800 Subject: [PATCH] refactor: use slices.Contains to simplify code Signed-off-by: slightsharp --- pkg/rpc/server/da_visualization.go | 14 ++++++-------- tools/local-da/rpc.go | 8 +++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pkg/rpc/server/da_visualization.go b/pkg/rpc/server/da_visualization.go index 008f88f40..e14a06910 100644 --- a/pkg/rpc/server/da_visualization.go +++ b/pkg/rpc/server/da_visualization.go @@ -8,6 +8,7 @@ import ( "fmt" "html/template" "net/http" + "slices" "sync" "time" @@ -199,15 +200,12 @@ func (s *DAVisualizationServer) handleDABlobDetails(w http.ResponseWriter, r *ht if !found { s.mutex.RLock() for _, submission := range s.submissions { - for _, subBlobID := range submission.BlobIDs { - if subBlobID == blobID { - if submission.Namespace != "" { - if ns, err := hex.DecodeString(submission.Namespace); err == nil { - namespace = ns - found = true - } + if slices.Contains(submission.BlobIDs, blobID) { + if submission.Namespace != "" { + if ns, err := hex.DecodeString(submission.Namespace); err == nil { + namespace = ns + found = true } - break } } if found { diff --git a/tools/local-da/rpc.go b/tools/local-da/rpc.go index 60dd51ac4..e90071efa 100644 --- a/tools/local-da/rpc.go +++ b/tools/local-da/rpc.go @@ -4,6 +4,7 @@ import ( "context" "errors" "net/http" + "slices" "time" libshare "github.com/celestiaorg/go-square/v3/share" @@ -93,11 +94,8 @@ func (s *blobServer) GetAll(_ context.Context, height uint64, namespaces []libsh out := make([]*jsonrpc.Blob, 0, len(blobs)) for _, b := range blobs { - for _, ns := range namespaces { - if b.Namespace().Equals(ns) { - out = append(out, b) - break - } + if b != nil && slices.ContainsFunc(namespaces, b.Namespace().Equals) { + out = append(out, b) } }