From 9cac265fcf092064d9454504ab9d3d00af3217da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=C4=90=C3=B4ng?= Date: Thu, 19 Dec 2024 11:23:42 +0700 Subject: [PATCH 1/3] add query bids by address --- proto/reserve/auction/v1/query.proto | 17 +- x/auction/client/cli/query.go | 23 ++ x/auction/keeper/grpc_query.go | 29 ++ x/auction/types/query.pb.go | 464 ++++++++++++++++++++++++--- x/auction/types/query.pb.gw.go | 83 +++++ 5 files changed, 578 insertions(+), 38 deletions(-) diff --git a/proto/reserve/auction/v1/query.proto b/proto/reserve/auction/v1/query.proto index f4910c8..584a5b1 100644 --- a/proto/reserve/auction/v1/query.proto +++ b/proto/reserve/auction/v1/query.proto @@ -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"; + } + } @@ -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 ]; -} \ No newline at end of file +} + +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 ]; +} diff --git a/x/auction/client/cli/query.go b/x/auction/client/cli/query.go index 2775fed..55cabda 100644 --- a/x/auction/client/cli/query.go +++ b/x/auction/client/cli/query.go @@ -23,6 +23,7 @@ func GetQueryCmd() *cobra.Command { cmd.AddCommand(CmdParams()) cmd.AddCommand(CmdQueryAllAuctions()) cmd.AddCommand(CmdQueryAllBids()) + cmd.AddCommand(CmdQueryAllBidsByAddress()) return cmd } @@ -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 +} diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index 2a75b41..5e87ecc 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -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 + top_auctionID, err := k.k.AuctionIdSeq.Peek(ctx) + if err != nil { + return nil, err + } + for auction_id := uint64(0); auction_id <= top_auctionID; auction_id++ { + bidsByAddress, err := k.k.BidByAddress.Get(ctx, collections.Join(auction_id, sdk.AccAddress(bidderAddr))) + if err != nil { + return nil, err + } + + Bids = append(Bids, bidsByAddress.Bids...) + } + + return &types.QueryAllBidsByAddressResponse{ + Bids: Bids, + }, nil +} diff --git a/x/auction/types/query.pb.go b/x/auction/types/query.pb.go index e6c1aeb..49bc5a5 100644 --- a/x/auction/types/query.pb.go +++ b/x/auction/types/query.pb.go @@ -381,6 +381,95 @@ func (m *QueryAllBidderBidsResponse) GetBids() []Bid { return nil } +type QueryAllBidsByAddressRequest struct { + Bidder string `protobuf:"bytes,1,opt,name=bidder,proto3" json:"bidder,omitempty"` +} + +func (m *QueryAllBidsByAddressRequest) Reset() { *m = QueryAllBidsByAddressRequest{} } +func (m *QueryAllBidsByAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllBidsByAddressRequest) ProtoMessage() {} +func (*QueryAllBidsByAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c0d0f2ec58bf1126, []int{8} +} +func (m *QueryAllBidsByAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBidsByAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBidsByAddressRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllBidsByAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBidsByAddressRequest.Merge(m, src) +} +func (m *QueryAllBidsByAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBidsByAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBidsByAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBidsByAddressRequest proto.InternalMessageInfo + +func (m *QueryAllBidsByAddressRequest) GetBidder() string { + if m != nil { + return m.Bidder + } + return "" +} + +type QueryAllBidsByAddressResponse struct { + // params holds all the parameters of this module. + Bids []Bid `protobuf:"bytes,1,rep,name=Bids,proto3" json:"Bids"` +} + +func (m *QueryAllBidsByAddressResponse) Reset() { *m = QueryAllBidsByAddressResponse{} } +func (m *QueryAllBidsByAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllBidsByAddressResponse) ProtoMessage() {} +func (*QueryAllBidsByAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c0d0f2ec58bf1126, []int{9} +} +func (m *QueryAllBidsByAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBidsByAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBidsByAddressResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllBidsByAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBidsByAddressResponse.Merge(m, src) +} +func (m *QueryAllBidsByAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBidsByAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBidsByAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBidsByAddressResponse proto.InternalMessageInfo + +func (m *QueryAllBidsByAddressResponse) GetBids() []Bid { + if m != nil { + return m.Bids + } + return nil +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "reserve.auction.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "reserve.auction.v1.QueryParamsResponse") @@ -390,48 +479,52 @@ func init() { proto.RegisterType((*QueryAllBidsResponse)(nil), "reserve.auction.v1.QueryAllBidsResponse") proto.RegisterType((*QueryAllBidderBidsRequest)(nil), "reserve.auction.v1.QueryAllBidderBidsRequest") proto.RegisterType((*QueryAllBidderBidsResponse)(nil), "reserve.auction.v1.QueryAllBidderBidsResponse") + proto.RegisterType((*QueryAllBidsByAddressRequest)(nil), "reserve.auction.v1.QueryAllBidsByAddressRequest") + proto.RegisterType((*QueryAllBidsByAddressResponse)(nil), "reserve.auction.v1.QueryAllBidsByAddressResponse") } func init() { proto.RegisterFile("reserve/auction/v1/query.proto", fileDescriptor_c0d0f2ec58bf1126) } var fileDescriptor_c0d0f2ec58bf1126 = []byte{ - // 564 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x41, 0x8b, 0xd3, 0x40, - 0x14, 0xc7, 0x3b, 0x6b, 0x2d, 0x76, 0x56, 0x10, 0xc7, 0x6a, 0xdb, 0xe8, 0xa6, 0x25, 0x87, 0xdd, - 0xb2, 0xb2, 0x99, 0xdd, 0x2a, 0xde, 0x3c, 0x34, 0x37, 0x3d, 0x88, 0xd6, 0x3d, 0x09, 0xb2, 0xa4, - 0xcd, 0x10, 0x03, 0x49, 0x26, 0x9b, 0x49, 0x8b, 0x55, 0x04, 0xf1, 0xec, 0x41, 0xf0, 0xe8, 0x17, - 0xf0, 0x28, 0xe8, 0x87, 0xd8, 0xe3, 0xa2, 0x17, 0x4f, 0x22, 0xad, 0xe0, 0xd7, 0x90, 0xcc, 0xbc, - 0x96, 0xb4, 0x89, 0x76, 0xc1, 0x4b, 0x9b, 0xcc, 0xfb, 0xbf, 0xff, 0xff, 0xf7, 0x98, 0xd7, 0x62, - 0x3d, 0x66, 0x82, 0xc5, 0x63, 0x46, 0xed, 0xd1, 0x30, 0xf1, 0x78, 0x48, 0xc7, 0x07, 0xf4, 0x78, - 0xc4, 0xe2, 0x89, 0x19, 0xc5, 0x3c, 0xe1, 0x84, 0x40, 0xdd, 0x84, 0xba, 0x39, 0x3e, 0xd0, 0x2e, - 0xdb, 0x81, 0x17, 0x72, 0x2a, 0x3f, 0x95, 0x4c, 0xab, 0xb9, 0xdc, 0xe5, 0xf2, 0x91, 0xa6, 0x4f, - 0x70, 0x7a, 0xc3, 0xe5, 0xdc, 0xf5, 0x19, 0xb5, 0x23, 0x8f, 0xda, 0x61, 0xc8, 0x13, 0x3b, 0xb5, - 0x10, 0x50, 0x6d, 0x15, 0x44, 0x47, 0x76, 0x6c, 0x07, 0x73, 0x41, 0xbb, 0x40, 0x30, 0xc7, 0x50, - 0x8a, 0xe6, 0x90, 0x8b, 0x80, 0x8b, 0x23, 0x95, 0xac, 0x5e, 0x54, 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22, 0x15, 0xb7, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x67, 0xc6, 0x03, 0xe2, - 0x92, 0x05, 0x00, 0x00, + // 606 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0xe3, 0xd2, 0x46, 0xe4, 0x15, 0x09, 0x71, 0xa4, 0x24, 0x31, 0x8d, 0x13, 0x79, 0x68, + 0xa3, 0xa2, 0xda, 0x49, 0x40, 0x6c, 0x0c, 0xf1, 0x06, 0x03, 0x2a, 0xa1, 0x12, 0x12, 0x12, 0xaa, + 0x9c, 0xf8, 0x64, 0x2c, 0x39, 0xbe, 0xd4, 0x76, 0x22, 0x02, 0x42, 0x42, 0xcc, 0x0c, 0x48, 0x8c, + 0x7c, 0x01, 0x46, 0x06, 0x3e, 0x44, 0xc7, 0x02, 0x0b, 0x13, 0x42, 0x09, 0x12, 0x5f, 0x03, 0xf9, + 0xee, 0x25, 0x72, 0x62, 0x97, 0x84, 0x76, 0x69, 0xed, 0xbb, 0xff, 0xfb, 0xff, 0x7f, 0xef, 0xf2, + 0xce, 0xa0, 0xf8, 0x34, 0xa0, 0xfe, 0x90, 0xea, 0xe6, 0xa0, 0x1b, 0x3a, 0xcc, 0xd3, 0x87, 0x0d, + 0xfd, 0x78, 0x40, 0xfd, 0x91, 0xd6, 0xf7, 0x59, 0xc8, 0x08, 0xc1, 0x7d, 0x0d, 0xf7, 0xb5, 0x61, + 0x43, 0xbe, 0x66, 0xf6, 0x1c, 0x8f, 0xe9, 0xfc, 0xaf, 0x90, 0xc9, 0x79, 0x9b, 0xd9, 0x8c, 0x3f, + 0xea, 0xd1, 0x13, 0xae, 0x6e, 0xdb, 0x8c, 0xd9, 0x2e, 0xd5, 0xcd, 0xbe, 0xa3, 0x9b, 0x9e, 0xc7, + 0x42, 0x33, 0xb2, 0x08, 0x70, 0xb7, 0x92, 0x12, 0xdd, 0x37, 0x7d, 0xb3, 0x37, 0x15, 0x54, 0x53, + 0x04, 0x53, 0x0c, 0xa1, 0x28, 0x75, 0x59, 0xd0, 0x63, 0xc1, 0x91, 0x48, 0x16, 0x2f, 0x62, 0x4b, + 0xcd, 0x03, 0x79, 0x14, 0xf5, 0x71, 0xc0, 0x1d, 0xdb, 0xf4, 0x78, 0x40, 0x83, 0x50, 0x3d, 0x84, + 0xeb, 0x73, 0xab, 0x41, 0x9f, 0x79, 0x01, 0x25, 0xf7, 0x20, 0x2b, 0x92, 0x8b, 0x52, 0x55, 0xaa, + 0x6d, 0x36, 0x65, 0x2d, 0xd9, 0xb6, 0x26, 0x6a, 0x8c, 0xdc, 0xc9, 0xcf, 0x4a, 0xe6, 0xd3, 0x9f, + 0xcf, 0x7b, 0x52, 0x1b, 0x8b, 0xd4, 0x22, 0xdc, 0xe0, 0xae, 0x2d, 0xd7, 0x6d, 0x09, 0xfd, 0x34, + 0xef, 0x19, 0x14, 0x12, 0x3b, 0x98, 0x69, 0xc0, 0x65, 0x34, 0x8f, 0x52, 0x2f, 0xd5, 0x36, 0x9b, + 0x37, 0xd3, 0x52, 0xb1, 0x2c, 0x1e, 0x3b, 0xab, 0x53, 0xef, 0x60, 0x3b, 0x2d, 0xd7, 0x35, 0x1c, + 0x6b, 0xda, 0x25, 0x29, 0x03, 0xa0, 0xe4, 0xc8, 0xb1, 0x78, 0x4b, 0xb9, 0x76, 0x0e, 0x57, 0xee, + 0x5b, 0xea, 0x43, 0xc8, 0xcf, 0x57, 0x21, 0xd1, 0x5d, 0x58, 0x8f, 0xde, 0x91, 0xa6, 0x90, 0x46, + 0x63, 0x38, 0x56, 0x9c, 0x84, 0xeb, 0x55, 0x17, 0x4a, 0x31, 0x3f, 0x8b, 0xfa, 0x71, 0x96, 0x3a, + 0x64, 0x3b, 0x7c, 0x51, 0x70, 0x18, 0xc5, 0x6f, 0x5f, 0xf6, 0xf3, 0xf8,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, 0x6e, 0xfc, 0x47, 0xc5, 0x4a, 0x67, 0x67, 0x3c, 0x38, 0x19, 0x2b, 0xd2, 0xe9, 0x58, + 0x91, 0x7e, 0x8d, 0x15, 0xe9, 0xfd, 0x44, 0xc9, 0x9c, 0x4e, 0x94, 0xcc, 0x8f, 0x89, 0x92, 0x79, + 0x5a, 0xb7, 0x9d, 0xf0, 0xf9, 0xa0, 0xa3, 0x75, 0x59, 0x4f, 0x67, 0x1e, 0xeb, 0x8d, 0xf8, 0xe7, + 0xbd, 0xcb, 0xdc, 0x99, 0xd1, 0x8b, 0x99, 0x55, 0x38, 0xea, 0xd3, 0xa0, 0x93, 0xe5, 0x8a, 0xdb, + 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x02, 0xf5, 0xa8, 0xed, 0xdb, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -451,6 +544,7 @@ type QueryClient interface { QueryAllAuction(ctx context.Context, in *QueryAllAuctionRequest, opts ...grpc.CallOption) (*QueryAllAuctionResponse, error) QueryAllBids(ctx context.Context, in *QueryAllBidsRequest, opts ...grpc.CallOption) (*QueryAllBidsResponse, error) QueryAllBidderBids(ctx context.Context, in *QueryAllBidderBidsRequest, opts ...grpc.CallOption) (*QueryAllBidderBidsResponse, error) + QueryAllBidsByAddress(ctx context.Context, in *QueryAllBidsByAddressRequest, opts ...grpc.CallOption) (*QueryAllBidsByAddressResponse, error) } type queryClient struct { @@ -497,6 +591,15 @@ func (c *queryClient) QueryAllBidderBids(ctx context.Context, in *QueryAllBidder return out, nil } +func (c *queryClient) QueryAllBidsByAddress(ctx context.Context, in *QueryAllBidsByAddressRequest, opts ...grpc.CallOption) (*QueryAllBidsByAddressResponse, error) { + out := new(QueryAllBidsByAddressResponse) + err := c.cc.Invoke(ctx, "/reserve.auction.v1.Query/QueryAllBidsByAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Parameters queries the parameters of the module. @@ -504,6 +607,7 @@ type QueryServer interface { QueryAllAuction(context.Context, *QueryAllAuctionRequest) (*QueryAllAuctionResponse, error) QueryAllBids(context.Context, *QueryAllBidsRequest) (*QueryAllBidsResponse, error) QueryAllBidderBids(context.Context, *QueryAllBidderBidsRequest) (*QueryAllBidderBidsResponse, error) + QueryAllBidsByAddress(context.Context, *QueryAllBidsByAddressRequest) (*QueryAllBidsByAddressResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -522,6 +626,9 @@ func (*UnimplementedQueryServer) QueryAllBids(ctx context.Context, req *QueryAll func (*UnimplementedQueryServer) QueryAllBidderBids(ctx context.Context, req *QueryAllBidderBidsRequest) (*QueryAllBidderBidsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method QueryAllBidderBids not implemented") } +func (*UnimplementedQueryServer) QueryAllBidsByAddress(ctx context.Context, req *QueryAllBidsByAddressRequest) (*QueryAllBidsByAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryAllBidsByAddress not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -599,6 +706,24 @@ func _Query_QueryAllBidderBids_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _Query_QueryAllBidsByAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllBidsByAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryAllBidsByAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/reserve.auction.v1.Query/QueryAllBidsByAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryAllBidsByAddress(ctx, req.(*QueryAllBidsByAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "reserve.auction.v1.Query", HandlerType: (*QueryServer)(nil), @@ -619,6 +744,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "QueryAllBidderBids", Handler: _Query_QueryAllBidderBids_Handler, }, + { + MethodName: "QueryAllBidsByAddress", + Handler: _Query_QueryAllBidsByAddress_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "reserve/auction/v1/query.proto", @@ -879,6 +1008,73 @@ func (m *QueryAllBidderBidsResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *QueryAllBidsByAddressRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllBidsByAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBidsByAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Bidder) > 0 { + i -= len(m.Bidder) + copy(dAtA[i:], m.Bidder) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Bidder))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllBidsByAddressResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllBidsByAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBidsByAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Bids) > 0 { + for iNdEx := len(m.Bids) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Bids[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -993,6 +1189,34 @@ func (m *QueryAllBidderBidsResponse) Size() (n int) { return n } +func (m *QueryAllBidsByAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Bidder) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllBidsByAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Bids) > 0 { + for _, e := range m.Bids { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1617,6 +1841,172 @@ func (m *QueryAllBidderBidsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryAllBidsByAddressRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllBidsByAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBidsByAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bidder", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bidder = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllBidsByAddressResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllBidsByAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBidsByAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bids", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bids = append(m.Bids, Bid{}) + if err := m.Bids[len(m.Bids)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/auction/types/query.pb.gw.go b/x/auction/types/query.pb.gw.go index a959698..eef435c 100644 --- a/x/auction/types/query.pb.gw.go +++ b/x/auction/types/query.pb.gw.go @@ -177,6 +177,42 @@ func local_request_Query_QueryAllBidderBids_0(ctx context.Context, marshaler run } +var ( + filter_Query_QueryAllBidsByAddress_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_QueryAllBidsByAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBidsByAddressRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryAllBidsByAddress_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.QueryAllBidsByAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryAllBidsByAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBidsByAddressRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryAllBidsByAddress_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.QueryAllBidsByAddress(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -275,6 +311,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_QueryAllBidsByAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryAllBidsByAddress_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAllBidsByAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -396,6 +455,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_QueryAllBidsByAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryAllBidsByAddress_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAllBidsByAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -407,6 +486,8 @@ var ( pattern_Query_QueryAllBids_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"reserve", "auction", "bids"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_QueryAllBidderBids_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"reserve", "auction", "bids", "bidder"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryAllBidsByAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"reserve", "auction", "bids"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -417,4 +498,6 @@ var ( forward_Query_QueryAllBids_0 = runtime.ForwardResponseMessage forward_Query_QueryAllBidderBids_0 = runtime.ForwardResponseMessage + + forward_Query_QueryAllBidsByAddress_0 = runtime.ForwardResponseMessage ) From 6db99df267cafb42c84deb3b858c93b34633e8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=C4=90=C3=B4ng?= Date: Thu, 19 Dec 2024 11:29:15 +0700 Subject: [PATCH 2/3] updates --- x/auction/keeper/grpc_query.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index 5e87ecc..a3a70d4 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -99,18 +99,15 @@ func (k Querier) QueryAllBidsByAddress(ctx context.Context, req *types.QueryAllB } var Bids []types.Bid - top_auctionID, err := k.k.AuctionIdSeq.Peek(ctx) - if err != nil { - return nil, err - } - for auction_id := uint64(0); auction_id <= top_auctionID; auction_id++ { - bidsByAddress, err := k.k.BidByAddress.Get(ctx, collections.Join(auction_id, sdk.AccAddress(bidderAddr))) + 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 nil, err + return true, err } Bids = append(Bids, bidsByAddress.Bids...) - } + return false, nil + }) return &types.QueryAllBidsByAddressResponse{ Bids: Bids, From b062f46bac53d75d0854a4e47c34b5e45f3e58fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=C4=90=C3=B4ng?= Date: Thu, 19 Dec 2024 11:33:48 +0700 Subject: [PATCH 3/3] lint --- x/auction/keeper/grpc_query.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index a3a70d4..b36ecfc 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -99,7 +99,7 @@ func (k Querier) QueryAllBidsByAddress(ctx context.Context, req *types.QueryAllB } var Bids []types.Bid - k.k.Auctions.Walk(ctx, nil, func(key uint64, value types.Auction) (stop bool, err error) { + 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 @@ -108,6 +108,9 @@ func (k Querier) QueryAllBidsByAddress(ctx context.Context, req *types.QueryAllB Bids = append(Bids, bidsByAddress.Bids...) return false, nil }) + if err != nil { + return nil, err + } return &types.QueryAllBidsByAddressResponse{ Bids: Bids,