github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/names/names_array.go (about) 1 package namesPkg 2 3 import ( 4 "sort" 5 "strings" 6 7 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 10 ) 11 12 // loadNamesArray loads the names from the cache and returns an array of names 13 func loadNamesArray(chain string, parts types.Parts, sortBy types.SortBy, terms []string) ([]types.Name, error) { 14 var ret []types.Name 15 if namesMap, err := names.LoadNamesMap(chain, parts, terms); err != nil { 16 return nil, err 17 } else { 18 for _, name := range namesMap { 19 // Custom names with Individual tag or tags under 30 are private during testing 20 isTesting := parts&types.Testing != 0 21 isPrivate := strings.Contains(name.Tags, "Individual") || (name.IsCustom && name.Tags < "3") 22 if !isTesting || !isPrivate { 23 ret = append(ret, name) 24 } 25 } 26 } 27 28 sort.Slice(ret, func(i, j int) bool { 29 switch sortBy { 30 case types.SortByTags: 31 return ret[i].Tags < ret[j].Tags 32 case types.SortByAddress: 33 fallthrough 34 default: 35 return ret[i].Address.Hex() < ret[j].Address.Hex() 36 } 37 }) 38 39 isTesting := parts&types.Testing != 0 40 isTags := sortBy == types.SortByTags 41 if isTesting && !isTags { 42 ret = ret[:base.Min(200, len(ret))] 43 } 44 45 return ret, nil 46 }