Skip to content

Commit

Permalink
refactor the bidder code
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 committed Jun 6, 2024
1 parent d3dbc6f commit 4c17664
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions x/auction/keeper/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/umee-network/umee/v6/util"
"github.com/umee-network/umee/v6/util/coin"
"github.com/umee-network/umee/v6/util/sdkutil"
"github.com/umee-network/umee/v6/util/store"
Expand Down Expand Up @@ -82,34 +81,32 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error {
return err
}

sender, err := sdk.AccAddressFromBech32(msg.Sender)
util.Panic(err)

if lastBid == nil {
if err = k.sendToModule(sender, msg.Amount); err != nil {
return err
}
} else {
bidderAccAddr, err := sdk.AccAddressFromBech32(lastBid.Bidder)
if err != nil {
return err
}
toAuction := msg.Amount
if lastBid != nil {
if msg.Sender == lastBid.Bidder {

Check warning on line 86 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L84-L86

Added lines #L84 - L86 were not covered by tests
// bidder updates his last bid: send only diff
toAuction = msg.Amount.SubAmount(lastBid.Amount)
} else {
returned := coin.UmeeInt(lastBid.Amount)
if err = k.sendFromModule(bidderAccAddr, returned); err != nil {
return err
}
if err = k.sendToModule(sender, msg.Amount); err != nil {
bidderAccAddr, err := sdk.AccAddressFromBech32(lastBid.Bidder)
if err != nil {
return err

Check warning on line 93 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L88-L93

Added lines #L88 - L93 were not covered by tests
}
} else {
diff := msg.Amount.SubAmount(lastBid.Amount)
if err = k.sendToModule(sender, diff); err != nil {
if err = k.sendFromModule(bidderAccAddr, returned); err != nil {
return err

Check warning on line 96 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L95-L96

Added lines #L95 - L96 were not covered by tests
}
}
}

sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return err

Check warning on line 103 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L102-L103

Added lines #L102 - L103 were not covered by tests
}

if err = k.sendToModule(sender, toAuction); err != nil {
return err

Check warning on line 107 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L106-L107

Added lines #L106 - L107 were not covered by tests
}

bid := auction.Bid{Bidder: msg.Sender, Amount: msg.Amount.Amount}

Check warning on line 110 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L110

Added line #L110 was not covered by tests
return store.SetValue(k.store, key, &bid, keyMsg)
}
Expand Down

0 comments on commit 4c17664

Please sign in to comment.