diff --git a/proto/umee/auction/v1/query.proto b/proto/umee/auction/v1/query.proto index 0072468b51..39ba409c22 100644 --- a/proto/umee/auction/v1/query.proto +++ b/proto/umee/auction/v1/query.proto @@ -42,6 +42,8 @@ message QueryRewardsAuctionResponse { // highest bidder string bidder = 2; repeated cosmos.base.v1beta1.Coin rewards = 3 [(gogoproto.nullable) = false]; - cosmos.base.v1beta1.Coin usd_rewards = 4 [(gogoproto.nullable) = false]; - google.protobuf.Timestamp ends_at = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + google.protobuf.Timestamp ends_at = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + + // not sure if we will need it: + // cosmos.base.v1beta1.Coin usd_rewards = 5 [(gogoproto.nullable) = false]; } diff --git a/util/store/store.go b/util/store/store.go index 7ae917999d..0d90a1982a 100644 --- a/util/store/store.go +++ b/util/store/store.go @@ -76,6 +76,7 @@ func SetBinValue[T BinMarshalable](store sdk.KVStore, key []byte, value T, errFi // false without modifying the object. func GetValueCdc(store sdk.KVStore, cdc codec.BinaryCodec, key []byte, object codec.ProtoMarshaler, errField string) bool { + if bz := store.Get(key); len(bz) > 0 { err := cdc.Unmarshal(bz, object) if err != nil { diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index 0c9b3a1c6c..1d0c716ad7 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -27,10 +27,14 @@ func (q Querier) RewardsParams(goCtx context.Context, _ *auction.QueryRewardsPar } // RewardsAuction returns params of the x/auction module. -func (q Querier) RewardsAuction(goCtx context.Context, _ *auction.QueryRewardsAuction) ( +func (q Querier) RewardsAuction(goCtx context.Context, msg *auction.QueryRewardsAuction) ( *auction.QueryRewardsAuctionResponse, error, ) { ctx := sdk.UnwrapSDKContext(goCtx) - b := q.Keeper(&ctx) - return b.currentRewardsAuction() + bid, id := q.Keeper(&ctx).getRewardsBid(msg.Id) + return &auction.QueryRewardsAuctionResponse{ + Id: id, + Bidder: bid.Bidder, + // TODO: add other fields + }, nil } diff --git a/x/auction/keeper/keys.go b/x/auction/keeper/keys.go index d3da854494..e0cb8e2bdd 100644 --- a/x/auction/keeper/keys.go +++ b/x/auction/keeper/keys.go @@ -2,7 +2,6 @@ package keeper import ( "github.com/umee-network/umee/v6/util" - "github.com/umee-network/umee/v6/x/auction" ) var ( @@ -12,5 +11,5 @@ var ( ) func (k Keeper) keyRewardsBid(id uint32) []byte { - return util.ConcatBytes(0, keyPrefixRewardsBid) + return util.KeyWithUint32(keyPrefixRewardsBid, id) } diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index 13cb3c1425..1606bb90cf 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -23,8 +23,14 @@ func (k Keeper) currentRewardsAuction() uint32 { } func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { + id := k.currentRewardsAuction() + if id != msg.Id { + return errors.New("bad auction ID, can only bid in the current auction = " + strconv.Itoa(int(id))) + } + keyMsg := "auction.rewards.highest_bid" - lastBid := store.GetValue[*auction.Bid](k.store, keyRewardsHighestBid, keyMsg) + key := k.keyRewardsBid(msg.Id) + lastBid := store.GetValue[*auction.Bid](k.store, key, keyMsg) minBid := auction.MinRewardsBid if lastBid != nil { minBid = lastBid.Amount.Add(minBid) @@ -38,10 +44,6 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { prevBidder, err := sdk.AccAddressFromBech32(lastBid.Bidder) util.Panic(err) vault := k.accs.RewardsBid - id := k.currentRewardsAuction() - if id != msg.Id { - return errors.New("bad auction ID, can only bid in the current auction = " + strconv.Itoa(int(id))) - } if lastBid.Bidder != msg.Sender { if err = k.sendCoins(vault, prevBidder, umeeCoins(lastBid.Amount)); err != nil { @@ -58,11 +60,14 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { } bid := auction.Bid{Bidder: msg.Sender, Amount: msg.Amount.Amount} - return store.SetValue(k.store, keyRewardsHighestBid, &bid, keyMsg) + return store.SetValue(k.store, key, &bid, keyMsg) } - - -func (k Keeper) currentRewardsAuction() (*auction.QueryRewardsAuctionResponse, error) { - panic("not implemented") +func (k Keeper) getRewardsBid(id uint32) (*auction.Bid, uint32) { + if id == 0 { + id = k.currentRewardsAuction() + } + keyMsg := "auction.rewards.bid" + key := k.keyRewardsBid(id) + return store.GetValue[*auction.Bid](k.store, key, keyMsg), id }