mirror of
https://github.com/logos-messaging/lab.waku.org.git
synced 2026-01-17 05:03:07 +00:00
28 lines
613 B
TypeScript
28 lines
613 B
TypeScript
import type { Peer } from "@libp2p/interface-peer-store";
|
|
import type { IFilter, ILightPush, IStore } from "@waku/interfaces";
|
|
|
|
export async function handleCatch(
|
|
promise?: Promise<Peer[]>
|
|
): Promise<Peer[] | undefined> {
|
|
if (!promise) {
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
try {
|
|
return await promise;
|
|
} catch (_) {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
export function getPeerIdsForProtocol(
|
|
protocol: IStore | ILightPush | IFilter | undefined,
|
|
peers: Peer[]
|
|
) {
|
|
return protocol
|
|
? peers
|
|
.filter((p) => p.protocols.includes(protocol.multicodec))
|
|
.map((p) => p.id)
|
|
: [];
|
|
}
|