Skip to content

Commit

Permalink
pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarom Swisa authored and Yarom Swisa committed Mar 5, 2024
1 parent 45bc5cf commit c73d48a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
21 changes: 17 additions & 4 deletions x/rewards/keeper/base_pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (k Keeper) SetAllBasePay(ctx sdk.Context, list []types.BasePayGenesis) {
}
}

func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string, removeAfterPop bool) (list []types.BasePayWithIndex) {
func (k Keeper) getAllBasePayForChain(ctx sdk.Context, chainID string) (list []types.BasePayWithIndex) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BasePayPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte(chainID))

Expand All @@ -64,9 +64,22 @@ func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string, removeAft
var val types.BasePay
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, types.BasePayWithIndex{BasePayIndex: types.BasePayKeyRecover(string(iterator.Key())), BasePay: val})
if removeAfterPop {
store.Delete(iterator.Key())
}
}

return
}

func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string) (list []types.BasePayWithIndex) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BasePayPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte(chainID))

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.BasePay
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, types.BasePayWithIndex{BasePayIndex: types.BasePayKeyRecover(string(iterator.Key())), BasePay: val})
store.Delete(iterator.Key())
}

return
Expand Down
10 changes: 8 additions & 2 deletions x/rewards/keeper/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@ func (k Keeper) specEmissionParts(ctx sdk.Context) (emissions []types.SpecEmissi
return emissions
}

func (k Keeper) specProvidersBasePay(ctx sdk.Context, chainID string, removeAfterPop bool) ([]types.BasePayWithIndex, math.Int) {
basepays := k.popAllBasePayForChain(ctx, chainID, removeAfterPop)
func (k Keeper) specProvidersBasePay(ctx sdk.Context, chainID string, pop bool) ([]types.BasePayWithIndex, math.Int) {
var basepays []types.BasePayWithIndex
if pop {
basepays = k.popAllBasePayForChain(ctx, chainID)
} else {
basepays = k.getAllBasePayForChain(ctx, chainID)
}

totalBasePay := math.ZeroInt()
for _, basepay := range basepays {
totalBasePay = totalBasePay.Add(basepay.Total)
Expand Down

0 comments on commit c73d48a

Please sign in to comment.