-
Notifications
You must be signed in to change notification settings - Fork 29
/
keeper.go
124 lines (109 loc) · 3.19 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package keeper
import (
"fmt"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/ixofoundation/ixo-blockchain/v2/x/claims/types"
entitykeeper "github.com/ixofoundation/ixo-blockchain/v2/x/entity/keeper"
iidkeeper "github.com/ixofoundation/ixo-blockchain/v2/x/iid/keeper"
"github.com/tendermint/tendermint/libs/log"
)
// UnmarshalFn is a generic function to unmarshal bytes
type UnmarshalFn func(value []byte) (interface{}, bool)
// MarshalFn is a generic function to marshal bytes
type MarshalFn func(value interface{}) []byte
type (
Keeper struct {
cdc codec.BinaryCodec
storeKey sdk.StoreKey
memKey sdk.StoreKey
paramstore paramtypes.Subspace
AuthzKeeper authzkeeper.Keeper
IidKeeper iidkeeper.Keeper
BankKeeper bankkeeper.Keeper
EntityKeeper entitykeeper.Keeper
WasmKeeper wasmtypes.ContractOpsKeeper
}
)
func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey sdk.StoreKey,
ps paramtypes.Subspace,
iidKeeper iidkeeper.Keeper,
authzKeeper authzkeeper.Keeper,
bankKeeper bankkeeper.Keeper,
entityKeeper entitykeeper.Keeper,
wasmKeeper wasmkeeper.Keeper,
) Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}
return Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
paramstore: ps,
IidKeeper: iidKeeper,
AuthzKeeper: authzKeeper,
BankKeeper: bankKeeper,
EntityKeeper: entityKeeper,
WasmKeeper: wasmkeeper.NewDefaultPermissionKeeper(wasmKeeper),
}
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
// GetParams returns the total set of project parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramstore.GetParamSet(ctx, ¶ms)
return params
}
// SetParams sets the total set of project parameters.
func (k Keeper) SetParams(ctx sdk.Context, params *types.Params) {
k.paramstore.SetParamSet(ctx, params)
}
// Set sets a value in the db with a prefixed key
func (k Keeper) Set(ctx sdk.Context,
key []byte,
prefix []byte,
i interface{},
marshal MarshalFn,
) {
store := ctx.KVStore(k.storeKey)
store.Set(append(prefix, key...), marshal(i))
}
// Delete - deletes a value form the store
func (k Keeper) Delete(
ctx sdk.Context,
key []byte,
prefix []byte,
) {
store := ctx.KVStore(k.storeKey)
store.Delete(append(prefix, key...))
}
// Get gets an item from the store by bytes
func (k Keeper) Get(
ctx sdk.Context,
key []byte,
prefix []byte,
unmarshal UnmarshalFn,
) (i interface{}, found bool) {
store := ctx.KVStore(k.storeKey)
value := store.Get(append(prefix, key...))
return unmarshal(value)
}
// GetAll values from with a prefix from the store
func (k Keeper) GetAll(
ctx sdk.Context,
prefix []byte,
) sdk.Iterator {
store := ctx.KVStore(k.storeKey)
return sdk.KVStorePrefixIterator(store, prefix)
}