@@ -86,12 +86,14 @@ func (k Keeper) GetLockedPower(ctx sdk.Context, lockerAddr sdk.AccAddress, keyNa
86
86
return lock .Amount , nil
87
87
}
88
88
89
+ // getAccumulatedRewards gets the accumulatedRewards of a lock if they lock since beginning.
89
90
func (k Keeper ) getAccumulatedRewards (ctx sdk.Context , lock types.Lock ) sdk.DecCoins {
90
91
key := k .MustGetKey (ctx , lock .Key )
91
92
92
93
return key .RewardPerPowers .MulDecTruncate (sdkmath .LegacyNewDecFromInt (lock .Amount ))
93
94
}
94
95
96
+ // getReward gets the reward of a lock by using accumulated rewards and reward debts.
95
97
func (k Keeper ) getReward (ctx sdk.Context , lock types.Lock ) types.Reward {
96
98
totalRewards := k .getAccumulatedRewards (ctx , lock )
97
99
@@ -105,14 +107,17 @@ func (k Keeper) getReward(ctx sdk.Context, lock types.Lock) types.Reward {
105
107
// store part
106
108
// -------------------------------
107
109
110
+ // GetLocksIterator gets iterator of lock store.
108
111
func (k Keeper ) GetLocksIterator (ctx sdk.Context ) sdk.Iterator {
109
112
return sdk .KVStorePrefixIterator (ctx .KVStore (k .storeKey ), types .LockStoreKeyPrefix )
110
113
}
111
114
115
+ // GetLocksByAddressIterator gets iterator of locks of the speicfic address.
112
116
func (k Keeper ) GetLocksByAddressIterator (ctx sdk.Context , addr sdk.AccAddress ) sdk.Iterator {
113
117
return sdk .KVStorePrefixIterator (ctx .KVStore (k .storeKey ), types .LocksStoreKey (addr ))
114
118
}
115
119
120
+ // GetLocksByAddress gets all locks of the address.
116
121
func (k Keeper ) GetLocksByAddress (ctx sdk.Context , addr sdk.AccAddress ) (locks []types.Lock ) {
117
122
iterator := k .GetLocksByAddressIterator (ctx , addr )
118
123
defer iterator .Close ()
@@ -126,6 +131,7 @@ func (k Keeper) GetLocksByAddress(ctx sdk.Context, addr sdk.AccAddress) (locks [
126
131
return locks
127
132
}
128
133
134
+ // GetLocks gets all locks in the store.
129
135
func (k Keeper ) GetLocks (ctx sdk.Context ) (locks []types.Lock ) {
130
136
iterator := k .GetLocksIterator (ctx )
131
137
defer iterator .Close ()
@@ -139,10 +145,12 @@ func (k Keeper) GetLocks(ctx sdk.Context) (locks []types.Lock) {
139
145
return locks
140
146
}
141
147
148
+ // HasLock checks if lock exists in the store.
142
149
func (k Keeper ) HasLock (ctx sdk.Context , addr sdk.AccAddress , keyName string ) bool {
143
150
return ctx .KVStore (k .storeKey ).Has (types .LockStoreKey (addr , keyName ))
144
151
}
145
152
153
+ // GetLock gets a lock from store by address and key name.
146
154
func (k Keeper ) GetLock (ctx sdk.Context , addr sdk.AccAddress , keyName string ) (types.Lock , error ) {
147
155
bz := ctx .KVStore (k .storeKey ).Get (types .LockStoreKey (addr , keyName ))
148
156
if bz == nil {
@@ -159,6 +167,7 @@ func (k Keeper) GetLock(ctx sdk.Context, addr sdk.AccAddress, keyName string) (t
159
167
return lock , nil
160
168
}
161
169
170
+ // SetLock sets a lock to the store.
162
171
func (k Keeper ) SetLock (ctx sdk.Context , lock types.Lock ) {
163
172
addr := sdk .MustAccAddressFromBech32 (lock .LockerAddress )
164
173
k .DeleteLock (ctx , addr , lock .Key )
@@ -167,6 +176,7 @@ func (k Keeper) SetLock(ctx sdk.Context, lock types.Lock) {
167
176
k .setLockByAmount (ctx , lock )
168
177
}
169
178
179
+ // DeleteLock deletes a lock from the store.
170
180
func (k Keeper ) DeleteLock (ctx sdk.Context , addr sdk.AccAddress , keyName string ) {
171
181
lock , err := k .GetLock (ctx , addr , keyName )
172
182
if err != nil {
@@ -176,10 +186,12 @@ func (k Keeper) DeleteLock(ctx sdk.Context, addr sdk.AccAddress, keyName string)
176
186
k .deleteLockByAmount (ctx , lock )
177
187
}
178
188
189
+ // setLockByAmount sets a lock by amount to the store.
179
190
func (k Keeper ) setLockByAmount (ctx sdk.Context , lock types.Lock ) {
180
191
ctx .KVStore (k .storeKey ).Set (types .LockByAmountIndexKey (lock ), []byte (lock .Key ))
181
192
}
182
193
194
+ // deleteLockByAmount deletes a lock by amount from the store.
183
195
func (k Keeper ) deleteLockByAmount (ctx sdk.Context , lock types.Lock ) {
184
196
ctx .KVStore (k .storeKey ).Delete (types .LockByAmountIndexKey (lock ))
185
197
}
0 commit comments