Skip to content

Commit

Permalink
chore: implemented feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed May 8, 2024
1 parent 9f5c717 commit 1a71d2e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions x/funders/keeper/logic_funders.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,21 @@ func (k Keeper) GetCoinWhitelistMap(ctx sdk.Context) (whitelist map[string]types
// The amount is transferred from the funders to the recipient module account.
// If there are no more active funders, an event is emitted. This method only charges
// coins which are whitelisted.
func (k Keeper) ChargeFundersOfPool(ctx sdk.Context, poolId uint64, recipient string) (payouts sdk.Coins, err error) {
func (k Keeper) ChargeFundersOfPool(ctx sdk.Context, poolId uint64, recipient string) (sdk.Coins, error) {
// Get funding state for pool
fundingState, found := k.GetFundingState(ctx, poolId)
if !found {
return payouts, errors.Wrapf(errorsTypes.ErrNotFound, types.ErrFundingStateDoesNotExist.Error(), poolId)
return sdk.NewCoins(), errors.Wrapf(errorsTypes.ErrNotFound, types.ErrFundingStateDoesNotExist.Error(), poolId)
}

// If there are no active fundings we immediately return
activeFundings := k.GetActiveFundings(ctx, fundingState)
if len(activeFundings) == 0 {
return
return sdk.NewCoins(), nil
}

whitelist := k.GetCoinWhitelistMap(ctx)
payouts := sdk.NewCoins()

// Charge every active funder and collect payouts
for _, funding := range activeFundings {
Expand All @@ -96,12 +97,15 @@ func (k Keeper) ChargeFundersOfPool(ctx sdk.Context, poolId uint64, recipient st
}

if payouts.IsZero() {
return
return payouts, nil
}

// Move funds to recipient module
err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, recipient, payouts)
return
if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, recipient, payouts); err != nil {
return sdk.NewCoins(), err
}

return payouts, nil
}

// GetLowestFunding returns the funding with the lowest amount
Expand Down Expand Up @@ -195,8 +199,6 @@ func (k Keeper) ensureFreeSlot(ctx sdk.Context, newFunding *types.Funding, fundi
return nil
}

whitelist := k.GetCoinWhitelistMap(ctx)

lowestFunding, err := k.GetLowestFunding(ctx, activeFundings)
if err != nil {
return err
Expand All @@ -207,6 +209,8 @@ func (k Keeper) ensureFreeSlot(ctx sdk.Context, newFunding *types.Funding, fundi
return nil
}

whitelist := k.GetCoinWhitelistMap(ctx)

// Check if lowest funding is lower than new funding based on amount (amount per bundle is ignored)
if newFunding.GetScore(whitelist) < lowestFunding.GetScore(whitelist) {
return errors.Wrapf(errorsTypes.ErrLogic, types.ErrFundsTooLow.Error(), lowestFunding.GetScore(whitelist))
Expand Down

0 comments on commit 1a71d2e

Please sign in to comment.