Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Module Order Matches the Sequence Constructed by BuildModules() #127

Open
wants to merge 1 commit into
base: cosmos/v0.50.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions modules/registrar/registrar.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package registrar

import (
"slices"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/forbole/juno/v6/node"
Expand Down Expand Up @@ -95,12 +97,21 @@ func (r *DefaultRegistrar) BuildModules(ctx Context) modules.Modules {
// For each module name that is specified but not found, a warning log is printed.
func GetModules(mods modules.Modules, names []string, logger logging.Logger) []modules.Module {
var modulesImpls []modules.Module
for _, name := range names {
module, found := mods.FindByName(name)
if found {
modulesImpls = append(modulesImpls, module)
} else {
logger.Error("Module is required but not registered. Be sure to register it using registrar.RegisterModule", "module", name)

for _, mod := range mods {
if slices.Contains(names, mod.Name()) {
modulesImpls = append(modulesImpls, mod)
}
}

if len(modulesImpls) != len(names) {
for _, name := range names {
found := slices.ContainsFunc(modulesImpls, func(n modules.Module) bool {
return n.Name() == name
})
if !found {
logger.Error("Module is required but not registered. Be sure to register it using registrar.RegisterModule", "module", name)
}
}
}
return modulesImpls
Expand Down