diff --git a/packages/core/src/lib/filter/filter_rpc.ts b/packages/core/src/lib/filter/filter_rpc.ts index cbbf6e1ca8..4bf7345c18 100644 --- a/packages/core/src/lib/filter/filter_rpc.ts +++ b/packages/core/src/lib/filter/filter_rpc.ts @@ -9,7 +9,7 @@ export type ContentFilter = { * FilterRPC represents a message conforming to the Waku Filter protocol */ export class FilterRPC { - public constructor(public proto: proto.FilterRPC) {} + public constructor(public proto: proto.FilterRpc) {} static createRequest( topic: string, @@ -34,7 +34,7 @@ export class FilterRPC { * @returns FilterRPC */ static decode(bytes: Uint8Array): FilterRPC { - const res = proto.FilterRPC.decode(bytes); + const res = proto.FilterRpc.decode(bytes); return new FilterRPC(res); } @@ -43,14 +43,14 @@ export class FilterRPC { * @returns Uint8Array */ encode(): Uint8Array { - return proto.FilterRPC.encode(this.proto); + return proto.FilterRpc.encode(this.proto); } get push(): proto.MessagePush | undefined { return this.proto.push; } - get requestId(): string | undefined { + get requestId(): string { return this.proto.requestId; } } diff --git a/packages/proto/src/lib/filter.proto b/packages/proto/src/lib/filter.proto index df9144023d..e20147e2bd 100644 --- a/packages/proto/src/lib/filter.proto +++ b/packages/proto/src/lib/filter.proto @@ -1,23 +1,26 @@ +// 12/WAKU2-FILTER rfc: https://rfc.vac.dev/spec/12/ +// Protocol identifier: /vac/waku/filter/2.0.0-beta1 + syntax = "proto3"; import "message.proto"; message FilterRequest { - optional bool subscribe = 1; - optional string topic = 2; - repeated ContentFilter content_filters = 3; - message ContentFilter { - optional string content_topic = 1; + string content_topic = 1; } + + bool subscribe = 1; + string topic = 2; + repeated ContentFilter content_filters = 3; } message MessagePush { repeated WakuMessage messages = 1; } -message FilterRPC { - optional string request_id = 1; +message FilterRpc { + string request_id = 1; optional FilterRequest request = 2; optional MessagePush push = 3; } diff --git a/packages/proto/src/lib/filter.ts b/packages/proto/src/lib/filter.ts index 648ff5e629..7e54b9ad7a 100644 --- a/packages/proto/src/lib/filter.ts +++ b/packages/proto/src/lib/filter.ts @@ -9,14 +9,14 @@ import type { Codec } from "protons-runtime"; import type { Uint8ArrayList } from "uint8arraylist"; export interface FilterRequest { - subscribe?: boolean; - topic?: string; + subscribe: boolean; + topic: string; contentFilters: FilterRequest.ContentFilter[]; } export namespace FilterRequest { export interface ContentFilter { - contentTopic?: string; + contentTopic: string; } export namespace ContentFilter { @@ -30,7 +30,7 @@ export namespace FilterRequest { w.fork(); } - if (obj.contentTopic != null) { + if (obj.contentTopic != null && obj.contentTopic !== "") { w.uint32(10); w.string(obj.contentTopic); } @@ -40,7 +40,9 @@ export namespace FilterRequest { } }, (reader, length) => { - const obj: any = {}; + const obj: any = { + contentTopic: "", + }; const end = length == null ? reader.len : reader.pos + length; @@ -84,12 +86,12 @@ export namespace FilterRequest { w.fork(); } - if (obj.subscribe != null) { + if (obj.subscribe != null && obj.subscribe !== false) { w.uint32(8); w.bool(obj.subscribe); } - if (obj.topic != null) { + if (obj.topic != null && obj.topic !== "") { w.uint32(18); w.string(obj.topic); } @@ -107,6 +109,8 @@ export namespace FilterRequest { }, (reader, length) => { const obj: any = { + subscribe: false, + topic: "", contentFilters: [], }; @@ -218,24 +222,24 @@ export namespace MessagePush { }; } -export interface FilterRPC { - requestId?: string; +export interface FilterRpc { + requestId: string; request?: FilterRequest; push?: MessagePush; } -export namespace FilterRPC { - let _codec: Codec; +export namespace FilterRpc { + let _codec: Codec; - export const codec = (): Codec => { + export const codec = (): Codec => { if (_codec == null) { - _codec = message( + _codec = message( (obj, w, opts = {}) => { if (opts.lengthDelimited !== false) { w.fork(); } - if (obj.requestId != null) { + if (obj.requestId != null && obj.requestId !== "") { w.uint32(10); w.string(obj.requestId); } @@ -255,7 +259,9 @@ export namespace FilterRPC { } }, (reader, length) => { - const obj: any = {}; + const obj: any = { + requestId: "", + }; const end = length == null ? reader.len : reader.pos + length; @@ -289,12 +295,12 @@ export namespace FilterRPC { return _codec; }; - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, FilterRPC.codec()); + export const encode = (obj: Partial): Uint8Array => { + return encodeMessage(obj, FilterRpc.codec()); }; - export const decode = (buf: Uint8Array | Uint8ArrayList): FilterRPC => { - return decodeMessage(buf, FilterRPC.codec()); + export const decode = (buf: Uint8Array | Uint8ArrayList): FilterRpc => { + return decodeMessage(buf, FilterRpc.codec()); }; }