From 69f98779e98060e160c57d1f0a9385709c4c2276 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 7 Jun 2024 18:48:22 +0200 Subject: [PATCH 1/2] chore(auction): return error on Not Found auction ID --- x/auction/keeper/grpc_query.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index e537594fa9..c4373fe142 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -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" @@ -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 } From fde43f9f6205c367c005f18eb31fd3891724f290 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 7 Jun 2024 18:58:55 +0200 Subject: [PATCH 2/2] lint --- x/auction/keeper/grpc_query.go | 2 +- x/auction/keeper/rewards.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index c4373fe142..42a8e7bcf2 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -45,7 +45,7 @@ func (q Querier) RewardsAuction(goCtx context.Context, msg *auction.QueryRewards r.Rewards = rewards.Rewards r.EndsAt = rewards.EndsAt - bid, _ := q.Keeper(&ctx).getRewardsBid(id) + bid := q.Keeper(&ctx).getRewardsBid(id) if bid != nil { r.Bidder = bid.Bidder r.Bid = coin.UmeeInt(bid.Amount) diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index db98d8cbcd..ce7cce0a96 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -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) @@ -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) {