From 85811b0a785cf11b2bc6f3f5d0170898b26feac5 Mon Sep 17 00:00:00 2001 From: fryorcraken Date: Wed, 2 Jul 2025 15:06:53 +1000 Subject: [PATCH] feat: use json serde library for config over ffi --- .../requests/node_lifecycle_request.nim | 32 +++---------------- waku.nimble | 1 + 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/library/waku_thread_requests/requests/node_lifecycle_request.nim b/library/waku_thread_requests/requests/node_lifecycle_request.nim index 21765838e..e7be31592 100644 --- a/library/waku_thread_requests/requests/node_lifecycle_request.nim +++ b/library/waku_thread_requests/requests/node_lifecycle_request.nim @@ -1,5 +1,5 @@ import std/[options, json, strutils, net] -import chronos, chronicles, results, confutils, confutils/std/net +import chronos, chronicles, results, confutils, confutils/std/net, json_serialization import ../../../waku/node/peer_manager/peer_manager, @@ -40,41 +40,17 @@ proc destroyShared(self: ptr NodeLifecycleRequest) = proc createWaku( configJson: cstring, appCallbacks: AppCallbacks = nil ): Future[Result[Waku, string]] {.async.} = - var conf = defaultWakuNodeConf().valueOr: - return err("Failed creating node: " & error) + let decodedConf = Json.decode(configJson, WakuNodeConf) var errorResp: string - var jsonNode: JsonNode - try: - jsonNode = parseJson($configJson) - except Exception: - return err( - "exception in createWaku when calling parseJson: " & getCurrentExceptionMsg() & - " configJson string: " & $configJson - ) - - for confField, confValue in fieldPairs(conf): - if jsonNode.contains(confField): - # Make sure string doesn't contain the leading or trailing " character - let formattedString = ($jsonNode[confField]).strip(chars = {'\"'}) - # Override conf field with the value set in the json-string - try: - confValue = parseCmdArg(typeof(confValue), formattedString) - except Exception: - return err( - "exception in createWaku when parsing configuration. exc: " & - getCurrentExceptionMsg() & ". string that could not be parsed: " & - formattedString & ". expected type: " & $typeof(confValue) - ) - # Don't send relay app callbacks if relay is disabled - if not conf.relay and not appCallbacks.isNil(): + if not decodedConf.relay and not appCallbacks.isNil(): appCallbacks.relayHandler = nil appCallbacks.topicHealthChangeHandler = nil # TODO: Convert `confJson` directly to `WakuConf` - var wakuConf = conf.toWakuConf().valueOr: + var wakuConf = decodedConf.toWakuConf().valueOr: return err("Configuration error: " & $error) wakuConf.restServerConf = none(RestServerConf) ## don't want REST in libwaku diff --git a/waku.nimble b/waku.nimble index 3790b0333..b52c89278 100644 --- a/waku.nimble +++ b/waku.nimble @@ -15,6 +15,7 @@ requires "nim >= 2.2.4", "chronos", "eth", "json_rpc", + "json_serialization", "libbacktrace", "nimcrypto", "stew",