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
# 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)

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`.
import unittest
import status_node_manager/helpers/submodule
test "correct welcome":
check getWelcomeMessage() == "Hello, World!"