package keeper
import (
"fmt"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cybercongress/go-cyber/v7/x/tokenfactory/types"
)
type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
permAddrs map[string]authtypes.PermissionsForAddress
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
communityPoolKeeper types.CommunityPoolKeeper
enabledCapabilities []string
authority string
}
)
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)
}
return Keeper{
cdc: cdc,
storeKey: storeKey,
permAddrs: permAddrs,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
communityPoolKeeper: communityPoolKeeper,
enabledCapabilities: enabledCapabilities,
authority: authority,
}
}
func (k Keeper) GetAuthority() string {
return k.authority
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k Keeper) GetDenomPrefixStore(ctx sdk.Context, denom string) sdk.KVStore {
store := ctx.KVStore(k.storeKey)
return prefix.NewStore(store, types.GetDenomPrefixStore(denom))
}
func (k Keeper) GetCreatorPrefixStore(ctx sdk.Context, creator string) sdk.KVStore {
store := ctx.KVStore(k.storeKey)
return prefix.NewStore(store, types.GetCreatorPrefix(creator))
}
func (k Keeper) GetCreatorsPrefixStore(ctx sdk.Context) sdk.KVStore {
store := ctx.KVStore(k.storeKey)
return prefix.NewStore(store, types.GetCreatorsPrefix())
}
func (k Keeper) CreateModuleAccount(ctx sdk.Context) {
k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
}