Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(auction): return error on Not Found auction ID #2544

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Comment on lines +39 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling for a non-existent auction ID is correctly implemented. Consider improving the error message for clarity.

- return nil, status.Error(codes.NotFound, "wrong ID")
+ return nil, status.Error(codes.NotFound, "Auction ID not found")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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
k := q.Keeper(&ctx)
rewards, id := k.getRewardsAuction(msg.Id)
if rewards == nil {
return nil, status.Error(codes.NotFound, "Auction ID not found")
}
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
Loading