forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper.go
59 lines (44 loc) · 1.38 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
package keeper
import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
storetypes "github.com/verzth/cosmos-sdk/store/types"
"github.com/verzth/cosmos-sdk/codec"
sdk "github.com/verzth/cosmos-sdk/types"
"github.com/verzth/cosmos-sdk/x/consensus/exported"
"github.com/verzth/cosmos-sdk/x/consensus/types"
)
var _ exported.ConsensusParamSetter = (*Keeper)(nil)
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
authority string
}
func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, authority string) Keeper {
return Keeper{
storeKey: storeKey,
cdc: cdc,
authority: authority,
}
}
func (k *Keeper) GetAuthority() string {
return k.authority
}
// Get gets the consensus parameters
func (k *Keeper) Get(ctx sdk.Context) (*cmtproto.ConsensusParams, error) {
store := ctx.KVStore(k.storeKey)
cp := &cmtproto.ConsensusParams{}
bz := store.Get(types.ParamStoreKeyConsensusParams)
if err := k.cdc.Unmarshal(bz, cp); err != nil {
return nil, err
}
return cp, nil
}
func (k *Keeper) Has(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.ParamStoreKeyConsensusParams)
}
// Set sets the consensus parameters
func (k *Keeper) Set(ctx sdk.Context, cp *cmtproto.ConsensusParams) {
store := ctx.KVStore(k.storeKey)
store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp))
}