diff --git a/CHANGELOG.md b/CHANGELOG.md index 8897ccbb1b..ef215195c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ * (versiondb) [#1379](https://github.com/crypto-org-chain/cronos/pull/1379) Flush versiondb when graceful shutdown, make rocksdb upgrade smooth. * (store) [#1378](https://github.com/crypto-org-chain/cronos/pull/1378) Upgrade rocksdb to `v8.11.3`. * (versiondb) [#1387](https://github.com/crypto-org-chain/cronos/pull/1387) Add dedicated config section for versiondb, prepare for sdk 0.50 integration. -* [#1413](https://github.com/crypto-org-chain/cronos/pull/1413) Add custom keyring implementation for e2ee module. +* (e2ee)[#1413](https://github.com/crypto-org-chain/cronos/pull/1413) Add custom keyring implementation for e2ee module. +* (e2ee)[#1415](https://github.com/crypto-org-chain/cronos/pull/1415) Add batch keys query for e2ee module. ### Bug Fixes diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index fd0103c893..7fee2443f9 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -896,7 +896,6 @@ paths: properties: key: type: string - format: byte description: KeyResponse is the response type for the Query/Key RPC method. default: description: An unexpected error response. @@ -927,6 +926,57 @@ paths: type: string tags: - Query + /e2ee/v1/keys: + post: + summary: Keys queries the encryption keys for a batch of addresses + operationId: Keys + responses: + '200': + description: A successful response. + schema: + type: object + properties: + keys: + type: array + items: + type: string + description: KeysResponse is the response type for the Query/Key RPC method. + default: + description: An unexpected error response. + schema: + type: object + properties: + error: + type: string + code: + type: integer + format: int32 + message: + type: string + details: + type: array + items: + type: object + properties: + type_url: + type: string + value: + type: string + format: byte + parameters: + - name: body + in: body + required: true + schema: + type: object + properties: + addresses: + type: array + items: + type: string + description: KeysRequest is the request type for the Query/Key RPC method. + tags: + - Query /ethermint/evm/v1/account/{address}: get: summary: Account queries an Ethereum account. @@ -45554,8 +45604,23 @@ definitions: properties: key: type: string - format: byte description: KeyResponse is the response type for the Query/Key RPC method. + e2ee.KeysRequest: + type: object + properties: + addresses: + type: array + items: + type: string + description: KeysRequest is the request type for the Query/Key RPC method. + e2ee.KeysResponse: + type: object + properties: + keys: + type: array + items: + type: string + description: KeysResponse is the response type for the Query/Key RPC method. ethermint.evm.v1.ChainConfig: type: object properties: diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index d2b9acaf5d..eba113be43 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -1854,6 +1854,18 @@ def query_e2ee_key(self, address): ) )["key"] + def query_e2ee_keys(self, *addresses): + return json.loads( + self.raw( + "q", + "e2ee", + "keys", + *addresses, + home=self.data_dir, + output="json", + ) + )["keys"] + def register_e2ee_key(self, key, **kwargs): kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE) kwargs.setdefault("gas", DEFAULT_GAS) diff --git a/integration_tests/test_e2ee.py b/integration_tests/test_e2ee.py index 99c1dc6c48..2c1738c7b4 100644 --- a/integration_tests/test_e2ee.py +++ b/integration_tests/test_e2ee.py @@ -7,7 +7,12 @@ def test_encrypt_decrypt(cronos): assert cli.query_e2ee_key(cli.address("validator")) == pubkey0 pubkey1 = cli.keygen(keyring_name="key1") cli.register_e2ee_key(pubkey1, _from="community") - assert cli.query_e2ee_key(cli.address("community")) == pubkey1 + + # query in batch + assert cli.query_e2ee_keys(cli.address("validator"), cli.address("community")) == [ + pubkey0, + pubkey1, + ] # prepare data file to encrypt content = "Hello World!" diff --git a/proto/e2ee/query.proto b/proto/e2ee/query.proto index b1789a1af8..9a8ac9c56b 100644 --- a/proto/e2ee/query.proto +++ b/proto/e2ee/query.proto @@ -11,6 +11,13 @@ service Query { rpc Key(KeyRequest) returns (KeyResponse) { option (google.api.http).get = "/e2ee/v1/key/{address}"; } + // Keys queries the encryption keys for a batch of addresses + rpc Keys(KeysRequest) returns (KeysResponse) { + option (google.api.http) = { + post: "/e2ee/v1/keys" + body: "*" + }; + } } // KeyRequest is the request type for the Query/Key RPC method. @@ -22,3 +29,14 @@ message KeyRequest { message KeyResponse { string key = 1; } + + +// KeysRequest is the request type for the Query/Key RPC method. +message KeysRequest { + repeated string addresses = 1; +} + +// KeysResponse is the response type for the Query/Key RPC method. +message KeysResponse { + repeated string keys = 1; +} diff --git a/x/e2ee/autocli.go b/x/e2ee/autocli.go index 9b9bb4904a..0c429c59fa 100644 --- a/x/e2ee/autocli.go +++ b/x/e2ee/autocli.go @@ -16,6 +16,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Short: "Query an encryption key by address", PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, }, + { + RpcMethod: "Keys", + Use: "keys [addresses] ...", + Short: "Query a batch of encryption key by addresses", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "addresses", Varargs: true}}, + }, }, }, Tx: &autocliv1.ServiceCommandDescriptor{ diff --git a/x/e2ee/client/cli/encrypt.go b/x/e2ee/client/cli/encrypt.go index cd7b071fe2..e6f7318aac 100644 --- a/x/e2ee/client/cli/encrypt.go +++ b/x/e2ee/client/cli/encrypt.go @@ -40,15 +40,16 @@ func EncryptCommand() *cobra.Command { // query encryption key from chain state client := types.NewQueryClient(clientCtx) + rsp, err := client.Keys(clientCtx.CmdContext, &types.KeysRequest{ + Addresses: recs, + }) + if err != nil { + return err + } + recipients := make([]age.Recipient, len(recs)) - for i, rec := range recs { - rsp, err := client.Key(clientCtx.CmdContext, &types.KeyRequest{ - Address: rec, - }) - if err != nil { - return err - } - recipient, err := age.ParseX25519Recipient(rsp.Key) + for i, key := range rsp.Keys { + recipient, err := age.ParseX25519Recipient(key) if err != nil { return err } diff --git a/x/e2ee/keeper/keeper.go b/x/e2ee/keeper/keeper.go index 84ccd5be5b..6c04f96390 100644 --- a/x/e2ee/keeper/keeper.go +++ b/x/e2ee/keeper/keeper.go @@ -85,3 +85,18 @@ func (k Keeper) Key(ctx context.Context, req *types.KeyRequest) (*types.KeyRespo value := sdkCtx.KVStore(k.storeKey).Get(types.KeyPrefix(bz)) return &types.KeyResponse{Key: string(value)}, nil } + +func (k Keeper) Keys(ctx context.Context, requests *types.KeysRequest) (*types.KeysResponse, error) { + store := sdk.UnwrapSDKContext(ctx).KVStore(k.storeKey) + var rsp types.KeysResponse + for _, address := range requests.Addresses { + bz, err := k.addressCodec.StringToBytes(address) + if err != nil { + return nil, err + } + value := store.Get(types.KeyPrefix(bz)) + rsp.Keys = append(rsp.Keys, string(value)) + } + + return &rsp, nil +} diff --git a/x/e2ee/types/query.pb.go b/x/e2ee/types/query.pb.go index 4758e396e5..7a934ff2b5 100644 --- a/x/e2ee/types/query.pb.go +++ b/x/e2ee/types/query.pb.go @@ -118,32 +118,128 @@ func (m *KeyResponse) GetKey() string { return "" } +// KeysRequest is the request type for the Query/Key RPC method. +type KeysRequest struct { + Addresses []string `protobuf:"bytes,1,rep,name=addresses,proto3" json:"addresses,omitempty"` +} + +func (m *KeysRequest) Reset() { *m = KeysRequest{} } +func (m *KeysRequest) String() string { return proto.CompactTextString(m) } +func (*KeysRequest) ProtoMessage() {} +func (*KeysRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_1e8b28e605d00558, []int{2} +} +func (m *KeysRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *KeysRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_KeysRequest.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 *KeysRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_KeysRequest.Merge(m, src) +} +func (m *KeysRequest) XXX_Size() int { + return m.Size() +} +func (m *KeysRequest) XXX_DiscardUnknown() { + xxx_messageInfo_KeysRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_KeysRequest proto.InternalMessageInfo + +func (m *KeysRequest) GetAddresses() []string { + if m != nil { + return m.Addresses + } + return nil +} + +// KeysResponse is the response type for the Query/Key RPC method. +type KeysResponse struct { + Keys []string `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"` +} + +func (m *KeysResponse) Reset() { *m = KeysResponse{} } +func (m *KeysResponse) String() string { return proto.CompactTextString(m) } +func (*KeysResponse) ProtoMessage() {} +func (*KeysResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1e8b28e605d00558, []int{3} +} +func (m *KeysResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *KeysResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_KeysResponse.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 *KeysResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_KeysResponse.Merge(m, src) +} +func (m *KeysResponse) XXX_Size() int { + return m.Size() +} +func (m *KeysResponse) XXX_DiscardUnknown() { + xxx_messageInfo_KeysResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_KeysResponse proto.InternalMessageInfo + +func (m *KeysResponse) GetKeys() []string { + if m != nil { + return m.Keys + } + return nil +} + func init() { proto.RegisterType((*KeyRequest)(nil), "e2ee.KeyRequest") proto.RegisterType((*KeyResponse)(nil), "e2ee.KeyResponse") + proto.RegisterType((*KeysRequest)(nil), "e2ee.KeysRequest") + proto.RegisterType((*KeysResponse)(nil), "e2ee.KeysResponse") } func init() { proto.RegisterFile("e2ee/query.proto", fileDescriptor_1e8b28e605d00558) } var fileDescriptor_1e8b28e605d00558 = []byte{ - // 263 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x48, 0x35, 0x4a, 0x4d, - 0xd5, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x01, 0x89, - 0x48, 0xc9, 0xa4, 0xe7, 0xe7, 0xa7, 0xe7, 0xa4, 0xea, 0x27, 0x16, 0x64, 0xea, 0x27, 0xe6, 0xe5, - 0xe5, 0x97, 0x24, 0x96, 0x64, 0xe6, 0xe7, 0x15, 0x43, 0xd4, 0x28, 0xa9, 0x71, 0x71, 0x79, 0xa7, - 0x56, 0x06, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0x49, 0x70, 0xb1, 0x27, 0xa6, 0xa4, 0x14, - 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xb8, 0x4a, 0xf2, 0x5c, 0xdc, - 0x60, 0x75, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x02, 0x5c, 0xcc, 0xd9, 0xa9, 0x95, 0x50, - 0x45, 0x20, 0xa6, 0x51, 0x30, 0x17, 0x6b, 0x20, 0xc8, 0x6e, 0x21, 0x2f, 0x2e, 0x66, 0xef, 0xd4, - 0x4a, 0x21, 0x01, 0x3d, 0x90, 0xed, 0x7a, 0x08, 0xc3, 0xa5, 0x04, 0x91, 0x44, 0x20, 0xc6, 0x28, - 0xc9, 0x35, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x42, 0x48, 0x4c, 0x1f, 0xec, 0xf8, 0x32, 0x43, 0xfd, - 0xec, 0xd4, 0x4a, 0xfd, 0x6a, 0xa8, 0xa5, 0xb5, 0x4e, 0x3e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, - 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, - 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x94, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, - 0x9f, 0x5c, 0x54, 0x59, 0x50, 0x92, 0xaf, 0x9b, 0x5f, 0x94, 0xae, 0x9b, 0x9c, 0x91, 0x98, 0x99, - 0xa7, 0x9f, 0x5c, 0x94, 0x9f, 0x97, 0x5f, 0xac, 0x5f, 0x66, 0xa4, 0x5f, 0x01, 0x31, 0xb8, 0xa4, - 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x65, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x5c, - 0x7b, 0x0b, 0x3a, 0x2a, 0x01, 0x00, 0x00, + // 324 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xbf, 0x4a, 0x03, 0x41, + 0x10, 0x87, 0xb3, 0x26, 0x2a, 0x19, 0x15, 0xe2, 0x16, 0x72, 0x84, 0xb0, 0xca, 0x16, 0x12, 0x94, + 0xdc, 0xe2, 0xd9, 0x59, 0xda, 0x08, 0xc6, 0xc6, 0x94, 0x76, 0x97, 0xcb, 0x70, 0x39, 0xa2, 0x37, + 0x97, 0xdb, 0x4d, 0x70, 0x11, 0x1b, 0x9f, 0x40, 0xb0, 0xf5, 0x81, 0x2c, 0x03, 0x36, 0x96, 0x92, + 0xf8, 0x20, 0x72, 0xff, 0x48, 0xba, 0xb9, 0x1f, 0xdf, 0x7c, 0x33, 0x73, 0x0b, 0x2d, 0xf4, 0x10, + 0xd5, 0x74, 0x86, 0xa9, 0x75, 0x93, 0x94, 0x0c, 0xf1, 0x46, 0x96, 0xb4, 0x3b, 0x21, 0x51, 0xf8, + 0x88, 0xca, 0x4f, 0x22, 0xe5, 0xc7, 0x31, 0x19, 0xdf, 0x44, 0x14, 0xeb, 0x82, 0x91, 0xa7, 0x00, + 0x7d, 0xb4, 0x03, 0x9c, 0xce, 0x50, 0x1b, 0xee, 0xc0, 0xae, 0x3f, 0x1a, 0xa5, 0xa8, 0xb5, 0xc3, + 0x4e, 0x58, 0xb7, 0x39, 0xa8, 0x3e, 0xe5, 0x31, 0xec, 0xe5, 0x9c, 0x4e, 0x28, 0xd6, 0xc8, 0x5b, + 0x50, 0x9f, 0xa0, 0x2d, 0xa1, 0xac, 0x94, 0xe7, 0x39, 0xa0, 0x2b, 0x53, 0x07, 0x9a, 0x65, 0x2b, + 0x66, 0xae, 0x7a, 0xb7, 0x39, 0x58, 0x07, 0x52, 0xc2, 0x7e, 0x01, 0x97, 0x3a, 0x0e, 0x8d, 0x09, + 0xda, 0x0a, 0xcc, 0x6b, 0xef, 0x93, 0xc1, 0xf6, 0x7d, 0x76, 0x0d, 0xbf, 0x85, 0x7a, 0x1f, 0x2d, + 0x6f, 0xb9, 0xd9, 0x3d, 0xee, 0x7a, 0xdd, 0xf6, 0xe1, 0x46, 0x52, 0x98, 0xa4, 0x78, 0xfb, 0xfe, + 0xfb, 0xd8, 0x72, 0xf8, 0x91, 0xca, 0x7f, 0xc7, 0xfc, 0x42, 0x4d, 0xd0, 0xaa, 0x97, 0x72, 0xf4, + 0x2b, 0xbf, 0x81, 0x46, 0x36, 0x99, 0xaf, 0x5b, 0xab, 0x95, 0xdb, 0x7c, 0x33, 0x2a, 0x75, 0x4e, + 0xae, 0xe3, 0x57, 0xec, 0x4c, 0x1e, 0x6c, 0x1a, 0xf5, 0xf5, 0xdd, 0xd7, 0x52, 0xb0, 0xc5, 0x52, + 0xb0, 0xdf, 0xa5, 0x60, 0xef, 0x2b, 0x51, 0x5b, 0xac, 0x44, 0xed, 0x67, 0x25, 0x6a, 0x0f, 0x5e, + 0x18, 0x99, 0xf1, 0x6c, 0xe8, 0x06, 0xf4, 0xa4, 0x82, 0xd4, 0x26, 0x86, 0x7a, 0x94, 0x86, 0xbd, + 0x60, 0xec, 0x47, 0xb1, 0x0a, 0x52, 0x8a, 0x49, 0xab, 0xb9, 0xa7, 0x9e, 0x0b, 0x9f, 0xb1, 0x09, + 0xea, 0xe1, 0x4e, 0xfe, 0x1a, 0x97, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xdd, 0xbf, 0x49, 0x6b, + 0xc5, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -160,6 +256,8 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Key queries the encryption key of a given address Key(ctx context.Context, in *KeyRequest, opts ...grpc.CallOption) (*KeyResponse, error) + // Keys queries the encryption keys for a batch of addresses + Keys(ctx context.Context, in *KeysRequest, opts ...grpc.CallOption) (*KeysResponse, error) } type queryClient struct { @@ -179,10 +277,21 @@ func (c *queryClient) Key(ctx context.Context, in *KeyRequest, opts ...grpc.Call return out, nil } +func (c *queryClient) Keys(ctx context.Context, in *KeysRequest, opts ...grpc.CallOption) (*KeysResponse, error) { + out := new(KeysResponse) + err := c.cc.Invoke(ctx, "/e2ee.Query/Keys", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Key queries the encryption key of a given address Key(context.Context, *KeyRequest) (*KeyResponse, error) + // Keys queries the encryption keys for a batch of addresses + Keys(context.Context, *KeysRequest) (*KeysResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -192,6 +301,9 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Key(ctx context.Context, req *KeyRequest) (*KeyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Key not implemented") } +func (*UnimplementedQueryServer) Keys(ctx context.Context, req *KeysRequest) (*KeysResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Keys not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -215,6 +327,24 @@ func _Query_Key_Handler(srv interface{}, ctx context.Context, dec func(interface return interceptor(ctx, in, info, handler) } +func _Query_Keys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(KeysRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Keys(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/e2ee.Query/Keys", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Keys(ctx, req.(*KeysRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "e2ee.Query", HandlerType: (*QueryServer)(nil), @@ -223,6 +353,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Key", Handler: _Query_Key_Handler, }, + { + MethodName: "Keys", + Handler: _Query_Keys_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "e2ee/query.proto", @@ -288,6 +422,70 @@ func (m *KeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *KeysRequest) 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 *KeysRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *KeysRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Addresses[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *KeysResponse) 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 *KeysResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *KeysResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Keys) > 0 { + for iNdEx := len(m.Keys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Keys[iNdEx]) + copy(dAtA[i:], m.Keys[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Keys[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -325,6 +523,36 @@ func (m *KeyResponse) Size() (n int) { return n } +func (m *KeysRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Addresses) > 0 { + for _, s := range m.Addresses { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *KeysResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Keys) > 0 { + for _, s := range m.Keys { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -495,6 +723,170 @@ func (m *KeyResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *KeysRequest) 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: KeysRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: KeysRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", 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.Addresses = append(m.Addresses, 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 *KeysResponse) 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: KeysResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: KeysResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Keys", 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.Keys = append(m.Keys, 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 skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/e2ee/types/query.pb.gw.go b/x/e2ee/types/query.pb.gw.go index 23fb826796..7e0fed42c3 100644 --- a/x/e2ee/types/query.pb.gw.go +++ b/x/e2ee/types/query.pb.gw.go @@ -87,6 +87,40 @@ func local_request_Query_Key_0(ctx context.Context, marshaler runtime.Marshaler, } +func request_Query_Keys_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq KeysRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Keys(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Keys_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq KeysRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Keys(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. @@ -116,6 +150,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("POST", pattern_Query_Keys_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_Keys_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_Keys_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -177,13 +234,37 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("POST", pattern_Query_Keys_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_Keys_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_Keys_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } var ( pattern_Query_Key_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"e2ee", "v1", "key", "address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Keys_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"e2ee", "v1", "keys"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Key_0 = runtime.ForwardResponseMessage + + forward_Query_Keys_0 = runtime.ForwardResponseMessage )