Skip to content

Commit

Permalink
query
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Apr 16, 2024
1 parent e3e1672 commit c35243c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
6 changes: 4 additions & 2 deletions proto/umee/auction/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
1 change: 1 addition & 0 deletions util/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions x/auction/keeper/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"github.com/umee-network/umee/v6/util"
"github.com/umee-network/umee/v6/x/auction"
)

var (
Expand All @@ -12,5 +11,5 @@ var (
)

func (k Keeper) keyRewardsBid(id uint32) []byte {
return util.ConcatBytes(0, keyPrefixRewardsBid)
return util.KeyWithUint32(keyPrefixRewardsBid, id)
}
25 changes: 15 additions & 10 deletions x/auction/keeper/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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
}

0 comments on commit c35243c

Please sign in to comment.