Ivan FB 8c274be44d
waku: extract node/query API into waku/api/ and move events
Move the discovery/lightpush/store/ping/debug/health/topics operations into
logos_delivery/waku/api/ and relocate the waku event definitions under
waku/api/events/.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 04:15:23 +02:00

36 lines
1.1 KiB
Nim

## Waku layer API — lightpush (light client publish) operations.
import logos_delivery/waku/compat/option_valueor
{.push raises: [].}
import results, chronos, chronicles
import logos_delivery/waku/waku
import
logos_delivery/waku/[
waku_core,
waku_core/codecs,
node/waku_node,
node/peer_manager,
waku_lightpush_legacy/client,
]
proc lightpushPublish*(
self: Waku, pubsubTopic: PubsubTopic, message: WakuMessage
): Future[Result[string, string]] {.async.} =
## Selects a lightpush service peer and publishes; returns the message hash.
try:
if self.node.wakuLegacyLightpushClient.isNil():
return err("wakuLegacyLightpushClient is not mounted")
let remotePeer = self.node.peerManager.selectPeer(WakuLightPushCodec).valueOr:
return err("failed to lightpublish message, no suitable remote peers")
let msgHashHex = (
await self.node.wakuLegacyLightpushClient.publish(pubsubTopic, message, remotePeer)
).valueOr:
return err($error)
return ok(msgHashHex)
except CatchableError as e:
return err(e.msg)