-
Notifications
You must be signed in to change notification settings - Fork 41
/
param_change.go
53 lines (43 loc) · 1.42 KB
/
param_change.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
package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/spn/x/launch/types"
)
// SetParamChange set a specific ParamChange in the store from its index
func (k Keeper) SetParamChange(ctx sdk.Context, paramChange types.ParamChange) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ParamChangeKeyPrefix))
b := k.cdc.MustMarshal(¶mChange)
store.Set(types.ParamChangePath(
paramChange.LaunchID,
paramChange.Module,
paramChange.Param,
), b)
}
// GetParamChange returns a ParamChange from its index
func (k Keeper) GetParamChange(
ctx sdk.Context,
launchID uint64,
module,
param string,
) (val types.ParamChange, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ParamChangeKeyPrefix))
b := store.Get(types.ParamChangePath(launchID, module, param))
if b == nil {
return val, false
}
k.cdc.MustUnmarshal(b, &val)
return val, true
}
// GetAllParamChange returns all ParamChange
func (k Keeper) GetAllParamChange(ctx sdk.Context) (list []types.ParamChange) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ParamChangeKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var val types.ParamChange
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}