Skip to content

Commit

Permalink
improve getToDistributedCoinsFromGauges (#2014)
Browse files Browse the repository at this point in the history
* mod getToDistributedCoinsFromGauges

* mod getToDistributedCoinsFromGauges

* rm unused function
  • Loading branch information
catShaark authored Jul 11, 2022
1 parent 938f9bd commit 23dbadd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
11 changes: 8 additions & 3 deletions x/incentives/keeper/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ func (k Keeper) getDistributedCoinsFromGauges(gauges []types.Gauge) sdk.Coins {
}

func (k Keeper) getToDistributeCoinsFromGauges(gauges []types.Gauge) sdk.Coins {
// TODO: Consider optimizing this in the future to only require one iteration over all gauges.
coins := k.getCoinsFromGauges(gauges)
distributed := k.getDistributedCoinsFromGauges(gauges)
coins := sdk.Coins{}
distributed := sdk.Coins{}

for _, gauge := range gauges {
coins = coins.Add(gauge.Coins...)
distributed = distributed.Add(gauge.DistributedCoins...)
}

return coins.Sub(distributed)
}

Expand Down
9 changes: 0 additions & 9 deletions x/incentives/keeper/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ func (k Keeper) getGaugesFromIterator(ctx sdk.Context, iterator db.Iterator) []t
return gauges
}

// Compute the total amount of coins in all the gauges.
func (k Keeper) getCoinsFromGauges(gauges []types.Gauge) sdk.Coins {
coins := sdk.Coins{}
for _, gauge := range gauges {
coins = coins.Add(gauge.Coins...)
}
return coins
}

// setGauge set the gauge inside store.
func (k Keeper) setGauge(ctx sdk.Context, gauge *types.Gauge) error {
store := ctx.KVStore(k.storeKey)
Expand Down

0 comments on commit 23dbadd

Please sign in to comment.