-
Notifications
You must be signed in to change notification settings - Fork 138
Open
Description
The current implementation of isModuleAccount relie on iterating through knownModules to determine whether an address is a module account.
neutron/x/tokenfactory/keeper/bankactions.go
Lines 92 to 105 in a6525cb
| func (k Keeper) isModuleAccount(ctx sdk.Context, addr sdk.AccAddress) bool { | |
| for _, moduleName := range k.knownModules { | |
| account := k.accountKeeper.GetModuleAccount(ctx, moduleName) | |
| if account == nil { | |
| continue | |
| } | |
| if account.GetAddress().Equals(addr) { | |
| return true | |
| } | |
| } | |
| return false | |
| } |
However, this approach has two notable drawbacks. First, the use of loop iteration for validation can be resource-intensive. Second, since knownModules is a configuration parameter initialized with the keeper, any updates introducing new modules might lead to omissions.
Given these considerations, it would be more efficient and reliable to determine whether an address is a module account by directly checking its account type.
func (k Keeper) isModuleAccount(ctx sdk.Context, addr sdk.AccAddress) bool {
acc := k.authKeeper.GetAccount(ctx, addr)
if acc == nil {
return false
}
_, ok := acc.(authtypes.ModuleAccountI)
return ok
}
Metadata
Metadata
Assignees
Labels
No labels