From ff369fe28af6f77fb4b9d2eac77eaf7cdfb7ca4c Mon Sep 17 00:00:00 2001 From: Arash <23505281+adshmh@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:46:34 -0500 Subject: [PATCH] [Application] Support filtering apps by delegatee gateway address (#957) ## Summary Support querying applications based on the delegated gateway address: - Add a new field to the `QueryAllApplicationsRequest` type. - Update the application keeper to process the query request based on the updated struct. - Add unit tests to cover the new functionality. Note: #888 adds a similar functionality by allowing access to delegating apps directly from a gateway struct. This PR allows querying apps directly for a specific gateway delegation. Likely both PRs are needed in the long term. ## Issue This is needed ot support integration with PATH. More specifically, it allows PATH to get the list of all applications which delegate to a specific gateway address: https://github.com/buildwithgrove/path/blob/8533ee8b6dae4dcc5d4615bdd1b58d6229ef85a7/protocol/shannon/gateway_mode.go#L25-L26 ## Type of change Select one or more from the following: - [x] New feature, functionality or library - [ ] Consensus breaking; add the `consensus-breaking` label if so. See #791 for details - [ ] Bug fix - [ ] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing - [x] **Unit Tests**: `make go_develop_and_test` - [ ] **LocalNet E2E Tests**: `make test_e2e` - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. ## Sanity Checklist - [x] I have tested my changes using the available tooling - [x] I have commented my code - [x] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable --------- Co-authored-by: Redouane Lakrache --- api/poktroll/application/query.pulsar.go | 203 ++++++++++++------ proto/poktroll/application/query.proto | 3 + x/application/keeper/application_test.go | 20 +- x/application/keeper/query_application.go | 11 + .../keeper/query_application_test.go | 48 +++++ x/application/types/errors.go | 33 +-- x/application/types/query.pb.go | 125 +++++++---- x/application/types/query_validation.go | 20 ++ 8 files changed, 346 insertions(+), 117 deletions(-) create mode 100644 x/application/types/query_validation.go diff --git a/api/poktroll/application/query.pulsar.go b/api/poktroll/application/query.pulsar.go index 5629ec0f0..5349bbc49 100644 --- a/api/poktroll/application/query.pulsar.go +++ b/api/poktroll/application/query.pulsar.go @@ -1664,14 +1664,16 @@ func (x *fastReflection_QueryGetApplicationResponse) ProtoMethods() *protoiface. } var ( - md_QueryAllApplicationsRequest protoreflect.MessageDescriptor - fd_QueryAllApplicationsRequest_pagination protoreflect.FieldDescriptor + md_QueryAllApplicationsRequest protoreflect.MessageDescriptor + fd_QueryAllApplicationsRequest_pagination protoreflect.FieldDescriptor + fd_QueryAllApplicationsRequest_delegatee_gateway_address protoreflect.FieldDescriptor ) func init() { file_poktroll_application_query_proto_init() md_QueryAllApplicationsRequest = File_poktroll_application_query_proto.Messages().ByName("QueryAllApplicationsRequest") fd_QueryAllApplicationsRequest_pagination = md_QueryAllApplicationsRequest.Fields().ByName("pagination") + fd_QueryAllApplicationsRequest_delegatee_gateway_address = md_QueryAllApplicationsRequest.Fields().ByName("delegatee_gateway_address") } var _ protoreflect.Message = (*fastReflection_QueryAllApplicationsRequest)(nil) @@ -1745,6 +1747,12 @@ func (x *fastReflection_QueryAllApplicationsRequest) Range(f func(protoreflect.F return } } + if x.DelegateeGatewayAddress != "" { + value := protoreflect.ValueOfString(x.DelegateeGatewayAddress) + if !f(fd_QueryAllApplicationsRequest_delegatee_gateway_address, value) { + return + } + } } // Has reports whether a field is populated. @@ -1762,6 +1770,8 @@ func (x *fastReflection_QueryAllApplicationsRequest) Has(fd protoreflect.FieldDe switch fd.FullName() { case "poktroll.application.QueryAllApplicationsRequest.pagination": return x.Pagination != nil + case "poktroll.application.QueryAllApplicationsRequest.delegatee_gateway_address": + return x.DelegateeGatewayAddress != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.application.QueryAllApplicationsRequest")) @@ -1780,6 +1790,8 @@ func (x *fastReflection_QueryAllApplicationsRequest) Clear(fd protoreflect.Field switch fd.FullName() { case "poktroll.application.QueryAllApplicationsRequest.pagination": x.Pagination = nil + case "poktroll.application.QueryAllApplicationsRequest.delegatee_gateway_address": + x.DelegateeGatewayAddress = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.application.QueryAllApplicationsRequest")) @@ -1799,6 +1811,9 @@ func (x *fastReflection_QueryAllApplicationsRequest) Get(descriptor protoreflect case "poktroll.application.QueryAllApplicationsRequest.pagination": value := x.Pagination return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "poktroll.application.QueryAllApplicationsRequest.delegatee_gateway_address": + value := x.DelegateeGatewayAddress + return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.application.QueryAllApplicationsRequest")) @@ -1821,6 +1836,8 @@ func (x *fastReflection_QueryAllApplicationsRequest) Set(fd protoreflect.FieldDe switch fd.FullName() { case "poktroll.application.QueryAllApplicationsRequest.pagination": x.Pagination = value.Message().Interface().(*v1beta1.PageRequest) + case "poktroll.application.QueryAllApplicationsRequest.delegatee_gateway_address": + x.DelegateeGatewayAddress = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.application.QueryAllApplicationsRequest")) @@ -1846,6 +1863,8 @@ func (x *fastReflection_QueryAllApplicationsRequest) Mutable(fd protoreflect.Fie x.Pagination = new(v1beta1.PageRequest) } return protoreflect.ValueOfMessage(x.Pagination.ProtoReflect()) + case "poktroll.application.QueryAllApplicationsRequest.delegatee_gateway_address": + panic(fmt.Errorf("field delegatee_gateway_address of message poktroll.application.QueryAllApplicationsRequest is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.application.QueryAllApplicationsRequest")) @@ -1862,6 +1881,8 @@ func (x *fastReflection_QueryAllApplicationsRequest) NewField(fd protoreflect.Fi case "poktroll.application.QueryAllApplicationsRequest.pagination": m := new(v1beta1.PageRequest) return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "poktroll.application.QueryAllApplicationsRequest.delegatee_gateway_address": + return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.application.QueryAllApplicationsRequest")) @@ -1935,6 +1956,10 @@ func (x *fastReflection_QueryAllApplicationsRequest) ProtoMethods() *protoiface. l = options.Size(x.Pagination) n += 1 + l + runtime.Sov(uint64(l)) } + l = len(x.DelegateeGatewayAddress) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -1964,6 +1989,13 @@ func (x *fastReflection_QueryAllApplicationsRequest) ProtoMethods() *protoiface. i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.DelegateeGatewayAddress) > 0 { + i -= len(x.DelegateeGatewayAddress) + copy(dAtA[i:], x.DelegateeGatewayAddress) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DelegateeGatewayAddress))) + i-- + dAtA[i] = 0x12 + } if x.Pagination != nil { encoded, err := options.Marshal(x.Pagination) if err != nil { @@ -2063,6 +2095,38 @@ func (x *fastReflection_QueryAllApplicationsRequest) ProtoMethods() *protoiface. return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DelegateeGatewayAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.DelegateeGatewayAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -2823,7 +2887,8 @@ type QueryAllApplicationsRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Pagination *v1beta1.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` + Pagination *v1beta1.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` + DelegateeGatewayAddress string `protobuf:"bytes,2,opt,name=delegatee_gateway_address,json=delegateeGatewayAddress,proto3" json:"delegatee_gateway_address,omitempty"` } func (x *QueryAllApplicationsRequest) Reset() { @@ -2853,6 +2918,13 @@ func (x *QueryAllApplicationsRequest) GetPagination() *v1beta1.PageRequest { return nil } +func (x *QueryAllApplicationsRequest) GetDelegateeGatewayAddress() string { + if x != nil { + return x.DelegateeGatewayAddress + } + return "" +} + type QueryAllApplicationsResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2933,70 +3005,73 @@ var file_poktroll_application_query_proto_rawDesc = []byte{ 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x0b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x22, 0x65, 0x0a, 0x1b, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x46, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, - 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, - 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x0a, 0x70, 0x61, 0x67, - 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xb4, 0x01, 0x0a, 0x1c, 0x51, 0x75, 0x65, 0x72, - 0x79, 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0c, 0x61, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, - 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x0c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x47, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, - 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x84, - 0x04, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x90, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, - 0x61, 0x6d, 0x73, 0x12, 0x28, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, - 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, - 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, - 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x31, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2b, - 0x12, 0x29, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, - 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0xb4, 0x01, 0x0a, 0x0b, - 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x30, 0x2e, 0x70, 0x6f, + 0x22, 0xa1, 0x01, 0x0a, 0x1b, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x46, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, + 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, + 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x0a, 0x70, 0x61, + 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3a, 0x0a, 0x19, 0x64, 0x65, 0x6c, 0x65, + 0x67, 0x61, 0x74, 0x65, 0x65, 0x5f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x61, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x17, 0x64, 0x65, 0x6c, + 0x65, 0x67, 0x61, 0x74, 0x65, 0x65, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x22, 0xb4, 0x01, 0x0a, 0x1c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, + 0x6c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x31, 0x2e, - 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, - 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x40, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x3a, 0x12, 0x38, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x2d, - 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, - 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x61, 0x70, 0x70, - 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x7b, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x7d, 0x12, 0xb0, 0x01, 0x0a, 0x0f, 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x31, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, - 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, - 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x32, 0x2e, 0x70, 0x6f, 0x6b, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x36, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x30, 0x12, 0x2e, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, + 0x6f, 0x6e, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x04, + 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x0c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x12, 0x47, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x62, 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x52, + 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x84, 0x04, 0x0a, 0x05, + 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x90, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, + 0x12, 0x28, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, + 0x61, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x31, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2b, 0x12, 0x29, 0x2f, + 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x2f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0xb4, 0x01, 0x0a, 0x0b, 0x41, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x30, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, + 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, + 0x51, 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x31, 0x2e, 0x70, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x3a, 0x12, 0x38, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0xc2, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x18, 0x63, 0x6f, - 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x25, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, - 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, - 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x41, - 0x58, 0xaa, 0x02, 0x14, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x41, 0x70, 0x70, - 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x14, 0x50, 0x6f, 0x6b, 0x74, 0x72, - 0x6f, 0x6c, 0x6c, 0x5c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xe2, - 0x02, 0x20, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x41, 0x70, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0xea, 0x02, 0x15, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x41, - 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x7b, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x7d, 0x12, + 0xb0, 0x01, 0x0a, 0x0f, 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x12, 0x31, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, + 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x32, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, + 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, + 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x36, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x30, 0x12, 0x2e, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, + 0x6b, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, + 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x42, 0xc2, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x18, 0x63, 0x6f, 0x6d, 0x2e, 0x70, + 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x25, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x41, 0x58, 0xaa, 0x02, + 0x14, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x14, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, + 0x5c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x20, 0x50, + 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, + 0x02, 0x15, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x41, 0x70, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/poktroll/application/query.proto b/proto/poktroll/application/query.proto index 1625c6658..22f7b746a 100644 --- a/proto/poktroll/application/query.proto +++ b/proto/poktroll/application/query.proto @@ -53,6 +53,9 @@ message QueryGetApplicationResponse { message QueryAllApplicationsRequest { cosmos.base.query.v1beta1.PageRequest pagination = 1; + // TODO_MAINNET(@adshmh): rename this field to `gateway_address_delegated_to` + // delegatee_gateway_address, if specified, filters the application list to only include those with delegation to the specified gateway address. + string delegatee_gateway_address = 2; } message QueryAllApplicationsResponse { diff --git a/x/application/keeper/application_test.go b/x/application/keeper/application_test.go index 77ff951d0..157c68db4 100644 --- a/x/application/keeper/application_test.go +++ b/x/application/keeper/application_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "context" + "slices" "strconv" "testing" @@ -18,18 +19,35 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize -func createNApplications(keeper keeper.Keeper, ctx context.Context, n int) []types.Application { +// testAppModifier represents any function that can be used to modify an application being instantiated for testing purposes. +type testAppModifier func(app *types.Application) + +func createNApplications(keeper keeper.Keeper, ctx context.Context, n int, testAppModifiers ...testAppModifier) []types.Application { apps := make([]types.Application, n) for i := range apps { apps[i].Address = strconv.Itoa(i) // Setting pending undelegations since nullify.Fill() does not seem to do it. apps[i].PendingUndelegations = make(map[uint64]types.UndelegatingGatewayList) + for _, modifier := range testAppModifiers { + modifier(&apps[i]) + } + keeper.SetApplication(ctx, apps[i]) } return apps } +// testAppModifierDelegateeAddr adds the supplied gateway address to the application's delegatee list if the application's address matches +// the supplied address list. +func withAppDelegateeGatewayAddr(delegateeGatewayAddr string, appsWithDelegationAddr []string) testAppModifier { + return func(app *types.Application) { + if slices.Contains(appsWithDelegationAddr, app.Address) { + app.DelegateeGatewayAddresses = append(app.DelegateeGatewayAddresses, delegateeGatewayAddr) + } + } +} + func init() { cmd.InitSDKConfig() } diff --git a/x/application/keeper/query_application.go b/x/application/keeper/query_application.go index 4ec5e8ac6..5d39b21ca 100644 --- a/x/application/keeper/query_application.go +++ b/x/application/keeper/query_application.go @@ -3,6 +3,7 @@ package keeper import ( "context" "fmt" + "slices" "cosmossdk.io/store/prefix" "github.com/cosmos/cosmos-sdk/runtime" @@ -20,6 +21,10 @@ func (k Keeper) AllApplications(ctx context.Context, req *types.QueryAllApplicat return nil, status.Error(codes.InvalidArgument, "invalid request") } + if err := req.ValidateBasic(); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + var apps []types.Application store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) @@ -32,6 +37,12 @@ func (k Keeper) AllApplications(ctx context.Context, req *types.QueryAllApplicat return status.Error(codes.Internal, err.Error()) } + // Filter out the application if the request specifies a delegatee gateway address as a contraint and the application + // does not delegate to the specifies gateway address. + if req.DelegateeGatewayAddress != "" && !slices.Contains(application.DelegateeGatewayAddresses, req.DelegateeGatewayAddress) { + return nil + } + // Ensure that the PendingUndelegations is an empty map and not nil when // unmarshalling an app that has no pending undelegations. if application.PendingUndelegations == nil { diff --git a/x/application/keeper/query_application_test.go b/x/application/keeper/query_application_test.go index e5d3d0fed..79464a0d9 100644 --- a/x/application/keeper/query_application_test.go +++ b/x/application/keeper/query_application_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "slices" "strconv" "testing" @@ -11,6 +12,7 @@ import ( keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/nullify" + "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/types" ) @@ -122,3 +124,49 @@ func TestApplicationQueryPaginated(t *testing.T) { require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } + +func TestAllApplicationsQuery_WithDelegateeGatewayAddressConstraint(t *testing.T) { + keeper, ctx := keepertest.ApplicationKeeper(t) + gatewayAddr1 := sample.AccAddress() + appsWithDelegationAddr := []string{"1", "2"} + apps := createNApplications(keeper, ctx, 5, withAppDelegateeGatewayAddr(gatewayAddr1, appsWithDelegationAddr)) + + requestBuilder := func(gatewayAddr string) *types.QueryAllApplicationsRequest { + return &types.QueryAllApplicationsRequest{ + DelegateeGatewayAddress: gatewayAddr, + } + } + + t.Run("QueryAppsWithDelegatee", func(t *testing.T) { + resp, err := keeper.AllApplications(ctx, requestBuilder(gatewayAddr1)) + require.NoError(t, err) + + var expectedApps []types.Application + for _, app := range apps { + if slices.Contains(appsWithDelegationAddr, app.Address) { + expectedApps = append(expectedApps, app) + } + } + + require.ElementsMatch(t, + nullify.Fill(expectedApps), + nullify.Fill(resp.Applications), + ) + }) + + t.Run("QueryAppsWithNoDelegationConstraint", func(t *testing.T) { + resp, err := keeper.AllApplications(ctx, &types.QueryAllApplicationsRequest{}) + require.NoError(t, err) + + require.ElementsMatch(t, + nullify.Fill(apps), + nullify.Fill(resp.Applications), + ) + }) + + t.Run("QueryAppsWithInvalidGatewayAddr", func(t *testing.T) { + addrInvalid := "invalid-address" + _, err := keeper.AllApplications(ctx, requestBuilder(addrInvalid)) + require.ErrorContains(t, err, types.ErrQueryAppsInvalidGatewayAddress.Error()) + }) +} diff --git a/x/application/types/errors.go b/x/application/types/errors.go index f2755aebe..4e8d7fb32 100644 --- a/x/application/types/errors.go +++ b/x/application/types/errors.go @@ -6,20 +6,21 @@ import sdkerrors "cosmossdk.io/errors" // x/application module sentinel errors var ( - ErrAppInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") - ErrAppInvalidStake = sdkerrors.Register(ModuleName, 1101, "invalid application stake") - ErrAppInvalidAddress = sdkerrors.Register(ModuleName, 1102, "invalid application address") - ErrAppUnauthorized = sdkerrors.Register(ModuleName, 1103, "unauthorized application signer") - ErrAppNotFound = sdkerrors.Register(ModuleName, 1104, "application not found") - ErrAppInvalidServiceConfigs = sdkerrors.Register(ModuleName, 1106, "invalid service configs") - ErrAppGatewayNotFound = sdkerrors.Register(ModuleName, 1107, "gateway not found") - ErrAppInvalidGatewayAddress = sdkerrors.Register(ModuleName, 1108, "invalid gateway address") - ErrAppAlreadyDelegated = sdkerrors.Register(ModuleName, 1109, "application already delegated to gateway") - ErrAppMaxDelegatedGateways = sdkerrors.Register(ModuleName, 1110, "maximum number of delegated gateways reached") - ErrAppNotDelegated = sdkerrors.Register(ModuleName, 1111, "application not delegated to gateway") - ErrAppIsUnstaking = sdkerrors.Register(ModuleName, 1112, "application is in unbonding period") - ErrAppDuplicateAddress = sdkerrors.Register(ModuleName, 1113, "duplicate application address") - ErrAppHasPendingTransfer = sdkerrors.Register(ModuleName, 1114, "application is in transfer period") - ErrAppParamInvalid = sdkerrors.Register(ModuleName, 1115, "the provided param is invalid") - ErrAppEmitEvent = sdkerrors.Register(ModuleName, 1116, "unable to emit on-chain event") + ErrAppInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrAppInvalidStake = sdkerrors.Register(ModuleName, 1101, "invalid application stake") + ErrAppInvalidAddress = sdkerrors.Register(ModuleName, 1102, "invalid application address") + ErrAppUnauthorized = sdkerrors.Register(ModuleName, 1103, "unauthorized application signer") + ErrAppNotFound = sdkerrors.Register(ModuleName, 1104, "application not found") + ErrAppInvalidServiceConfigs = sdkerrors.Register(ModuleName, 1106, "invalid service configs") + ErrAppGatewayNotFound = sdkerrors.Register(ModuleName, 1107, "gateway not found") + ErrAppInvalidGatewayAddress = sdkerrors.Register(ModuleName, 1108, "invalid gateway address") + ErrAppAlreadyDelegated = sdkerrors.Register(ModuleName, 1109, "application already delegated to gateway") + ErrAppMaxDelegatedGateways = sdkerrors.Register(ModuleName, 1110, "maximum number of delegated gateways reached") + ErrAppNotDelegated = sdkerrors.Register(ModuleName, 1111, "application not delegated to gateway") + ErrAppIsUnstaking = sdkerrors.Register(ModuleName, 1112, "application is in unbonding period") + ErrAppDuplicateAddress = sdkerrors.Register(ModuleName, 1113, "duplicate application address") + ErrAppHasPendingTransfer = sdkerrors.Register(ModuleName, 1114, "application is in transfer period") + ErrAppParamInvalid = sdkerrors.Register(ModuleName, 1115, "the provided param is invalid") + ErrAppEmitEvent = sdkerrors.Register(ModuleName, 1116, "unable to emit on-chain event") + ErrQueryAppsInvalidGatewayAddress = sdkerrors.Register(ModuleName, 1117, "invalid gateway address querying for apps with delegatee gateway address") ) diff --git a/x/application/types/query.pb.go b/x/application/types/query.pb.go index fa797343a..61dddd8e2 100644 --- a/x/application/types/query.pb.go +++ b/x/application/types/query.pb.go @@ -188,7 +188,8 @@ func (m *QueryGetApplicationResponse) GetApplication() Application { } type QueryAllApplicationsRequest struct { - Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` + DelegateeGatewayAddress string `protobuf:"bytes,2,opt,name=delegatee_gateway_address,json=delegateeGatewayAddress,proto3" json:"delegatee_gateway_address,omitempty"` } func (m *QueryAllApplicationsRequest) Reset() { *m = QueryAllApplicationsRequest{} } @@ -227,6 +228,13 @@ func (m *QueryAllApplicationsRequest) GetPagination() *query.PageRequest { return nil } +func (m *QueryAllApplicationsRequest) GetDelegateeGatewayAddress() string { + if m != nil { + return m.DelegateeGatewayAddress + } + return "" +} + type QueryAllApplicationsResponse struct { Applications []Application `protobuf:"bytes,1,rep,name=applications,proto3" json:"applications"` Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` @@ -287,41 +295,43 @@ func init() { func init() { proto.RegisterFile("poktroll/application/query.proto", fileDescriptor_5cf77e4e046ed3a7) } var fileDescriptor_5cf77e4e046ed3a7 = []byte{ - // 538 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x3f, 0x6f, 0xd3, 0x40, - 0x18, 0xc6, 0x73, 0xa5, 0x04, 0xf5, 0x82, 0x84, 0x38, 0x32, 0x54, 0x26, 0x32, 0xad, 0x07, 0x68, - 0x8b, 0xb8, 0x6b, 0x02, 0xaa, 0x10, 0x0b, 0x34, 0x03, 0x15, 0x62, 0x29, 0x1e, 0x18, 0xd8, 0x2e, - 0xe9, 0xc9, 0xb5, 0xea, 0xf8, 0x75, 0xed, 0x0b, 0x50, 0x21, 0x16, 0xc4, 0x07, 0xa8, 0xc4, 0x97, - 0x60, 0xec, 0xd0, 0x0f, 0xd1, 0xb1, 0x12, 0x4b, 0x27, 0x84, 0x12, 0x24, 0xbe, 0x06, 0xf2, 0xdd, - 0x59, 0x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69, 0x9f, - 0x3f, 0x99, 0xd5, 0xfe, 0x4c, 0x8e, 0x10, 0xbe, 0xf5, 0xcf, 0x16, 0x90, 0x69, 0x20, 0xee, 0xcd, - 0xf4, 0x3a, 0xb3, 0x58, 0x0c, 0xfc, 0x86, 0x82, 0x5f, 0x27, 0x74, 0x36, 0xf8, 0x6e, 0x78, 0x32, - 0xf2, 0xd1, 0xe9, 0xc8, 0x47, 0x67, 0x23, 0x1f, 0xfd, 0x1a, 0xf9, 0xe8, 0x70, 0xec, 0xd7, 0x4e, - 0xc7, 0x7e, 0xed, 0x6c, 0xec, 0xd7, 0xde, 0x3d, 0x89, 0x62, 0xb9, 0x3b, 0xec, 0xd1, 0x3e, 0x0c, - 0xfe, 0x73, 0xef, 0xc7, 0x8b, 0x9f, 0xa3, 0x5e, 0x5d, 0x7d, 0x8f, 0x1e, 0xff, 0x0d, 0x00, 0x00, - 0xff, 0xff, 0xab, 0x23, 0x79, 0xa6, 0xa1, 0x05, 0x00, 0x00, + // 574 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x41, 0x6f, 0xd3, 0x3e, + 0x18, 0xc6, 0xeb, 0xfe, 0xf7, 0x2f, 0x9a, 0x8b, 0x84, 0x30, 0x95, 0x18, 0xa1, 0x0a, 0x5b, 0x0e, + 0xb0, 0x0d, 0x61, 0xaf, 0x05, 0x4d, 0x68, 0x17, 0x68, 0x0f, 0x54, 0x88, 0xcb, 0xc8, 0x81, 0x03, + 0x97, 0xc9, 0x6d, 0xad, 0x2c, 0x5a, 0x1a, 0x67, 0x89, 0xcb, 0xa8, 0x10, 0x17, 0xc4, 0x07, 0x98, + 0xc4, 0x27, 0xe0, 0xc6, 0x71, 0x87, 0x7d, 0x88, 0x1d, 0x27, 0x71, 0xd9, 0x09, 0xa1, 0x16, 0x89, + 0xaf, 0x81, 0x62, 0x3b, 0xcc, 0x65, 0xa6, 0x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, 0x4f, 0xf7, 0xc8, 0x8c, 0xff, 0x0b, 0x3a, 0x06, 0xb0, 0x6a, 0x74, 0x02, 0x6d, + 0xcc, 0xa8, 0x66, 0x9d, 0x5e, 0xa7, 0x31, 0x87, 0x43, 0x73, 0x3e, 0x95, 0x9c, 0x5b, 0xe8, 0xf1, + 0x25, 0x38, 0xcd, 0xf5, 0x3b, 0x3d, 0x28, 0xef, 0xd1, 0x11, 0x80, 0xd7, 0xfe, 0x98, 0x02, 0x34, + 0x0b, 0xc4, 0x3e, 0xd5, 0x4e, 0x73, 0x1e, 0x8b, 0x86, 0xdf, 0x94, 0xf0, 0x1b, 0x08, 0xcf, 0x07, + 0xdf, 0xf6, 0x4f, 0xc6, 0x2e, 0x38, 0x1d, 0xbb, 0xe0, 0x6c, 0xec, 0x82, 0xef, 0x63, 0x17, 0x1c, + 0x4e, 0xdc, 0xd2, 0xe9, 0xc4, 0x2d, 0x9d, 0x4d, 0xdc, 0xd2, 0xeb, 0x47, 0x41, 0x28, 0x76, 0x87, + 0x5d, 0xdc, 0xe3, 0x83, 0xbf, 0x9c, 0xfb, 0xf6, 0xe2, 0xb7, 0xac, 0x5b, 0x91, 0x1f, 0xb3, 0x87, + 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x0c, 0x43, 0x1f, 0xbc, 0xde, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -619,6 +629,13 @@ func (m *QueryAllApplicationsRequest) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if len(m.DelegateeGatewayAddress) > 0 { + i -= len(m.DelegateeGatewayAddress) + copy(dAtA[i:], m.DelegateeGatewayAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.DelegateeGatewayAddress))) + i-- + dAtA[i] = 0x12 + } if m.Pagination != nil { { size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) @@ -748,6 +765,10 @@ func (m *QueryAllApplicationsRequest) Size() (n int) { l = m.Pagination.Size() n += 1 + l + sovQuery(uint64(l)) } + l = len(m.DelegateeGatewayAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -1139,6 +1160,38 @@ func (m *QueryAllApplicationsRequest) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegateeGatewayAddress", 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.DelegateeGatewayAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/application/types/query_validation.go b/x/application/types/query_validation.go new file mode 100644 index 000000000..7df32b36e --- /dev/null +++ b/x/application/types/query_validation.go @@ -0,0 +1,20 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// ValidateBasic performs basic (non-state-dependant) validation on a QueryAllApplicationsRequest. +func (query *QueryAllApplicationsRequest) ValidateBasic() error { + delegateeGatewayAddr := query.GetDelegateeGatewayAddress() + if delegateeGatewayAddr == "" { + return nil + } + + // Validate the delegation gateway address if the request specifies it as a constraint. + if _, err := sdk.AccAddressFromBech32(delegateeGatewayAddr); err != nil { + return ErrQueryAppsInvalidGatewayAddress.Wrapf("%q; (%v)", delegateeGatewayAddr, err) + } + + return nil +}