2026-06-30 11:51:22 +02:00
|
|
|
import std/[json, strformat]
|
2025-12-19 17:00:43 +01:00
|
|
|
import chronicles, chronos, results, ffi
|
|
|
|
|
import
|
2026-06-30 11:51:22 +02:00
|
|
|
logos_delivery,
|
2026-06-08 13:37:53 +02:00
|
|
|
logos_delivery/waku/waku_core/message,
|
|
|
|
|
logos_delivery/waku/waku_core/topics/pubsub_topic,
|
2025-12-19 17:00:43 +01:00
|
|
|
library/events/json_message_event,
|
|
|
|
|
library/declare_lib
|
|
|
|
|
|
|
|
|
|
proc waku_lightpush_publish(
|
2026-08-06 23:53:38 -03:00
|
|
|
self: LogosDelivery, pubSubTopic: string, jsonWakuMessage: string
|
|
|
|
|
): Future[Result[string, string]] {.ffi.} =
|
2025-12-19 17:00:43 +01:00
|
|
|
var jsonMessage: JsonMessage
|
|
|
|
|
try:
|
2026-08-06 23:53:38 -03:00
|
|
|
let jsonContent = parseJson(jsonWakuMessage)
|
2025-12-19 17:00:43 +01:00
|
|
|
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
|
|
|
|
|
raise newException(JsonParsingError, $error)
|
2026-08-06 23:53:38 -03:00
|
|
|
except JsonParsingError as e:
|
|
|
|
|
return err(fmt"Error parsing json message: {e.msg}")
|
2025-12-19 17:00:43 +01:00
|
|
|
|
|
|
|
|
let msg = json_message_event.toWakuMessage(jsonMessage).valueOr:
|
|
|
|
|
return err("Problem building the WakuMessage: " & $error)
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
let msgHashHex = (await self.waku.lightpushPublish(PubsubTopic(pubSubTopic), msg)).valueOr:
|
2025-12-19 17:00:43 +01:00
|
|
|
error "PUBLISH failed", error = error
|
2026-06-30 11:51:22 +02:00
|
|
|
return err(error)
|
2025-12-19 17:00:43 +01:00
|
|
|
|
|
|
|
|
return ok(msgHashHex)
|