Skip to content

Commit bc8acf7

Browse files
authored
feat: Waku API create node (#3580)
* introduce createNode # Conflicts: # apps/wakunode2/cli_args.nim * remove confutils dependency on the library * test: remove websocket in default test config * update to latest specs * test: cli_args * align to spec changes (sovereign, message conf, entrypoints * accept enr, entree and multiaddr as entry points * post rebase * format * change from "sovereign" to "core" * add example * get example to continue running * nitpicks * idiomatic constructors * fix enum naming * replace procs with consts * remove messageConfirmation * use pure enum * rename example file
1 parent 08d14fb commit bc8acf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1086
-70
lines changed

apps/liteprotocoltester/diagnose_connections.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import
1414
libp2p/wire
1515

1616
import
17+
../../tools/confutils/cli_args,
1718
waku/[
18-
factory/external_config,
1919
node/peer_manager,
2020
waku_lightpush/common,
2121
waku_relay,

apps/liteprotocoltester/liteprotocoltester.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import
1111
confutils
1212

1313
import
14+
../../tools/confutils/cli_args,
1415
waku/[
1516
common/enr,
1617
common/logging,
1718
factory/waku as waku_factory,
18-
factory/external_config,
1919
waku_node,
2020
node/waku_metrics,
2121
node/peer_manager,

apps/liteprotocoltester/service_peer_management.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import
1111
libp2p/wire
1212

1313
import
14+
../wakunode2/cli_args,
1415
waku/[
15-
factory/external_config,
1616
common/enr,
1717
waku_node,
1818
node/peer_manager,

apps/liteprotocoltester/tester_config.nim

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ import
1212
secp256k1
1313

1414
import
15-
waku/[
16-
common/confutils/envvar/defs as confEnvvarDefs,
17-
common/confutils/envvar/std/net as confEnvvarNet,
18-
common/logging,
19-
factory/external_config,
20-
waku_core,
21-
waku_core/topics/pubsub_topic,
22-
]
15+
../../tools/confutils/
16+
[cli_args, envvar as confEnvvarDefs, envvar_net as confEnvvarNet],
17+
waku/[common/logging, waku_core, waku_core/topics/pubsub_topic]
2318

2419
export confTomlDefs, confTomlNet, confEnvvarDefs, confEnvvarNet
2520

apps/liteprotocoltester/v3_publisher.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import results, options, chronos
2-
import waku/[waku_node, waku_core, waku_lightpush]
2+
import waku/[waku_node, waku_core, waku_lightpush, waku_lightpush/common]
33
import publisher_base
44

55
type V3Publisher* = ref object of PublisherBase

apps/wakunode2/wakunode2.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import
99
system/ansi_c,
1010
libp2p/crypto/crypto
1111
import
12-
../../tools/rln_keystore_generator/rln_keystore_generator,
12+
../../tools/[rln_keystore_generator/rln_keystore_generator, confutils/cli_args],
1313
waku/[
1414
common/logging,
15-
factory/external_config,
1615
factory/waku,
1716
node/health_monitor,
1817
waku_api/rest/builder as rest_server_builder,
18+
waku_core/message/default_values,
1919
]
2020

2121
logScope:

examples/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@ Make all examples.
77
make example2
88
```
99

10-
## basic2
10+
## Waku API
1111

12-
TODO
12+
Uses the simplified Waku API to create and start a node,
13+
you need an RPC endpoint for Linea Sepolia for RLN:
14+
15+
```console
16+
./build/waku_api --ethRpcEndpoint=https://linea-sepolia.infura.io/v3/<your key>
17+
```
18+
19+
If you can't be bothered but still want to see some action,
20+
just run the binary and it will use a non-RLN network:
21+
22+
```console
23+
./build/waku_api
24+
```
1325

1426
## publisher/subscriber
1527

examples/waku_example.nim

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import std/options
2+
import chronos, results, confutils, confutils/defs
3+
import waku
4+
5+
type CliArgs = object
6+
ethRpcEndpoint* {.
7+
defaultValue: "", desc: "ETH RPC Endpoint, if passed, RLN is enabled"
8+
.}: string
9+
10+
when isMainModule:
11+
let args = CliArgs.load()
12+
13+
echo "Starting Waku node..."
14+
15+
let config =
16+
if (args.ethRpcEndpoint == ""):
17+
# Create a basic configuration for the Waku node
18+
# No RLN as we don't have an ETH RPC Endpoint
19+
NodeConfig.init(wakuConfig = WakuConfig.init(entryNodes = @[], clusterId = 42))
20+
else:
21+
# Connect to TWN, use ETH RPC Endpoint for RLN
22+
NodeConfig.init(ethRpcEndpoints = @[args.ethRpcEndpoint])
23+
24+
# Create the node using the library API's createNode function
25+
let node = (waitFor createNode(config)).valueOr:
26+
echo "Failed to create node: ", error
27+
quit(QuitFailure)
28+
29+
echo("Waku node created successfully!")
30+
31+
# Start the node
32+
(waitFor startWaku(addr node)).isOkOr:
33+
echo "Failed to start node: ", error
34+
quit(QuitFailure)
35+
36+
echo "Node started successfully!"
37+
38+
runForever()

examples/wakustealthcommitments/node_spec.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{.push raises: [].}
22

3-
import waku/[common/logging, factory/[waku, networks_config, external_config]]
3+
import ../../apps/wakunode2/cli_args
4+
import waku/[common/logging, factory/[waku, networks_config]]
45
import
56
std/[options, strutils, os, sequtils],
67
chronicles,

library/waku_thread_requests/requests/node_lifecycle_request.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import chronos, chronicles, results, confutils, confutils/std/net
33

44
import
55
../../../waku/node/peer_manager/peer_manager,
6-
../../../waku/factory/external_config,
6+
../../../tools/confutils/cli_args,
77
../../../waku/factory/waku,
88
../../../waku/factory/node_factory,
99
../../../waku/factory/networks_config,

0 commit comments

Comments
 (0)