From c85b113df74928b9aeb508df4c3f248934b1e781 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Wed, 25 Jan 2023 17:25:46 +1100 Subject: [PATCH] chore: use `this.multicodec` over constant To enable extraction of common functions. --- packages/core/src/lib/filter/index.ts | 10 +++++----- packages/core/src/lib/light_push/index.ts | 4 ++-- packages/core/src/lib/store/index.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/core/src/lib/filter/index.ts b/packages/core/src/lib/filter/index.ts index 31f66e8f5b..341c68b0fc 100644 --- a/packages/core/src/lib/filter/index.ts +++ b/packages/core/src/lib/filter/index.ts @@ -61,7 +61,7 @@ class Filter implements IFilter { this.subscriptions = new Map(); this.decoders = new Map(); this.libp2p - .handle(FilterCodec, this.onRequest.bind(this)) + .handle(this.multicodec, this.onRequest.bind(this)) .catch((e) => log("Failed to register filter protocol", e)); } @@ -264,23 +264,23 @@ class Filter implements IFilter { throw new Error("Failed to get a connection to the peer"); } - return connection.newStream(FilterCodec); + return connection.newStream(this.multicodec); } private async getPeer(peerId?: PeerId): Promise { const res = await selectPeerForProtocol( this.peerStore, - [FilterCodec], + [this.multicodec], peerId ); if (!res) { - throw new Error(`Failed to select peer for ${FilterCodec}`); + throw new Error(`Failed to select peer for ${this.multicodec}`); } return res.peer; } async peers(): Promise { - return getPeersForProtocol(this.peerStore, [FilterCodec]); + return getPeersForProtocol(this.peerStore, [this.multicodec]); } async randomPeer(): Promise { diff --git a/packages/core/src/lib/light_push/index.ts b/packages/core/src/lib/light_push/index.ts index b5fd967511..4e98917b4f 100644 --- a/packages/core/src/lib/light_push/index.ts +++ b/packages/core/src/lib/light_push/index.ts @@ -67,7 +67,7 @@ class LightPush implements ILightPush { if (!connection) throw "Failed to get a connection to the peer"; - const stream = await connection.newStream(LightPushCodec); + const stream = await connection.newStream(this.multicodec); const recipients: PeerId[] = []; @@ -116,7 +116,7 @@ class LightPush implements ILightPush { * peers. */ async peers(): Promise { - return getPeersForProtocol(this.peerStore, [LightPushCodec]); + return getPeersForProtocol(this.peerStore, [this.multicodec]); } /** diff --git a/packages/core/src/lib/store/index.ts b/packages/core/src/lib/store/index.ts index a1f71ce746..9e25aa220b 100644 --- a/packages/core/src/lib/store/index.ts +++ b/packages/core/src/lib/store/index.ts @@ -239,7 +239,7 @@ class Store implements IStore { const res = await selectPeerForProtocol( this.peerStore, - [StoreCodec], + [this.multicodec], options?.peerId ); @@ -269,7 +269,7 @@ class Store implements IStore { * store protocol. Waku may or may not be currently connected to these peers. */ async peers(): Promise { - return getPeersForProtocol(this.peerStore, [StoreCodec]); + return getPeersForProtocol(this.peerStore, [this.multicodec]); } get peerStore(): PeerStore {