-
Notifications
You must be signed in to change notification settings - Fork 1
/
keeper.go
110 lines (93 loc) · 3.44 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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/elesto-dao/elesto/v2/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
distrKeeper types.DistributionKeeper
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, dk types.DistributionKeeper, 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")
}
//TODO: what is paramSpace this used for?
//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,
bankKeeper: bk,
distrKeeper: dk,
accountKeeper: ak,
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)
}
// AddInflationToFeeCollector implements an alias call to the underlying supply keeper's
// AddInflationToFeeCollector to be used in BeginBlocker.
func (k Keeper) AddInflationToFeeCollector(ctx sdk.Context, fees sdk.Coins) error {
return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, fees)
}
// CollectAmount implement an alias to call SendCoinsFromModuleToAccount
func (k Keeper) CollectAmount(ctx sdk.Context, address string, amount sdk.Coins) error {
addr, err := sdk.AccAddressFromBech32(address)
if err != nil {
return err
}
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, amount)
}
// GetSupply returns the current supply on the chain for a denom
func (k Keeper) GetSupply(ctx sdk.Context, denom string) sdk.Coin {
return k.bankKeeper.GetSupply(ctx, denom)
}
// FundCommunityPool funds the x/distribution community pool with amount coins, directly from
// this module's ModuleAccount.
func (k Keeper) FundCommunityPool(ctx sdk.Context, amount sdk.Coins) error {
if amount.Empty() {
// skip as no coins need to be minted
return nil
}
addr := k.accountKeeper.GetModuleAddress(types.ModuleName)
if addr == nil {
panic("the mint module account has not been set")
}
return k.distrKeeper.FundCommunityPool(ctx, amount, addr)
}