Skip to content

Commit

Permalink
fix the bidder address on genesis export
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 committed Jun 5, 2024
1 parent 6d79cd1 commit f7b3f07
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 100 deletions.
2 changes: 1 addition & 1 deletion proto/umee/auction/v1/auction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ message RewardsParams {

// Bid records a user bid
message Bid {
bytes bidder = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string bidder = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string amount = 2 [(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false];
}

Expand Down
3 changes: 2 additions & 1 deletion proto/umee/auction/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package umee.auction.v1;

import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "umee/auction/v1/auction.proto";
import "cosmos/base/v1beta1/coin.proto";
Expand Down Expand Up @@ -42,7 +43,7 @@ message QueryRewardsAuction {
message QueryRewardsAuctionResponse {
uint32 id = 1;
// highest bidder
string bidder = 2;
string bidder = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
cosmos.base.v1beta1.Coin bid = 3 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin rewards = 4 [(gogoproto.nullable) = false];
google.protobuf.Timestamp ends_at = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
Expand Down
70 changes: 34 additions & 36 deletions x/auction/auction.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/auction/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func TestGenesis(t *testing.T) {
{4, auction.Rewards{newCoin(412313), randTime()}},
}
gs.RewardsBids = []auction.BidKV{
{1, auction.Bid{accs.Alice, sdkmath.NewInt(153252)}},
{2, auction.Bid{accs.Alice, sdkmath.NewInt(8521)}},
{1, auction.Bid{accs.Alice.String(), sdkmath.NewInt(153252)}},
{2, auction.Bid{accs.Alice.String(), sdkmath.NewInt(8521)}},
}
check(gs)
}
2 changes: 1 addition & 1 deletion x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (q Querier) RewardsAuction(goCtx context.Context, msg *auction.QueryRewards
bid, id := q.Keeper(&ctx).getRewardsBid(msg.Id)
r := &auction.QueryRewardsAuctionResponse{Id: id}
if bid != nil {
r.Bidder = sdk.AccAddress(bid.Bidder).String()
r.Bidder = bid.Bidder

Check warning on line 40 in x/auction/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/grpc_query.go#L40

Added line #L40 was not covered by tests
r.Bid = coin.UmeeInt(bid.Amount)
}
rewards, _ := q.Keeper(&ctx).getRewardsAuction(msg.Id)
Expand Down
21 changes: 13 additions & 8 deletions x/auction/keeper/rewards.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"bytes"
"errors"
"fmt"
"strconv"
Expand Down Expand Up @@ -30,7 +29,11 @@ func (k Keeper) FinalizeRewardsAuction() error {
newCoins := k.bank.GetAllBalances(*k.ctx, k.accs.RewardsCollect)
bid, _ := k.getRewardsBid(id)
if bid != nil && len(bid.Bidder) != 0 {
err := k.sendCoins(k.accs.RewardsCollect, bid.Bidder, a.Rewards)
bidderAccAddr, err := sdk.AccAddressFromBech32(bid.Bidder)
if err != nil {
return err

Check warning on line 34 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L32-L34

Added lines #L32 - L34 were not covered by tests
}
err = k.sendCoins(k.accs.RewardsCollect, bidderAccAddr, a.Rewards)

Check warning on line 36 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L36

Added line #L36 was not covered by tests
if err != nil {
return fmt.Errorf("can't send coins to finalize the auction [%w]", err)
}
Expand Down Expand Up @@ -87,9 +90,13 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error {
return err
}
} else {
if !bytes.Equal(sender, lastBid.Bidder) {
bidderAccAddr, err := sdk.AccAddressFromBech32(lastBid.Bidder)
if err != nil {

Check warning on line 94 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L93-L94

Added lines #L93 - L94 were not covered by tests
return err
}
if msg.Sender == lastBid.Bidder {
returned := coin.UmeeInt(lastBid.Amount)
if err = k.sendFromModule(lastBid.Bidder, returned); err != nil {
if err = k.sendFromModule(bidderAccAddr, returned); err != nil {
return err

Check warning on line 100 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L97-L100

Added lines #L97 - L100 were not covered by tests
}
if err = k.sendToModule(sender, msg.Amount); err != nil {
Expand All @@ -103,7 +110,7 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error {
}
}

bid := auction.Bid{Bidder: sender, Amount: msg.Amount.Amount}
bid := auction.Bid{Bidder: msg.Sender, Amount: msg.Amount.Amount}

Check warning on line 113 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L113

Added line #L113 was not covered by tests
return store.SetValue(k.store, key, &bid, keyMsg)
}

Expand All @@ -117,8 +124,7 @@ func (k Keeper) getRewardsBid(id uint32) (*auction.Bid, uint32) {
}

func (k Keeper) getAllRewardsBids() ([]auction.BidKV, error) {
elems, err := store.LoadAllKV[*store.Uint32, store.Uint32, *auction.Bid](
k.store, keyPrefixRewardsBid)
elems, err := store.LoadAllKV[*store.Uint32, store.Uint32, *auction.Bid](k.store, keyPrefixRewardsBid)
if err != nil {
return nil, err
}
Expand All @@ -128,7 +134,6 @@ func (k Keeper) getAllRewardsBids() ([]auction.BidKV, error) {
bids[i].Bid = elems[i].Val
}
return bids, nil

}

func (k Keeper) storeAllRewardsBids(elems []auction.BidKV) error {
Expand Down
19 changes: 0 additions & 19 deletions x/auction/module/genesis.go

This file was deleted.

67 changes: 35 additions & 32 deletions x/auction/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f7b3f07

Please sign in to comment.