@@ -221,27 +221,11 @@ func (bva BaseVestingAccount) spendableCoins(vestingCoins sdk.Coins) sdk.Coins {
221
221
var spendableCoins sdk.Coins
222
222
bc := bva .GetCoins ()
223
223
224
- j , k := 0 , 0
225
224
for _ , coin := range bc {
226
225
// zip/lineup all coins by their denomination to provide O(n) time
227
- for j < len (vestingCoins ) && vestingCoins [j ].Denom != coin .Denom {
228
- j ++
229
- }
230
- for k < len (bva .DelegatedVesting ) && bva .DelegatedVesting [k ].Denom != coin .Denom {
231
- k ++
232
- }
233
-
234
226
baseAmt := coin .Amount
235
-
236
- vestingAmt := sdk .ZeroInt ()
237
- if len (vestingCoins ) > 0 {
238
- vestingAmt = vestingCoins [j ].Amount
239
- }
240
-
241
- delVestingAmt := sdk .ZeroInt ()
242
- if len (bva .DelegatedVesting ) > 0 {
243
- delVestingAmt = bva .DelegatedVesting [k ].Amount
244
- }
227
+ vestingAmt := vestingCoins .AmountOf (coin .Denom )
228
+ delVestingAmt := bva .DelegatedVesting .AmountOf (coin .Denom )
245
229
246
230
// compute min((BC + DV) - V, BC) per the specification
247
231
min := sdk .MinInt (baseAmt .Add (delVestingAmt ).Sub (vestingAmt ), baseAmt )
@@ -264,33 +248,12 @@ func (bva BaseVestingAccount) spendableCoins(vestingCoins sdk.Coins) sdk.Coins {
264
248
func (bva * BaseVestingAccount ) trackDelegation (vestingCoins , amount sdk.Coins ) {
265
249
bc := bva .GetCoins ()
266
250
267
- i , j , k := 0 , 0 , 0
268
251
for _ , coin := range amount {
269
252
// zip/lineup all coins by their denomination to provide O(n) time
270
- for i < len (bc ) && bc [i ].Denom != coin .Denom {
271
- i ++
272
- }
273
- for j < len (vestingCoins ) && vestingCoins [j ].Denom != coin .Denom {
274
- j ++
275
- }
276
- for k < len (bva .DelegatedVesting ) && bva .DelegatedVesting [k ].Denom != coin .Denom {
277
- k ++
278
- }
279
253
280
- baseAmt := sdk .ZeroInt ()
281
- if len (bc ) > 0 {
282
- baseAmt = bc [i ].Amount
283
- }
284
-
285
- vestingAmt := sdk .ZeroInt ()
286
- if len (vestingCoins ) > 0 {
287
- vestingAmt = vestingCoins [j ].Amount
288
- }
289
-
290
- delVestingAmt := sdk .ZeroInt ()
291
- if len (bva .DelegatedVesting ) > 0 {
292
- delVestingAmt = bva .DelegatedVesting [k ].Amount
293
- }
254
+ baseAmt := bc .AmountOf (coin .Denom )
255
+ vestingAmt := vestingCoins .AmountOf (coin .Denom )
256
+ delVestingAmt := bva .DelegatedVesting .AmountOf (coin .Denom )
294
257
295
258
// Panic if the delegation amount is zero or if the base coins does not
296
259
// exceed the desired delegation amount.
@@ -325,21 +288,12 @@ func (bva *BaseVestingAccount) trackDelegation(vestingCoins, amount sdk.Coins) {
325
288
//
326
289
// CONTRACT: The account's coins and undelegation coins must be sorted.
327
290
func (bva * BaseVestingAccount ) TrackUndelegation (amount sdk.Coins ) {
328
- i := 0
329
291
for _ , coin := range amount {
330
292
// panic if the undelegation amount is zero
331
293
if coin .Amount .IsZero () {
332
294
panic ("undelegation attempt with zero coins" )
333
295
}
334
-
335
- for i < len (bva .DelegatedFree ) && bva .DelegatedFree [i ].Denom != coin .Denom {
336
- i ++
337
- }
338
-
339
- delegatedFree := sdk .ZeroInt ()
340
- if len (bva .DelegatedFree ) > 0 {
341
- delegatedFree = bva .DelegatedFree [i ].Amount
342
- }
296
+ delegatedFree := bva .DelegatedFree .AmountOf (coin .Denom )
343
297
344
298
// compute x and y per the specification, where:
345
299
// X := min(DF, D)
0 commit comments