Skip to content

Commit

Permalink
fix query all bids flow auction id
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Dec 19, 2024
1 parent 3e24d9a commit b7a30d1
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 47 deletions.
4 changes: 3 additions & 1 deletion proto/reserve/auction/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ message QueryAllAuctionResponse {
}


message QueryAllBidsRequest {}
message QueryAllBidsRequest {
string auction_id = 1;
}

message QueryAllBidsResponse {
// params holds all the parameters of this module.
Expand Down
8 changes: 4 additions & 4 deletions x/auction/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ func CmdParams() *cobra.Command {

func CmdQueryAllBids() *cobra.Command {
cmd := &cobra.Command{
Use: "all-bids",
Short: "show all bids",
Args: cobra.ExactArgs(0),
Use: "all-bids [auction-id]",
Short: "show all bids of a auction-id",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.QueryAllBids(context.Background(), &types.QueryAllBidsRequest{})
res, err := queryClient.QueryAllBids(context.Background(), &types.QueryAllBidsRequest{AuctionId: args[0]})
if err != nil {
return err
}
Expand Down
16 changes: 10 additions & 6 deletions x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"strconv"

"cosmossdk.io/collections"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -52,15 +53,18 @@ func (k Querier) QueryAllBids(ctx context.Context, req *types.QueryAllBidsReques
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

allBids := []types.Bid{}
auction_id, err := strconv.ParseUint(req.AuctionId, 10, 64)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "auction id canot convert to uint64")
}

err := k.k.Bids.Walk(ctx, nil, func(key uint64, value types.BidQueue) (stop bool, err error) {
allBids = append(allBids, value.Bids...)
return false, nil
})
bids, err := k.k.Bids.Get(ctx, auction_id)
if err != nil {
return nil, err
}

return &types.QueryAllBidsResponse{
Bids: allBids,
Bids: bids.Bids,
}, err
}

Expand Down
124 changes: 88 additions & 36 deletions x/auction/types/query.pb.go

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

18 changes: 18 additions & 0 deletions x/auction/types/query.pb.gw.go

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

0 comments on commit b7a30d1

Please sign in to comment.