Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli(auction): fix query all bids flow auction id #114

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading