-
Notifications
You must be signed in to change notification settings - Fork 8
/
keeper.go
61 lines (50 loc) · 1.3 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 (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/terpnetwork/terp-core/v4/x/globalfee/types"
)
// Keeper of the globalfee store
type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
}
func NewKeeper(
cdc codec.BinaryCodec,
key storetypes.StoreKey,
authority string,
) Keeper {
return Keeper{
cdc: cdc,
storeKey: key,
authority: authority,
}
}
// GetAuthority returns the x/globalfee module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}
// SetParams sets the x/globalfee module parameters.
func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error {
if err := p.Validate(); err != nil {
return err
}
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&p)
store.Set(types.ParamsKey, bz)
return nil
}
// GetParams returns the current x/globalfee module parameters.
func (k Keeper) GetParams(ctx sdk.Context) (p types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return p
}
k.cdc.MustUnmarshal(bz, &p)
return p
}