Skip to content

Commit

Permalink
update: tf
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersuweijie committed May 30, 2024
1 parent db9b997 commit e6d56f9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ func NewTerraAppKeepers(
)
keepers.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
keys[tokenfactorytypes.StoreKey],
maccPerms,
keepers.AccountKeeper,
&keepers.BankKeeper,
keepers.DistrKeeper,
Expand Down
25 changes: 25 additions & 0 deletions x/tokenfactory/keeper/bankactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"sort"

errorsmod "cosmossdk.io/errors"
customterratypes "github.com/terra-money/core/v2/x/bank/types"
Expand Down Expand Up @@ -71,6 +74,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
8 changes: 5 additions & 3 deletions x/tokenfactory/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"fmt"

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

"github.com/cometbft/cometbft/libs/log"
Expand All @@ -17,7 +16,8 @@ import (

type (
Keeper struct {
storeKey storetypes.StoreKey
storeKey storetypes.StoreKey
permAddrs map[string][]string

accountKeeper types.AccountKeeper
bankKeeper *customtypes.Keeper
Expand All @@ -33,6 +33,7 @@ type (
// NewKeeper returns a new instance of the x/tokenfactory keeper
func NewKeeper(
storeKey storetypes.StoreKey,
permAddrs map[string][]string,
accountKeeper types.AccountKeeper,
bankKeeper *customtypes.Keeper,
communityPoolKeeper types.CommunityPoolKeeper,
Expand All @@ -41,7 +42,8 @@ func NewKeeper(
) Keeper {

return Keeper{
storeKey: storeKey,
storeKey: storeKey,
permAddrs: permAddrs,

accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
Expand Down

0 comments on commit e6d56f9

Please sign in to comment.