mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-03 09:03:19 +00:00
move waku api to own file
This commit is contained in:
parent
613e2eea20
commit
9ec9468d6f
@ -16,7 +16,6 @@ import
|
||||
waku/waku_core/subscription/push_handler,
|
||||
waku/waku_relay,
|
||||
waku/factory/waku,
|
||||
./libwaku_conf,
|
||||
./events/json_message_event,
|
||||
./waku_context,
|
||||
./waku_thread_requests/requests/node_lifecycle_request,
|
||||
@ -99,23 +98,6 @@ proc initializeLibrary() {.exported.} =
|
||||
### End of library setup
|
||||
################################################################################
|
||||
|
||||
################################################################################
|
||||
### Nim native exported procs (Waku API)
|
||||
|
||||
proc createNode*(config: LibWakuConf): Future[Result[Waku, string]] {.async.} =
|
||||
let wakuConf = toWakuConf(config).valueOr:
|
||||
return err("Failed to handle the configuration: " & error)
|
||||
|
||||
## We are not defining app callbacks at node creation
|
||||
let wakuRes = (await Waku.new(wakuConf)).valueOr:
|
||||
error "waku initialization failed", error = error
|
||||
return err("Failed setting up Waku: " & $error)
|
||||
|
||||
return ok(wakuRes)
|
||||
|
||||
### End of Nim native exported procs (Waku API)
|
||||
################################################################################
|
||||
|
||||
################################################################################
|
||||
### FFI Exported procs
|
||||
|
||||
|
||||
16
library/libwaku_api.nim
Normal file
16
library/libwaku_api.nim
Normal file
@ -0,0 +1,16 @@
|
||||
import chronicles, chronos, results
|
||||
|
||||
import waku/factory/waku
|
||||
|
||||
import ./libwaku_conf
|
||||
|
||||
proc createNode*(config: LibWakuConf): Future[Result[Waku, string]] {.async.} =
|
||||
let wakuConf = toWakuConf(config).valueOr:
|
||||
return err("Failed to handle the configuration: " & error)
|
||||
|
||||
## We are not defining app callbacks at node creation
|
||||
let wakuRes = (await Waku.new(wakuConf)).valueOr:
|
||||
error "waku initialization failed", error = error
|
||||
return err("Failed setting up Waku: " & $error)
|
||||
|
||||
return ok(wakuRes)
|
||||
@ -16,6 +16,7 @@ type RlnConfig* = object
|
||||
contractAddress*: string
|
||||
chainId*: uint
|
||||
epochSizeSec*: uint64
|
||||
rpcApiUrls*: seq[string]
|
||||
|
||||
type MessageValidation* = object
|
||||
maxMessageSizeBytes*: uint64
|
||||
@ -96,5 +97,10 @@ proc toWakuConf*(libConf: LibWakuConf): Result[WakuConf, string] =
|
||||
b.rlnRelayConf.withEthContractAddress(rlnConfig.contractAddress)
|
||||
b.rlnRelayConf.withChainId(rlnConfig.chainId)
|
||||
b.rlnRelayConf.withEpochSizeSec(rlnConfig.epochSizeSec)
|
||||
b.rlnRelayConf.withDynamic(true)
|
||||
b.rlnRelayConf.withEthClientUrls(rlnConfig.rpcApiUrls)
|
||||
|
||||
## Various configurations
|
||||
b.withNatStrategy("any")
|
||||
|
||||
return b.build()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import std/options, results, chronos, results, testutils/unittests
|
||||
import library/libwaku, library/libwaku_conf, waku/factory/waku
|
||||
import std/options, results, chronos, testutils/unittests
|
||||
import library/libwaku_api, library/libwaku_conf, waku/factory/waku
|
||||
|
||||
suite "LibWaku - createNode":
|
||||
asyncTest "Create node with minimal Relay configuration":
|
||||
@ -72,6 +72,7 @@ suite "LibWaku - createNode":
|
||||
contractAddress: "0x1234567890123456789012345678901234567890",
|
||||
chainId: 1'u,
|
||||
epochSizeSec: 600'u64,
|
||||
rpcApiUrls: @["https://example.com/1234"],
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user