-
Notifications
You must be signed in to change notification settings - Fork 3
/
keeper.go
96 lines (82 loc) · 2.83 KB
/
keeper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package keeper
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmosquad-labs/squad/v3/x/mint/types"
)
// Keeper of the mint store
type Keeper struct {
cdc codec.BinaryCodec
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
feeCollectorName string
}
// NewKeeper creates a new mint Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, ak types.AccountKeeper, bk types.BankKeeper, feeCollectorName string,
) Keeper {
// ensure mint module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
panic("the mint module account has not been set")
}
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}
return Keeper{
cdc: cdc,
storeKey: key,
paramSpace: paramSpace,
accountKeeper: ak,
bankKeeper: bk,
feeCollectorName: feeCollectorName,
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}
// GetParams returns the total set of mint parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, ¶ms)
return params
}
// SetParams sets the total set of mint parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, ¶ms)
}
// MintCoins implements an alias call to the underlying supply keeper's
// MintCoins to be used in BeginBlocker.
func (k Keeper) MintCoins(ctx sdk.Context, newCoins sdk.Coins) error {
if newCoins.Empty() {
// skip as no coins need to be minted
return nil
}
return k.bankKeeper.MintCoins(ctx, types.ModuleName, newCoins)
}
// SendInflationToMintPool sends inflation to params.MintPoolAddress, It to be used in BeginBlocker.
func (k Keeper) SendInflationToMintPool(ctx sdk.Context, inflation sdk.Coins) error {
return k.bankKeeper.SendCoins(ctx,
k.accountKeeper.GetModuleAddress(types.ModuleName),
k.GetMintPoolAddress(ctx),
inflation)
}
// GetInflationSchedules return inflation schedules set on app
func (k Keeper) GetInflationSchedules(ctx sdk.Context) (res []types.InflationSchedule) {
k.paramSpace.Get(ctx, types.KeyInflationSchedules, &res)
return
}
// GetMintPoolAddress return mint pool address on app
func (k Keeper) GetMintPoolAddress(ctx sdk.Context) (acc sdk.AccAddress) {
var addr string
k.paramSpace.Get(ctx, types.KeyMintPoolAddress, &addr)
acc, err := sdk.AccAddressFromBech32(addr)
if err != nil {
panic(err)
}
return
}