-
Notifications
You must be signed in to change notification settings - Fork 118
/
keeper.go
61 lines (51 loc) · 1.47 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
package keeper
import (
"fmt"
"github.com/Sifchain/sifnode/x/dispensation/types"
"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"
)
// Keeper of the clp store
type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryCodec
bankKeeper types.BankKeeper
accountKeeper types.AccountKeeper
}
// NewKeeper creates a dispensation keeper
func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, bankkeeper types.BankKeeper, accountKeeper types.AccountKeeper, ps paramtypes.Subspace) Keeper {
keeper := Keeper{
storeKey: key,
cdc: cdc,
bankKeeper: bankkeeper,
accountKeeper: accountKeeper,
}
return keeper
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k Keeper) Codec() codec.BinaryCodec {
return k.cdc
}
func (k Keeper) GetBankKeeper() types.BankKeeper {
return k.bankKeeper
}
func (k Keeper) GetAccountKeeper() types.AccountKeeper {
return k.accountKeeper
}
func (k Keeper) Exists(ctx sdk.Context, key []byte) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(key)
}
func (k Keeper) HasCoins(ctx sdk.Context, user sdk.AccAddress, coins sdk.Coins) bool {
for _, coin := range coins {
if !k.bankKeeper.HasBalance(ctx, user, coin) {
return false
}
}
return true
}