github.com/cosmos/cosmos-sdk@v0.50.10/x/mint/keeper/keeper.go (about) 1 package keeper 2 3 import ( 4 "context" 5 "fmt" 6 7 "cosmossdk.io/collections" 8 storetypes "cosmossdk.io/core/store" 9 "cosmossdk.io/log" 10 "cosmossdk.io/math" 11 12 "github.com/cosmos/cosmos-sdk/codec" 13 sdk "github.com/cosmos/cosmos-sdk/types" 14 "github.com/cosmos/cosmos-sdk/x/mint/types" 15 ) 16 17 // Keeper of the mint store 18 type Keeper struct { 19 cdc codec.BinaryCodec 20 storeService storetypes.KVStoreService 21 stakingKeeper types.StakingKeeper 22 bankKeeper types.BankKeeper 23 feeCollectorName string 24 25 // the address capable of executing a MsgUpdateParams message. Typically, this 26 // should be the x/gov module account. 27 authority string 28 29 Schema collections.Schema 30 Params collections.Item[types.Params] 31 Minter collections.Item[types.Minter] 32 } 33 34 // NewKeeper creates a new mint Keeper instance 35 func NewKeeper( 36 cdc codec.BinaryCodec, 37 storeService storetypes.KVStoreService, 38 sk types.StakingKeeper, 39 ak types.AccountKeeper, 40 bk types.BankKeeper, 41 feeCollectorName string, 42 authority string, 43 ) Keeper { 44 // ensure mint module account is set 45 if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { 46 panic(fmt.Sprintf("the x/%s module account has not been set", types.ModuleName)) 47 } 48 49 sb := collections.NewSchemaBuilder(storeService) 50 k := Keeper{ 51 cdc: cdc, 52 storeService: storeService, 53 stakingKeeper: sk, 54 bankKeeper: bk, 55 feeCollectorName: feeCollectorName, 56 authority: authority, 57 Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), 58 Minter: collections.NewItem(sb, types.MinterKey, "minter", codec.CollValue[types.Minter](cdc)), 59 } 60 61 schema, err := sb.Build() 62 if err != nil { 63 panic(err) 64 } 65 k.Schema = schema 66 return k 67 } 68 69 // GetAuthority returns the x/mint module's authority. 70 func (k Keeper) GetAuthority() string { 71 return k.authority 72 } 73 74 // Logger returns a module-specific logger. 75 func (k Keeper) Logger(ctx context.Context) log.Logger { 76 sdkCtx := sdk.UnwrapSDKContext(ctx) 77 return sdkCtx.Logger().With("module", "x/"+types.ModuleName) 78 } 79 80 // StakingTokenSupply implements an alias call to the underlying staking keeper's 81 // StakingTokenSupply to be used in BeginBlocker. 82 func (k Keeper) StakingTokenSupply(ctx context.Context) (math.Int, error) { 83 return k.stakingKeeper.StakingTokenSupply(ctx) 84 } 85 86 // BondedRatio implements an alias call to the underlying staking keeper's 87 // BondedRatio to be used in BeginBlocker. 88 func (k Keeper) BondedRatio(ctx context.Context) (math.LegacyDec, error) { 89 return k.stakingKeeper.BondedRatio(ctx) 90 } 91 92 // MintCoins implements an alias call to the underlying supply keeper's 93 // MintCoins to be used in BeginBlocker. 94 func (k Keeper) MintCoins(ctx context.Context, newCoins sdk.Coins) error { 95 if newCoins.Empty() { 96 // skip as no coins need to be minted 97 return nil 98 } 99 100 return k.bankKeeper.MintCoins(ctx, types.ModuleName, newCoins) 101 } 102 103 // AddCollectedFees implements an alias call to the underlying supply keeper's 104 // AddCollectedFees to be used in BeginBlocker. 105 func (k Keeper) AddCollectedFees(ctx context.Context, fees sdk.Coins) error { 106 return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, fees) 107 }