From dc0ebc7142fb9f4841e79c6f262a40977c5efecf Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Wed, 24 Dec 2025 13:40:36 +0530 Subject: [PATCH] updated libwaku API to integrate with logos chat poc for mix integration --- library/kernel_api/protocols/filter_api.nim | 4 ++- .../kernel_api/protocols/lightpush_api.nim | 18 +++++----- waku/node/kernel_api/lightpush.nim | 36 ++++++++++--------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/library/kernel_api/protocols/filter_api.nim b/library/kernel_api/protocols/filter_api.nim index c4f99510a..868f47a52 100644 --- a/library/kernel_api/protocols/filter_api.nim +++ b/library/kernel_api/protocols/filter_api.nim @@ -47,8 +47,10 @@ proc waku_filter_subscribe( error "fail filter subscribe", error = errorMsg return err(errorMsg) + let pubsubTopicOpt = + if ($pubsubTopic).len > 0: some(PubsubTopic($pubsubTopic)) else: none(PubsubTopic) let subFut = ctx.myLib[].node.filterSubscribe( - some(PubsubTopic($pubsubTopic)), + pubsubTopicOpt, ($contentTopics).split(",").mapIt(ContentTopic(it)), peer, ) diff --git a/library/kernel_api/protocols/lightpush_api.nim b/library/kernel_api/protocols/lightpush_api.nim index e9251a3f3..3484f9308 100644 --- a/library/kernel_api/protocols/lightpush_api.nim +++ b/library/kernel_api/protocols/lightpush_api.nim @@ -39,13 +39,15 @@ proc waku_lightpush_publish( let errorMsg = "failed to lightpublish message, no suitable remote peers" error "PUBLISH failed", error = errorMsg return err(errorMsg) + let topic = + if ($pubsubTopic).len == 0: + none(PubsubTopic) + else: + some(PubsubTopic($pubsubTopic)) - let msgHashHex = ( - await ctx.myLib[].node.wakuLegacyLightpushClient.publish( - $pubsubTopic, msg, peer = peerOpt.get() - ) - ).valueOr: - error "PUBLISH failed", error = error - return err($error) + discard (await ctx.myLib[].node.lightpushPublish(topic, msg, peerOpt)).valueOr: + let errorMsg = error.desc.get($error.code.int) + error "PUBLISH failed", error = errorMsg + return err(errorMsg) - return ok(msgHashHex) + return ok("") diff --git a/waku/node/kernel_api/lightpush.nim b/waku/node/kernel_api/lightpush.nim index 2a5f6acbb..0e44f60fb 100644 --- a/waku/node/kernel_api/lightpush.nim +++ b/waku/node/kernel_api/lightpush.nim @@ -246,23 +246,27 @@ proc lightpushPublish*( return lighpushErrorResult( LightPushErrorCode.SERVICE_NOT_AVAILABLE, "Waku lightpush not available" ) - if mixify and node.wakuMix.isNil(): - error "failed to publish message using mix as mix protocol is not mounted" + var lmixify = mixify + if not node.wakuMix.isNil(): + lmixify = true + + let + #[ error "failed to publish message using mix as mix protocol is not mounted" return lighpushErrorResult( LightPushErrorCode.SERVICE_NOT_AVAILABLE, "Waku lightpush with mix not available" - ) - let toPeer: RemotePeerInfo = peerOpt.valueOr: - if not node.wakuLightPush.isNil(): - RemotePeerInfo.init(node.peerId()) - elif not node.wakuLightpushClient.isNil(): - node.peerManager.selectPeer(WakuLightPushCodec).valueOr: - let msg = "no suitable remote peers" - error "failed to publish message", msg = msg - return lighpushErrorResult(LightPushErrorCode.NO_PEERS_TO_RELAY, msg) - else: - return lighpushErrorResult( - LightPushErrorCode.NO_PEERS_TO_RELAY, "no suitable remote peers" - ) + ) ]# + toPeer: RemotePeerInfo = peerOpt.valueOr: + if not node.wakuLightPush.isNil(): + RemotePeerInfo.init(node.peerId()) + elif not node.wakuLightpushClient.isNil(): + node.peerManager.selectPeer(WakuLightPushCodec).valueOr: + let msg = "no suitable remote peers" + error "failed to publish message", msg = msg + return lighpushErrorResult(LightPushErrorCode.NO_PEERS_TO_RELAY, msg) + else: + return lighpushErrorResult( + LightPushErrorCode.NO_PEERS_TO_RELAY, "no suitable remote peers" + ) let pubsubForPublish = pubSubTopic.valueOr: if node.wakuAutoSharding.isNone(): @@ -280,4 +284,4 @@ proc lightpushPublish*( error "lightpush publish error", error = msg return lighpushErrorResult(LightPushErrorCode.INTERNAL_SERVER_ERROR, msg) - return await lightpushPublishHandler(node, pubsubForPublish, message, toPeer, mixify) + return await lightpushPublishHandler(node, pubsubForPublish, message, toPeer, lmixify)