From cfc7d06cc91122f44d09592ddc616fb189bc4ca4 Mon Sep 17 00:00:00 2001 From: Aaron Chen Date: Mon, 8 Apr 2024 18:58:37 +0800 Subject: [PATCH] signer/core/apitypes: use slices.Contains (#29474) --- log/handler.go | 2 +- signer/core/apitypes/types.go | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/log/handler.go b/log/handler.go index 290e381509..c604a62301 100644 --- a/log/handler.go +++ b/log/handler.go @@ -118,7 +118,7 @@ func JSONHandler(wr io.Writer) slog.Handler { return JSONHandlerWithLevel(wr, levelMaxVerbosity) } -// JSONHandler returns a handler which prints records in JSON format that are less than or equal to +// JSONHandlerWithLevel returns a handler which prints records in JSON format that are less than or equal to // the specified verbosity level. func JSONHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler { return slog.NewJSONHandler(wr, &slog.HandlerOptions{ diff --git a/signer/core/apitypes/types.go b/signer/core/apitypes/types.go index eba9d7768f..9113c091c5 100644 --- a/signer/core/apitypes/types.go +++ b/signer/core/apitypes/types.go @@ -25,6 +25,7 @@ import ( "math/big" "reflect" "regexp" + "slices" "sort" "strconv" "strings" @@ -386,16 +387,8 @@ func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage // Dependencies returns an array of custom types ordered by their hierarchical reference tree func (typedData *TypedData) Dependencies(primaryType string, found []string) []string { primaryType = strings.TrimSuffix(primaryType, "[]") - includes := func(arr []string, str string) bool { - for _, obj := range arr { - if obj == str { - return true - } - } - return false - } - if includes(found, primaryType) { + if slices.Contains(found, primaryType) { return found } if typedData.Types[primaryType] == nil { @@ -404,7 +397,7 @@ func (typedData *TypedData) Dependencies(primaryType string, found []string) []s found = append(found, primaryType) for _, field := range typedData.Types[primaryType] { for _, dep := range typedData.Dependencies(field.Type, found) { - if !includes(found, dep) { + if !slices.Contains(found, dep) { found = append(found, dep) } }