Skip to content

Commit

Permalink
chore(auction): return error on Not Found auction ID (#2544)
Browse files Browse the repository at this point in the history
* chore(auction): return error on Not Found auction ID

* lint
  • Loading branch information
robert-zaremba authored Jun 7, 2024
1 parent ee860df commit 10f3261
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 11 additions & 6 deletions x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/umee-network/umee/v6/util/coin"
"github.com/umee-network/umee/v6/x/auction"
Expand Down Expand Up @@ -34,17 +36,20 @@ func (q Querier) RewardsAuction(goCtx context.Context, msg *auction.QueryRewards
*auction.QueryRewardsAuctionResponse, error,
) {
ctx := sdk.UnwrapSDKContext(goCtx)
bid, id := q.Keeper(&ctx).getRewardsBid(msg.Id)
k := q.Keeper(&ctx)
rewards, id := k.getRewardsAuction(msg.Id)
if rewards == nil {
return nil, status.Error(codes.NotFound, "wrong ID")
}
r := &auction.QueryRewardsAuctionResponse{Id: id}
r.Rewards = rewards.Rewards
r.EndsAt = rewards.EndsAt

bid := q.Keeper(&ctx).getRewardsBid(id)
if bid != nil {
r.Bidder = bid.Bidder
r.Bid = coin.UmeeInt(bid.Amount)
}
rewards, _ := q.Keeper(&ctx).getRewardsAuction(msg.Id)
if rewards != nil {
r.Rewards = rewards.Rewards
r.EndsAt = rewards.EndsAt
}

return r, nil
}
6 changes: 3 additions & 3 deletions x/auction/keeper/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (k Keeper) FinalizeRewardsAuction() error {
return nil
}

bid, _ := k.getRewardsBid(id)
bid := k.getRewardsBid(id)
if bid != nil && len(bid.Bidder) != 0 {
bidderAccAddr := sdk.MustAccAddressFromBech32(bid.Bidder)
err := k.sendCoins(k.accs.RewardsCollect, bidderAccAddr, a.Rewards)
Expand Down Expand Up @@ -98,13 +98,13 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error {
return store.SetValue(k.store, key, &bid, keyMsg)
}

func (k Keeper) getRewardsBid(id uint32) (*auction.Bid, uint32) {
func (k Keeper) getRewardsBid(id uint32) *auction.Bid {
if id == 0 {
id = k.currentRewardsAuctionID()
}
keyMsg := "auction.rewards.bid"
key := k.keyRewardsBid(id)
return store.GetValue[*auction.Bid](k.store, key, keyMsg), id
return store.GetValue[*auction.Bid](k.store, key, keyMsg)
}

func (k Keeper) getAllRewardsBids() ([]auction.BidKV, error) {
Expand Down

0 comments on commit 10f3261

Please sign in to comment.