-
Notifications
You must be signed in to change notification settings - Fork 264
/
utils.go
44 lines (37 loc) · 1.07 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package module
import (
"slices"
"sort"
sdkmodule "github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
// defaultMigrationsOrder returns a default migrations order. The order is
// ascending alphabetical by module name except "auth" will will be last. See:
// https://github.com/cosmos/cosmos-sdk/issues/10591
func defaultMigrationsOrder(modules []string) []string {
result := filter(modules, isNotAuth)
sort.Strings(result)
if hasAuth := slices.Contains(modules, authtypes.ModuleName); hasAuth {
return append(result, authtypes.ModuleName)
}
return result
}
func filter(elements []string, filter func(string) bool) (filtered []string) {
for _, element := range elements {
if filter(element) {
filtered = append(filtered, element)
}
}
return filtered
}
func isNotAuth(name string) bool {
return name != authtypes.ModuleName
}
func getKeys(m map[uint64]map[string]sdkmodule.AppModule) []uint64 {
keys := make([]uint64, 0, len(m))
for key := range m {
keys = append(keys, key)
}
slices.Sort(keys)
return keys
}