Skip to content

Commit

Permalink
tokenfactory updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dimiandre committed Apr 17, 2024
1 parent 70b2faa commit 1afc59a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ heighliner*
# emacs editor config
\#*\#
.\#*

.DS_Store
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ func NewAppKeepers(
appKeepers.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
appCodec,
appKeepers.keys[tokenfactorytypes.StoreKey],
maccPerms,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.DistrKeeper,
Expand Down
26 changes: 26 additions & 0 deletions x/tokenfactory/keeper/bankactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package keeper

import (
"fmt"
"sort"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

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

Expand Down Expand Up @@ -68,6 +72,28 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr string,
return err
}

fromAcc, err := sdk.AccAddressFromBech32(fromAddr)
if err != nil {
return err
}

sortedPermAddrs := make([]string, 0, len(k.permAddrs))
for moduleName := range k.permAddrs {
sortedPermAddrs = append(sortedPermAddrs, moduleName)
}
sort.Strings(sortedPermAddrs)

for _, moduleName := range sortedPermAddrs {
account := k.accountKeeper.GetModuleAccount(ctx, moduleName)
if account == nil {
return status.Errorf(codes.NotFound, "account %s not found", moduleName)
}

if account.GetAddress().Equals(fromAcc) {
return status.Errorf(codes.Internal, "send from module acc not available")
}
}

fromSdkAddr, err := sdk.AccAddressFromBech32(fromAddr)
if err != nil {
return err
Expand Down
12 changes: 10 additions & 2 deletions x/tokenfactory/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (

type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
permAddrs map[string]authtypes.PermissionsForAddress

accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
Expand All @@ -35,16 +36,23 @@ type (
func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
maccPerms map[string][]string,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
communityPoolKeeper types.CommunityPoolKeeper,
enabledCapabilities []string,
authority string,
) Keeper {
permAddrs := make(map[string]authtypes.PermissionsForAddress)
for name, perms := range maccPerms {
permAddrs[name] = authtypes.NewPermissionsForAddress(name, perms)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism

return Keeper{
cdc: cdc,
storeKey: storeKey,

permAddrs: permAddrs,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
communityPoolKeeper: communityPoolKeeper,
Expand Down
1 change: 1 addition & 0 deletions x/tokenfactory/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type BankKeeper interface {
type AccountKeeper interface {
SetModuleAccount(ctx sdk.Context, macc authtypes.ModuleAccountI)
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI
}

// CommunityPoolKeeper defines the contract needed to be fulfilled for community pool interactions.
Expand Down

0 comments on commit 1afc59a

Please sign in to comment.