-
Notifications
You must be signed in to change notification settings - Fork 0
/
exposure_participation.go
128 lines (100 loc) · 4.52 KB
/
exposure_participation.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
125
126
127
128
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furya-network/furya/x/strategicreserve/types"
)
// SetParticipationExposure sets a participation exposure.
func (k Keeper) SetParticipationExposure(ctx sdk.Context, pe types.ParticipationExposure) {
peKey := types.GetParticipationExposureKey(pe.BookUID, pe.OddsUID, pe.ParticipationIndex)
store := k.getParticipationExposureStore(ctx)
b := k.cdc.MustMarshal(&pe)
store.Set(peKey, b)
k.SetParticipationExposureByIndex(ctx, pe)
}
// removeParticipationExposure removes a participation exposure.
func (k Keeper) removeParticipationExposure(ctx sdk.Context, pe types.ParticipationExposure) {
store := k.getParticipationExposureStore(ctx)
store.Delete(types.GetParticipationExposureKey(pe.BookUID, pe.OddsUID, pe.ParticipationIndex))
}
// GetExposureByBookAndOdds returns all exposures for a book id and odds id
func (k Keeper) GetExposureByBookAndOdds(ctx sdk.Context, bookUID, oddsUID string) (list []types.ParticipationExposure, err error) {
store := k.getParticipationExposureStore(ctx)
iterator := sdk.KVStorePrefixIterator(store, types.GetParticipationExposuresKey(bookUID, oddsUID))
defer func() {
err = iterator.Close()
}()
for ; iterator.Valid(); iterator.Next() {
var val types.ParticipationExposure
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}
// GetAllParticipationExposures returns all participation exposures used during genesis dump.
func (k Keeper) GetAllParticipationExposures(ctx sdk.Context) (list []types.ParticipationExposure, err error) {
store := k.getParticipationExposureStore(ctx)
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer func() {
err = iterator.Close()
}()
for ; iterator.Valid(); iterator.Next() {
var val types.ParticipationExposure
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}
// SetParticipationExposureByIndex sets a participation exposure by index.
func (k Keeper) SetParticipationExposureByIndex(ctx sdk.Context, pe types.ParticipationExposure) {
peKey := types.GetParticipationExposureByIndexKey(pe.BookUID, pe.OddsUID, pe.ParticipationIndex)
store := k.getParticipationExposureByIndexStore(ctx)
b := k.cdc.MustMarshal(&pe)
store.Set(peKey, b)
}
// GetExposureByBookAndParticipationIndex returns all exposures for a book id and participation index
func (k Keeper) GetExposureByBookAndParticipationIndex(ctx sdk.Context, bookUID string, participationIndex uint64) (list []types.ParticipationExposure, err error) {
store := k.getParticipationExposureByIndexStore(ctx)
iterator := sdk.KVStorePrefixIterator(store, types.GetParticipationByIndexKey(bookUID, participationIndex))
defer func() {
err = iterator.Close()
}()
for ; iterator.Valid(); iterator.Next() {
var val types.ParticipationExposure
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}
// removeParticipationExposureByIndex removes a participation exposure by index.
func (k Keeper) removeParticipationExposureByIndex(ctx sdk.Context, pe types.ParticipationExposure) {
store := k.getParticipationExposureByIndexStore(ctx)
store.Delete(types.GetParticipationExposureByIndexKey(pe.BookUID, pe.OddsUID, pe.ParticipationIndex))
}
// SetHistoricalParticipationExposure sets a historical participation exposure.
func (k Keeper) SetHistoricalParticipationExposure(ctx sdk.Context, pe types.ParticipationExposure) {
peKey := types.GetHistoricalParticipationExposureKey(pe.BookUID, pe.OddsUID, pe.ParticipationIndex, pe.Round)
store := k.getHistoricalParticipationExposureStore(ctx)
b := k.cdc.MustMarshal(&pe)
store.Set(peKey, b)
}
// GetAllHistoricalParticipationExposures returns all participation exposures used during genesis dump.
func (k Keeper) GetAllHistoricalParticipationExposures(ctx sdk.Context) (list []types.ParticipationExposure, err error) {
store := k.getHistoricalParticipationExposureStore(ctx)
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer func() {
err = iterator.Close()
}()
for ; iterator.Valid(); iterator.Next() {
var val types.ParticipationExposure
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}
// MoveToHistoricalParticipationExposure removes the participation exposures and indices
// and sets historical participation exposures.
func (k Keeper) MoveToHistoricalParticipationExposure(ctx sdk.Context, pe types.ParticipationExposure) {
k.SetHistoricalParticipationExposure(ctx, pe)
k.removeParticipationExposure(ctx, pe)
k.removeParticipationExposureByIndex(ctx, pe)
}