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`
This commit is contained in:
Emil Ivanichkov 2024-03-08 17:29:39 +02:00 committed by Emil Ivanichkov
parent e79d36b411
commit 1e697e253e
3 changed files with 38 additions and 22 deletions

View File

@ -1,22 +1,49 @@
import import
# Standard library
std/[strutils, typetraits], std/[strutils, typetraits],
confutils,
chronos, # Nimble packages
libp2p/crypto/crypto, confutils, chronos,
eth/[p2p/discoveryv5/enr],
chronicles/[log_output, topics_registry], chronicles/[log_output, topics_registry],
waku/[waku_core] eth/p2p/discoveryv5/enr,
libp2p/crypto/crypto,
presto,
waku/waku_core,
import status_node_manager/[ # Local modules
config, status_node_manager/[config, rest/common],
helpers/submodule # TODO: remove me ../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) = proc setupLogLevel*(level: LogLevel) =
topics_registry.setLogLevel(level) 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) = proc doWakuPairing(config: StatusNodeManagerConfig, rng: ref HmacDrbgContext) =
let wakuPairResult = waitFor wakuPair(rng, config.qr, config.qrMessageNameTag, let wakuPairResult = waitFor wakuPair(rng, config.qr, config.qrMessageNameTag,
config.wakuPort, config.discv5Port, config.wakuPort, config.discv5Port,
@ -32,6 +59,6 @@ when isMainModule:
let conf = load StatusNodeManagerConfig let conf = load StatusNodeManagerConfig
case conf.cmd case conf.cmd
of SNMStartUpCmd.noCommand: echo(getWelcomeMessage()) # TODO: remove me of SNMStartUpCmd.noCommand: doRunStatusNodeManager(conf)
of SNMStartUpCmd.pair: doWakuPairing(conf, rng) of SNMStartUpCmd.pair: doWakuPairing(conf, rng)

View File

@ -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!"

View File

@ -6,8 +6,3 @@
# To run these tests, simply execute `nimble test`. # To run these tests, simply execute `nimble test`.
import unittest import unittest
import status_node_manager/helpers/submodule
test "correct welcome":
check getWelcomeMessage() == "Hello, World!"