mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 16:33:08 +00:00
feat: use json serde library for config over ffi
This commit is contained in:
parent
cc30666016
commit
85811b0a78
@ -1,5 +1,5 @@
|
|||||||
import std/[options, json, strutils, net]
|
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
|
import
|
||||||
../../../waku/node/peer_manager/peer_manager,
|
../../../waku/node/peer_manager/peer_manager,
|
||||||
@ -40,41 +40,17 @@ proc destroyShared(self: ptr NodeLifecycleRequest) =
|
|||||||
proc createWaku(
|
proc createWaku(
|
||||||
configJson: cstring, appCallbacks: AppCallbacks = nil
|
configJson: cstring, appCallbacks: AppCallbacks = nil
|
||||||
): Future[Result[Waku, string]] {.async.} =
|
): Future[Result[Waku, string]] {.async.} =
|
||||||
var conf = defaultWakuNodeConf().valueOr:
|
let decodedConf = Json.decode(configJson, WakuNodeConf)
|
||||||
return err("Failed creating node: " & error)
|
|
||||||
|
|
||||||
var errorResp: string
|
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
|
# 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.relayHandler = nil
|
||||||
appCallbacks.topicHealthChangeHandler = nil
|
appCallbacks.topicHealthChangeHandler = nil
|
||||||
|
|
||||||
# TODO: Convert `confJson` directly to `WakuConf`
|
# TODO: Convert `confJson` directly to `WakuConf`
|
||||||
var wakuConf = conf.toWakuConf().valueOr:
|
var wakuConf = decodedConf.toWakuConf().valueOr:
|
||||||
return err("Configuration error: " & $error)
|
return err("Configuration error: " & $error)
|
||||||
|
|
||||||
wakuConf.restServerConf = none(RestServerConf) ## don't want REST in libwaku
|
wakuConf.restServerConf = none(RestServerConf) ## don't want REST in libwaku
|
||||||
|
|||||||
@ -15,6 +15,7 @@ requires "nim >= 2.2.4",
|
|||||||
"chronos",
|
"chronos",
|
||||||
"eth",
|
"eth",
|
||||||
"json_rpc",
|
"json_rpc",
|
||||||
|
"json_serialization",
|
||||||
"libbacktrace",
|
"libbacktrace",
|
||||||
"nimcrypto",
|
"nimcrypto",
|
||||||
"stew",
|
"stew",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user