mirror of
https://github.com/logos-messaging/examples.waku.org.git
synced 2026-01-02 12:53:08 +00:00
feat: enable autosharding in rln-js
This commit is contained in:
parent
cbb436ad35
commit
1fcc640016
@ -9,7 +9,12 @@ import {
|
||||
} from "@waku/rln";
|
||||
import { createEncoder, createDecoder } from "@waku/sdk";
|
||||
|
||||
import { CONTENT_TOPIC, MEMBERSHIP_ID, RLN_CREDENTIALS } from "./const";
|
||||
import {
|
||||
CONTENT_TOPIC,
|
||||
MEMBERSHIP_ID,
|
||||
RLN_CREDENTIALS,
|
||||
CLUSTER_ID,
|
||||
} from "./const";
|
||||
|
||||
export async function initRLN(onStatusChange) {
|
||||
onStatusChange("Connecting to wallet...");
|
||||
@ -40,16 +45,21 @@ export async function initRLN(onStatusChange) {
|
||||
onStatusChange("Failed to initialize RLN", "error");
|
||||
throw Error(err);
|
||||
}
|
||||
|
||||
const encoder = new RLNEncoder(
|
||||
createEncoder({
|
||||
ephemeral: false,
|
||||
contentTopic: CONTENT_TOPIC,
|
||||
pubsubTopicShardInfo: { clusterId: CLUSTER_ID },
|
||||
}),
|
||||
rlnInstance,
|
||||
MEMBERSHIP_ID,
|
||||
RLN_CREDENTIALS
|
||||
);
|
||||
const decoder = new RLNDecoder(rlnInstance, createDecoder(CONTENT_TOPIC));
|
||||
const decoder = new RLNDecoder(
|
||||
rlnInstance,
|
||||
createDecoder(CONTENT_TOPIC, { clusterId: CLUSTER_ID })
|
||||
);
|
||||
|
||||
onStatusChange("RLN initialized", "success");
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { createLightNode, waitForRemotePeer } from "@waku/sdk";
|
||||
|
||||
import { ProtoChatMessage } from "./const";
|
||||
import { CLUSTER_ID, ProtoChatMessage } from "./const";
|
||||
|
||||
export async function initWaku({
|
||||
encoder,
|
||||
@ -11,6 +11,7 @@ export async function initWaku({
|
||||
onStatusChange("Initializing Waku...");
|
||||
const node = await createLightNode({
|
||||
defaultBootstrap: true,
|
||||
shardInfo: { clusterId: CLUSTER_ID, contentTopics: [CONTENT_TOPIC] },
|
||||
});
|
||||
onStatusChange("Waiting for peers");
|
||||
await node.start();
|
||||
@ -31,7 +32,10 @@ export async function initWaku({
|
||||
};
|
||||
|
||||
onStatusChange("Subscribing to content topic...");
|
||||
const subscription = await node.filter.createSubscription();
|
||||
const subscription = await node.filter.createSubscription({
|
||||
clusterId: CLUSTER_ID,
|
||||
shard: contentTopicToShardIndex(CONTENT_TOPIC),
|
||||
});
|
||||
const onSubscribe = async (cb) => {
|
||||
await subscription.subscribe(decoder, (message) => {
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user