2026-03-03 19:17:54 +01:00
|
|
|
import chronicles, chronos, results
|
2025-10-01 16:31:34 +10:00
|
|
|
|
|
|
|
|
import waku/factory/waku
|
2026-05-29 11:40:31 -03:00
|
|
|
import waku/messaging_client
|
2026-02-12 14:52:39 -03:00
|
|
|
import waku/[requests/health_requests, waku_core, waku_node]
|
2026-01-30 01:06:00 +01:00
|
|
|
import waku/node/delivery_service/send_service
|
2026-05-29 11:40:31 -03:00
|
|
|
import waku/node/subscription_manager
|
2026-02-17 10:38:35 +01:00
|
|
|
import libp2p/peerid
|
2026-03-03 19:17:54 +01:00
|
|
|
import ../../tools/confutils/cli_args
|
2026-01-30 01:06:00 +01:00
|
|
|
import ./[api_conf, types]
|
2025-10-01 16:31:34 +10:00
|
|
|
|
2026-03-03 19:17:54 +01:00
|
|
|
export cli_args
|
|
|
|
|
|
2026-01-30 01:06:00 +01:00
|
|
|
logScope:
|
|
|
|
|
topics = "api"
|
2025-10-01 16:31:34 +10:00
|
|
|
|
2026-03-03 19:17:54 +01:00
|
|
|
proc createNode*(conf: WakuNodeConf): Future[Result[Waku, string]] {.async.} =
|
|
|
|
|
let wakuConf = conf.toWakuConf().valueOr:
|
2025-10-01 16:31:34 +10:00
|
|
|
return err("Failed to handle the configuration: " & error)
|
|
|
|
|
|
|
|
|
|
## We are not defining app callbacks at node creation
|
|
|
|
|
let wakuRes = (await Waku.new(wakuConf)).valueOr:
|
|
|
|
|
error "waku initialization failed", error = error
|
|
|
|
|
return err("Failed setting up Waku: " & $error)
|
|
|
|
|
|
|
|
|
|
return ok(wakuRes)
|
2026-01-30 01:06:00 +01:00
|
|
|
|
|
|
|
|
proc checkApiAvailability(w: Waku): Result[void, string] =
|
|
|
|
|
if w.isNil():
|
|
|
|
|
return err("Waku node is not initialized")
|
|
|
|
|
|
2026-02-12 14:52:39 -03:00
|
|
|
# TODO: Conciliate request-bouncing health checks here with unit testing.
|
|
|
|
|
# (For now, better to just allow all sends and rely on retries.)
|
2026-01-30 01:06:00 +01:00
|
|
|
|
|
|
|
|
return ok()
|
|
|
|
|
|
|
|
|
|
proc subscribe*(
|
|
|
|
|
w: Waku, contentTopic: ContentTopic
|
|
|
|
|
): Future[Result[void, string]] {.async.} =
|
|
|
|
|
?checkApiAvailability(w)
|
|
|
|
|
|
2026-05-29 11:40:31 -03:00
|
|
|
return w.node.subscriptionManager.subscribe(contentTopic)
|
2026-01-30 01:06:00 +01:00
|
|
|
|
|
|
|
|
proc unsubscribe*(w: Waku, contentTopic: ContentTopic): Result[void, string] =
|
|
|
|
|
?checkApiAvailability(w)
|
|
|
|
|
|
2026-05-29 11:40:31 -03:00
|
|
|
return w.node.subscriptionManager.unsubscribe(contentTopic)
|
2026-01-30 01:06:00 +01:00
|
|
|
|
|
|
|
|
proc send*(
|
|
|
|
|
w: Waku, envelope: MessageEnvelope
|
|
|
|
|
): Future[Result[RequestId, string]] {.async.} =
|
|
|
|
|
?checkApiAvailability(w)
|
2026-05-29 18:50:07 -03:00
|
|
|
return await w.messagingClient.send(envelope)
|