-
Notifications
You must be signed in to change notification settings - Fork 207
/
keeper.go
65 lines (54 loc) · 1.55 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
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"
types "github.com/akash-network/akash-api/go/node/staking/v1beta3"
)
type IKeeper interface {
Codec() codec.BinaryCodec
StoreKey() sdk.StoreKey
SetParams(ctx sdk.Context, params types.Params) error
GetParams(ctx sdk.Context) (params types.Params)
MinCommissionRate(ctx sdk.Context) sdk.Dec
}
// Keeper of the provider store
type Keeper struct {
skey sdk.StoreKey
cdc codec.BinaryCodec
pspace paramtypes.Subspace
}
// NewKeeper creates and returns an instance for Provider keeper
func NewKeeper(cdc codec.BinaryCodec, skey sdk.StoreKey, pspace paramtypes.Subspace) IKeeper {
if !pspace.HasKeyTable() {
pspace = pspace.WithKeyTable(types.ParamKeyTable())
}
return Keeper{
skey: skey,
cdc: cdc,
pspace: pspace,
}
}
// Codec returns keeper codec
func (k Keeper) Codec() codec.BinaryCodec {
return k.cdc
}
func (k Keeper) StoreKey() sdk.StoreKey {
return k.skey
}
func (k Keeper) MinCommissionRate(ctx sdk.Context) sdk.Dec {
res := sdk.NewDec(0)
k.pspace.Get(ctx, types.KeyMinCommissionRate, &res)
return res
}
// SetParams sets the deployment parameters to the paramspace.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
k.pspace.SetParamSet(ctx, ¶ms)
return nil
}
// GetParams returns the total set of deployment parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
return types.NewParams(
k.MinCommissionRate(ctx),
)
}