Skip to content

Commit

Permalink
signer/core/apitypes: use slices.Contains (ethereum#29474)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronChen0 authored Apr 8, 2024
1 parent 0dc09da commit cfc7d06
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion log/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
13 changes: 3 additions & 10 deletions signer/core/apitypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"math/big"
"reflect"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand Down

0 comments on commit cfc7d06

Please sign in to comment.