Skip to content

Commit

Permalink
Merge pull request #115 from onomyprotocol/dong/auction-querry-bids-b…
Browse files Browse the repository at this point in the history
…y-addr

add auction query bids by address
  • Loading branch information
DongLieu authored Dec 19, 2024
2 parents b7c5af9 + b062f46 commit a25c97c
Show file tree
Hide file tree
Showing 5 changed files with 578 additions and 38 deletions.
17 changes: 16 additions & 1 deletion proto/reserve/auction/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ service Query {
rpc QueryAllBidderBids(QueryAllBidderBidsRequest) returns (QueryAllBidderBidsResponse){
option (google.api.http).get = "/reserve/auction/bids/{bidder}";
}

rpc QueryAllBidsByAddress(QueryAllBidsByAddressRequest) returns (QueryAllBidsByAddressResponse){
option (google.api.http).get = "/reserve/auction/bids";
}

}


Expand Down Expand Up @@ -69,4 +74,14 @@ message QueryAllBidderBidsResponse {
// params holds all the parameters of this module.
repeated Bid Bids = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}
}

message QueryAllBidsByAddressRequest {
string bidder = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

message QueryAllBidsByAddressResponse {
// params holds all the parameters of this module.
repeated Bid Bids = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}
23 changes: 23 additions & 0 deletions x/auction/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func GetQueryCmd() *cobra.Command {
cmd.AddCommand(CmdParams())
cmd.AddCommand(CmdQueryAllAuctions())
cmd.AddCommand(CmdQueryAllBids())
cmd.AddCommand(CmdQueryAllBidsByAddress())
return cmd
}

Expand Down Expand Up @@ -91,3 +92,25 @@ func CmdQueryAllBids() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func CmdQueryAllBidsByAddress() *cobra.Command {
cmd := &cobra.Command{
Use: "all-bids-by-address [address]",
Short: "show all bids by address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.QueryAllBidsByAddress(context.Background(), &types.QueryAllBidsByAddressRequest{Bidder: args[0]})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
29 changes: 29 additions & 0 deletions x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,32 @@ func (k Querier) QueryAllBidderBids(ctx context.Context, req *types.QueryAllBidd
Bids: bidsByAddress.Bids,
}, err
}

func (k Querier) QueryAllBidsByAddress(ctx context.Context, req *types.QueryAllBidsByAddressRequest) (*types.QueryAllBidsByAddressResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

bidderAddr, err := k.k.authKeeper.AddressCodec().StringToBytes(req.Bidder)
if err != nil {
return nil, err
}

var Bids []types.Bid
err = k.k.Auctions.Walk(ctx, nil, func(key uint64, value types.Auction) (stop bool, err error) {
bidsByAddress, err := k.k.BidByAddress.Get(ctx, collections.Join(key, sdk.AccAddress(bidderAddr)))
if err != nil {
return true, err
}

Bids = append(Bids, bidsByAddress.Bids...)
return false, nil
})
if err != nil {
return nil, err
}

return &types.QueryAllBidsByAddressResponse{
Bids: Bids,
}, nil
}
Loading

0 comments on commit a25c97c

Please sign in to comment.