-
Notifications
You must be signed in to change notification settings - Fork 172
/
keeper.go
91 lines (73 loc) · 2.07 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package keeper
import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/CosmosContracts/juno/v23/x/clock/types"
)
// Keeper of the clock store
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
wasmKeeper wasmkeeper.Keeper
contractKeeper wasmtypes.ContractOpsKeeper
authority string
}
func NewKeeper(
key storetypes.StoreKey,
cdc codec.BinaryCodec,
wasmKeeper wasmkeeper.Keeper,
contractKeeper wasmtypes.ContractOpsKeeper,
authority string,
) Keeper {
return Keeper{
cdc: cdc,
storeKey: key,
wasmKeeper: wasmKeeper,
contractKeeper: contractKeeper,
authority: authority,
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}
// GetAuthority returns the x/clock module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}
// SetParams sets the x/clock 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/clock 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
}
// GetContractKeeper returns the x/wasm module's contract keeper.
func (k Keeper) GetContractKeeper() wasmtypes.ContractOpsKeeper {
return k.contractKeeper
}
// GetCdc returns the x/clock module's codec.
func (k Keeper) GetCdc() codec.BinaryCodec {
return k.cdc
}
// GetStore returns the x/clock module's store key.
func (k Keeper) GetStore() storetypes.StoreKey {
return k.storeKey
}