diff --git a/README.md b/README.md index 01b2d5640d..c76c48551d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ You can track progress on the [project board](https://github.com/status-im/js-wa |[10/WAKU2](https://rfc.vac.dev/spec/10)|🚧| |[11/WAKU2-RELAY](https://rfc.vac.dev/spec/11)|✔| |[12/WAKU2-FILTER](https://rfc.vac.dev/spec/12)|| -|[13/WAKU2-STORE](https://rfc.vac.dev/spec/13)|🚧| +|[13/WAKU2-STORE](https://rfc.vac.dev/spec/13)|✔ (querying node only)| |[14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14)|✔| |[15/WAKU2-BRIDGE](https://rfc.vac.dev/spec/15)|| |[16/WAKU2-RPC](https://rfc.vac.dev/spec/16)|⛔| diff --git a/nim-waku b/nim-waku index 286482ea32..fb2ea06a4f 160000 --- a/nim-waku +++ b/nim-waku @@ -1 +1 @@ -Subproject commit 286482ea32401952ff01b80ad7cc183cb9336c06 +Subproject commit fb2ea06a4fdfaee91aa081be2592eb79349ed6c2 diff --git a/proto/waku/v2/store.proto b/proto/waku/v2/store.proto index b58dd485ad..f3655274dd 100644 --- a/proto/waku/v2/store.proto +++ b/proto/waku/v2/store.proto @@ -9,19 +9,22 @@ message Index { double received_time = 2; } -enum Direction { - DIRECTION_BACKWARD_UNSPECIFIED = 0; - DIRECTION_FORWARD = 1; -} - message PagingInfo { uint64 page_size = 1; Index cursor = 2; + enum Direction { + DIRECTION_BACKWARD_UNSPECIFIED = 0; + DIRECTION_FORWARD = 1; + } Direction direction = 3; } +message ContentFilter { + string content_topic = 1; +} + message HistoryQuery { - repeated string topics = 2; + repeated ContentFilter content_filters = 2; optional PagingInfo paging_info = 3; optional double start_time = 4; optional double end_time = 5; diff --git a/src/lib/waku_store/history_rpc.ts b/src/lib/waku_store/history_rpc.ts index ff4a8ede4f..b94fb69914 100644 --- a/src/lib/waku_store/history_rpc.ts +++ b/src/lib/waku_store/history_rpc.ts @@ -8,17 +8,27 @@ export class HistoryRPC { public constructor(public proto: proto.HistoryRPC) {} static createQuery( - topics: string[] = [DEFAULT_CONTENT_TOPIC], + contentTopics: string[] = [DEFAULT_CONTENT_TOPIC], cursor?: proto.Index ): HistoryRPC { const pagingInfo = { pageSize: 10, cursor, - direction: proto.Direction.DIRECTION_FORWARD, + direction: proto.PagingInfo_Direction.DIRECTION_FORWARD, }; + + const contentFilters = contentTopics.map((contentTopic) => { + return { contentTopic }; + }); + return new HistoryRPC({ requestId: uuid(), - query: { topics, pagingInfo, startTime: undefined, endTime: undefined }, + query: { + contentFilters, + pagingInfo, + startTime: undefined, + endTime: undefined, + }, response: undefined, }); } diff --git a/src/proto/waku/v2/store.ts b/src/proto/waku/v2/store.ts index 134e4afa23..77692dabea 100644 --- a/src/proto/waku/v2/store.ts +++ b/src/proto/waku/v2/store.ts @@ -5,38 +5,6 @@ import _m0 from 'protobufjs/minimal'; export const protobufPackage = 'waku.v2'; -export enum Direction { - DIRECTION_BACKWARD_UNSPECIFIED = 0, - DIRECTION_FORWARD = 1, - UNRECOGNIZED = -1, -} - -export function directionFromJSON(object: any): Direction { - switch (object) { - case 0: - case 'DIRECTION_BACKWARD_UNSPECIFIED': - return Direction.DIRECTION_BACKWARD_UNSPECIFIED; - case 1: - case 'DIRECTION_FORWARD': - return Direction.DIRECTION_FORWARD; - case -1: - case 'UNRECOGNIZED': - default: - return Direction.UNRECOGNIZED; - } -} - -export function directionToJSON(object: Direction): string { - switch (object) { - case Direction.DIRECTION_BACKWARD_UNSPECIFIED: - return 'DIRECTION_BACKWARD_UNSPECIFIED'; - case Direction.DIRECTION_FORWARD: - return 'DIRECTION_FORWARD'; - default: - return 'UNKNOWN'; - } -} - export interface Index { digest: Uint8Array; receivedTime: number; @@ -45,11 +13,51 @@ export interface Index { export interface PagingInfo { pageSize: number; cursor: Index | undefined; - direction: Direction; + direction: PagingInfo_Direction; +} + +export enum PagingInfo_Direction { + DIRECTION_BACKWARD_UNSPECIFIED = 0, + DIRECTION_FORWARD = 1, + UNRECOGNIZED = -1, +} + +export function pagingInfo_DirectionFromJSON( + object: any +): PagingInfo_Direction { + switch (object) { + case 0: + case 'DIRECTION_BACKWARD_UNSPECIFIED': + return PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED; + case 1: + case 'DIRECTION_FORWARD': + return PagingInfo_Direction.DIRECTION_FORWARD; + case -1: + case 'UNRECOGNIZED': + default: + return PagingInfo_Direction.UNRECOGNIZED; + } +} + +export function pagingInfo_DirectionToJSON( + object: PagingInfo_Direction +): string { + switch (object) { + case PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED: + return 'DIRECTION_BACKWARD_UNSPECIFIED'; + case PagingInfo_Direction.DIRECTION_FORWARD: + return 'DIRECTION_FORWARD'; + default: + return 'UNKNOWN'; + } +} + +export interface ContentFilter { + contentTopic: string; } export interface HistoryQuery { - topics: string[]; + contentFilters: ContentFilter[]; pagingInfo?: PagingInfo | undefined; startTime?: number | undefined; endTime?: number | undefined; @@ -196,7 +204,7 @@ export const PagingInfo = { message.cursor = undefined; } if (object.direction !== undefined && object.direction !== null) { - message.direction = directionFromJSON(object.direction); + message.direction = pagingInfo_DirectionFromJSON(object.direction); } else { message.direction = 0; } @@ -209,7 +217,7 @@ export const PagingInfo = { message.cursor !== undefined && (obj.cursor = message.cursor ? Index.toJSON(message.cursor) : undefined); message.direction !== undefined && - (obj.direction = directionToJSON(message.direction)); + (obj.direction = pagingInfo_DirectionToJSON(message.direction)); return obj; }, @@ -234,15 +242,74 @@ export const PagingInfo = { }, }; -const baseHistoryQuery: object = { topics: '' }; +const baseContentFilter: object = { contentTopic: '' }; + +export const ContentFilter = { + encode( + message: ContentFilter, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.contentTopic !== '') { + writer.uint32(10).string(message.contentTopic); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): ContentFilter { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseContentFilter } as ContentFilter; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.contentTopic = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): ContentFilter { + const message = { ...baseContentFilter } as ContentFilter; + if (object.contentTopic !== undefined && object.contentTopic !== null) { + message.contentTopic = String(object.contentTopic); + } else { + message.contentTopic = ''; + } + return message; + }, + + toJSON(message: ContentFilter): unknown { + const obj: any = {}; + message.contentTopic !== undefined && + (obj.contentTopic = message.contentTopic); + return obj; + }, + + fromPartial(object: DeepPartial): ContentFilter { + const message = { ...baseContentFilter } as ContentFilter; + if (object.contentTopic !== undefined && object.contentTopic !== null) { + message.contentTopic = object.contentTopic; + } else { + message.contentTopic = ''; + } + return message; + }, +}; + +const baseHistoryQuery: object = {}; export const HistoryQuery = { encode( message: HistoryQuery, writer: _m0.Writer = _m0.Writer.create() ): _m0.Writer { - for (const v of message.topics) { - writer.uint32(18).string(v!); + for (const v of message.contentFilters) { + ContentFilter.encode(v!, writer.uint32(18).fork()).ldelim(); } if (message.pagingInfo !== undefined) { PagingInfo.encode(message.pagingInfo, writer.uint32(26).fork()).ldelim(); @@ -260,12 +327,14 @@ export const HistoryQuery = { const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; let end = length === undefined ? reader.len : reader.pos + length; const message = { ...baseHistoryQuery } as HistoryQuery; - message.topics = []; + message.contentFilters = []; while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 2: - message.topics.push(reader.string()); + message.contentFilters.push( + ContentFilter.decode(reader, reader.uint32()) + ); break; case 3: message.pagingInfo = PagingInfo.decode(reader, reader.uint32()); @@ -286,10 +355,10 @@ export const HistoryQuery = { fromJSON(object: any): HistoryQuery { const message = { ...baseHistoryQuery } as HistoryQuery; - message.topics = []; - if (object.topics !== undefined && object.topics !== null) { - for (const e of object.topics) { - message.topics.push(String(e)); + message.contentFilters = []; + if (object.contentFilters !== undefined && object.contentFilters !== null) { + for (const e of object.contentFilters) { + message.contentFilters.push(ContentFilter.fromJSON(e)); } } if (object.pagingInfo !== undefined && object.pagingInfo !== null) { @@ -312,10 +381,12 @@ export const HistoryQuery = { toJSON(message: HistoryQuery): unknown { const obj: any = {}; - if (message.topics) { - obj.topics = message.topics.map((e) => e); + if (message.contentFilters) { + obj.contentFilters = message.contentFilters.map((e) => + e ? ContentFilter.toJSON(e) : undefined + ); } else { - obj.topics = []; + obj.contentFilters = []; } message.pagingInfo !== undefined && (obj.pagingInfo = message.pagingInfo @@ -328,10 +399,10 @@ export const HistoryQuery = { fromPartial(object: DeepPartial): HistoryQuery { const message = { ...baseHistoryQuery } as HistoryQuery; - message.topics = []; - if (object.topics !== undefined && object.topics !== null) { - for (const e of object.topics) { - message.topics.push(e); + message.contentFilters = []; + if (object.contentFilters !== undefined && object.contentFilters !== null) { + for (const e of object.contentFilters) { + message.contentFilters.push(ContentFilter.fromPartial(e)); } } if (object.pagingInfo !== undefined && object.pagingInfo !== null) {