/
keeper.go
62 lines (50 loc) · 1.99 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
package keeper
import (
"fmt"
"github.com/tendermint/tendermint/libs/log"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furya-official/mage/x/community/types"
)
// Keeper of the community store
type Keeper struct {
bankKeeper types.BankKeeper
distrKeeper types.DistributionKeeper
hardKeeper types.HardKeeper
moduleAddress sdk.AccAddress
legacyCommunityPoolAddress sdk.AccAddress
}
// NewKeeper creates a new community Keeper instance
func NewKeeper(ak types.AccountKeeper, bk types.BankKeeper, dk types.DistributionKeeper, hk types.HardKeeper) Keeper {
// ensure community module account is set
addr := ak.GetModuleAddress(types.ModuleAccountName)
if addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleAccountName))
}
legacyAddr := ak.GetModuleAddress(types.LegacyCommunityPoolModuleName)
if addr == nil {
panic("legacy community pool address not found")
}
return Keeper{
bankKeeper: bk,
distrKeeper: dk,
hardKeeper: hk,
moduleAddress: addr,
legacyCommunityPoolAddress: legacyAddr,
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}
// GetModuleAccountBalance returns all the coins held by the community module account
func (k Keeper) GetModuleAccountBalance(ctx sdk.Context) sdk.Coins {
return k.bankKeeper.GetAllBalances(ctx, k.moduleAddress)
}
// FundCommunityPool transfers coins from the sender to the community module account.
func (k Keeper) FundCommunityPool(ctx sdk.Context, sender sdk.AccAddress, amount sdk.Coins) error {
return k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleAccountName, amount)
}
// DistributeFromCommunityPool transfers coins from the community pool to recipient.
func (k Keeper) DistributeFromCommunityPool(ctx sdk.Context, recipient sdk.AccAddress, amount sdk.Coins) error {
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleAccountName, recipient, amount)
}