From 1e697e253ef1156bbfbbedaddf6fb8882e488cec Mon Sep 17 00:00:00 2001 From: Emil Ivanichkov Date: Fri, 8 Mar 2024 17:29:39 +0200 Subject: [PATCH] feat(SNM): Initial implementation of `doRunStatusNodeManager` This includes: - Initial implementation of global state object called `SNM` - It's corresponding `init` & `run` functions that initialize and start a rest server - Formatting improvements in the `import` section of `src/status_node_manager.nim` --- src/status_node_manager.nim | 49 ++++++++++++++----- src/status_node_manager/helpers/submodule.nim | 6 --- tests/test1.nim | 5 -- 3 files changed, 38 insertions(+), 22 deletions(-) delete mode 100644 src/status_node_manager/helpers/submodule.nim diff --git a/src/status_node_manager.nim b/src/status_node_manager.nim index 4a86368..c7fa357 100644 --- a/src/status_node_manager.nim +++ b/src/status_node_manager.nim @@ -1,22 +1,49 @@ import + # Standard library std/[strutils, typetraits], - confutils, - chronos, - libp2p/crypto/crypto, - eth/[p2p/discoveryv5/enr], + + # Nimble packages + confutils, chronos, chronicles/[log_output, topics_registry], - waku/[waku_core] + eth/p2p/discoveryv5/enr, + libp2p/crypto/crypto, + presto, + waku/waku_core, -import status_node_manager/[ - config, - helpers/submodule # TODO: remove me - ] + # Local modules + status_node_manager/[config, rest/common], + ../libs/waku_utils/waku_pair -import ../libs/waku_utils/waku_pair +type SNM* = ref object + restServer*: RestServerRef + +proc init*(T: type SNM, + config: StatusNodeManagerConfig): SNM = + + let restServer = if config.restEnabled: + RestServerRef.init(config.restAddress, config.restPort, + restValidate, + config) + else: + nil + + SNM(restServer: restServer) + +proc run(snm: SNM) = + if not isNil(snm.restServer): + snm.restServer.start() + + runForever() proc setupLogLevel*(level: LogLevel) = topics_registry.setLogLevel(level) +proc doRunStatusNodeManager(config: StatusNodeManagerConfig) = + notice "Starting Status Node Manager" + + let snm = SNM.init(config) + snm.run() + proc doWakuPairing(config: StatusNodeManagerConfig, rng: ref HmacDrbgContext) = let wakuPairResult = waitFor wakuPair(rng, config.qr, config.qrMessageNameTag, config.wakuPort, config.discv5Port, @@ -32,6 +59,6 @@ when isMainModule: let conf = load StatusNodeManagerConfig case conf.cmd - of SNMStartUpCmd.noCommand: echo(getWelcomeMessage()) # TODO: remove me + of SNMStartUpCmd.noCommand: doRunStatusNodeManager(conf) of SNMStartUpCmd.pair: doWakuPairing(conf, rng) diff --git a/src/status_node_manager/helpers/submodule.nim b/src/status_node_manager/helpers/submodule.nim deleted file mode 100644 index 2679348..0000000 --- a/src/status_node_manager/helpers/submodule.nim +++ /dev/null @@ -1,6 +0,0 @@ -# This is just an example to get you started. Users of your hybrid library will -# import this file by writing ``import status_node_manager/submodule``. Feel free to rename or -# remove this file altogether. You may create additional modules alongside -# this file as required. - -proc getWelcomeMessage*(): string = "Hello, World!" diff --git a/tests/test1.nim b/tests/test1.nim index 6a7cf04..7707c5f 100644 --- a/tests/test1.nim +++ b/tests/test1.nim @@ -6,8 +6,3 @@ # To run these tests, simply execute `nimble test`. import unittest - -import status_node_manager/helpers/submodule - -test "correct welcome": - check getWelcomeMessage() == "Hello, World!"