-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
135 lines (118 loc) · 3.97 KB
/
store.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
129
130
131
132
133
134
135
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/fanfury-sports/blackfury/x/voter/types"
)
func (k Keeper) SetTotalVotes(ctx sdk.Context, votes sdk.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: votes})
store.Set(types.TotalVotesKey(), bz)
}
func (k Keeper) GetTotalVotes(ctx sdk.Context) sdk.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.TotalVotesKey())
if bz == nil {
return sdk.ZeroInt()
}
var votes sdk.IntProto
k.cdc.MustUnmarshal(bz, &votes)
return votes.Int
}
func (k Keeper) SetTotalVotesByUser(ctx sdk.Context, veID uint64, votes sdk.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: votes})
store.Set(types.TotalVotesByUserKey(veID), bz)
}
func (k Keeper) GetTotalVotesByUser(ctx sdk.Context, veID uint64) sdk.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.TotalVotesByUserKey(veID))
if bz == nil {
return sdk.ZeroInt()
}
var votes sdk.IntProto
k.cdc.MustUnmarshal(bz, &votes)
return votes.Int
}
func (k Keeper) DeleteTotalVotesByUser(ctx sdk.Context, veID uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.TotalVotesByUserKey(veID))
}
func (k Keeper) SetPoolWeightedVotes(ctx sdk.Context, poolDenom string, votes sdk.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: votes})
store.Set(types.PoolWeightedVotesKey(poolDenom), bz)
}
func (k Keeper) GetPoolWeightedVotes(ctx sdk.Context, poolDenom string) sdk.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.PoolWeightedVotesKey(poolDenom))
if bz == nil {
return sdk.ZeroInt()
}
var votes sdk.IntProto
k.cdc.MustUnmarshal(bz, &votes)
return votes.Int
}
func (k Keeper) SetPoolWeightedVotesByUser(ctx sdk.Context, veID uint64, poolDenom string, votes sdk.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: votes})
store.Set(types.PoolWeightedVotesByUserKey(veID, poolDenom), bz)
}
func (k Keeper) GetPoolWeightedVotesByUser(ctx sdk.Context, veID uint64, poolDenom string) sdk.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.PoolWeightedVotesByUserKey(veID, poolDenom))
if bz == nil {
return sdk.ZeroInt()
}
var votes sdk.IntProto
k.cdc.MustUnmarshal(bz, &votes)
return votes.Int
}
func (k Keeper) DeletePoolWeightedVotesByUser(ctx sdk.Context, veID uint64, poolDenom string) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.PoolWeightedVotesByUserKey(veID, poolDenom))
}
func (k Keeper) SetIndex(ctx sdk.Context, index sdk.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: index})
store.Set(types.IndexKey(), bz)
}
func (k Keeper) GetIndex(ctx sdk.Context) sdk.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.IndexKey())
if bz == nil {
return sdk.ZeroInt()
}
var index sdk.IntProto
k.cdc.MustUnmarshal(bz, &index)
return index.Int
}
func (k Keeper) SetIndexAtLastUpdatedByGauge(ctx sdk.Context, poolDenom string, index sdk.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: index})
store.Set(types.IndexAtLastUpdatedByGaugeKey(poolDenom), bz)
}
func (k Keeper) GetIndexAtLastUpdatedByGauge(ctx sdk.Context, poolDenom string) sdk.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.IndexAtLastUpdatedByGaugeKey(poolDenom))
if bz == nil {
return sdk.ZeroInt()
}
var index sdk.IntProto
k.cdc.MustUnmarshal(bz, &index)
return index.Int
}
func (k Keeper) SetClaimableRewardByGauge(ctx sdk.Context, poolDenom string, claimable sdk.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: claimable})
store.Set(types.ClaimableRewardByGaugeKey(poolDenom), bz)
}
func (k Keeper) GetClaimableRewardByGauge(ctx sdk.Context, poolDenom string) sdk.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ClaimableRewardByGaugeKey(poolDenom))
if bz == nil {
return sdk.ZeroInt()
}
var claimable sdk.IntProto
k.cdc.MustUnmarshal(bz, &claimable)
return claimable.Int
}