/
risk_params.go
83 lines (68 loc) · 2.64 KB
/
risk_params.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
package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/petri-labs/kaiju/x/maker/types"
)
func (k Keeper) SetBackingRiskParams(ctx sdk.Context, params types.BackingRiskParams) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixBackingParams)
bz := k.cdc.MustMarshal(¶ms)
store.Set([]byte(params.BackingDenom), bz)
}
func (k Keeper) SetCollateralRiskParams(ctx sdk.Context, params types.CollateralRiskParams) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixCollateralParams)
bz := k.cdc.MustMarshal(¶ms)
store.Set([]byte(params.CollateralDenom), bz)
}
func (k Keeper) IsBackingRegistered(ctx sdk.Context, denom string) bool {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixBackingParams)
return store.Has([]byte(denom))
}
func (k Keeper) GetBackingRiskParams(ctx sdk.Context, denom string) (types.BackingRiskParams, bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixBackingParams)
bz := store.Get([]byte(denom))
var params types.BackingRiskParams
if len(bz) == 0 {
return params, false
}
k.cdc.MustUnmarshal(bz, ¶ms)
return params, true
}
func (k Keeper) GetAllBackingRiskParams(ctx sdk.Context) []types.BackingRiskParams {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixBackingParams)
defer iterator.Close()
var allParams []types.BackingRiskParams
for ; iterator.Valid(); iterator.Next() {
var params types.BackingRiskParams
k.cdc.MustUnmarshal(iterator.Value(), ¶ms)
allParams = append(allParams, params)
}
return allParams
}
func (k Keeper) IsCollateralRegistered(ctx sdk.Context, denom string) bool {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixCollateralParams)
return store.Has([]byte(denom))
}
func (k Keeper) GetCollateralRiskParams(ctx sdk.Context, denom string) (types.CollateralRiskParams, bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixCollateralParams)
bz := store.Get([]byte(denom))
var params types.CollateralRiskParams
if len(bz) == 0 {
return params, false
}
k.cdc.MustUnmarshal(bz, ¶ms)
return params, true
}
func (k Keeper) GetAllCollateralRiskParams(ctx sdk.Context) []types.CollateralRiskParams {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixCollateralParams)
defer iterator.Close()
var allParams []types.CollateralRiskParams
for ; iterator.Valid(); iterator.Next() {
var params types.CollateralRiskParams
k.cdc.MustUnmarshal(iterator.Value(), ¶ms)
allParams = append(allParams, params)
}
return allParams
}