Make basic Waku v2 examples run again (#123)

* Make basic Waku v2 examples run again

Regression introduced in https://github.com/status-im/nim-waku/pull/117

Happened due to example not being run on CI.

- Add wakuexample to all target
- Fix example2 to run
- Basic formatting

* Update examples/v2/basic2.nim

Co-authored-by: Kim De Mey <kim.demey@gmail.com>

* Update examples/v2/basic2.nim

* Update examples/v2/basic2.nim

* Update examples/v2/basic2.nim

Co-authored-by: Kim De Mey <kim.demey@gmail.com>
This commit is contained in:
Oskar Thorén 2020-09-01 16:32:19 +08:00 committed by GitHub
parent 67a964be28
commit e8d3156571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 22 deletions

View File

@ -47,7 +47,7 @@ GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
else # "variables.mk" was included. Business as usual until the end of this file. else # "variables.mk" was included. Business as usual until the end of this file.
# default target, because it's the first one that doesn't start with '.' # default target, because it's the first one that doesn't start with '.'
all: | wakunode wakusim wakuexample wakunode2 wakusim2 all: | wakunode wakusim wakuexample wakunode2 wakusim2 wakuexample2
# must be included after the default target # must be included after the default target
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk -include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk

View File

@ -1,25 +1,27 @@
# Here's an example of how you would start a Waku node, subscribe to topics, and ## Here's a basic example of how you would start a Waku node, subscribe to
# publish to them ## topics, and publish to them.
import confutils, chronicles, chronos, os import
std/os,
import stew/shims/net as stewNet confutils, chronicles, chronos,
import libp2p/crypto/crypto stew/shims/net as stewNet,
import libp2p/crypto/secp libp2p/crypto/[crypto,secp],
import eth/keys eth/keys,
import json_rpc/[rpcclient, rpcserver] json_rpc/[rpcclient, rpcserver],
../../waku/node/v2/[config, wakunode2, waku_types],
import ../../waku/node/v2/config ../../waku/node/common
import ../../waku/node/v2/wakunode2
import ../../waku/node/v2/waku_types
# Loads the config in `waku/node/v2/config.nim`
let conf = WakuNodeConf.load()
# Node operations happens asynchronously # Node operations happens asynchronously
proc runBackground(conf: WakuNodeConf) {.async.} = proc runBackground() {.async.} =
# Create and start the node let
let node = await WakuNode.init(conf) conf = WakuNodeConf.load()
(extIp, extTcpPort, extUdpPort) = setupNat(conf.nat, clientId,
Port(uint16(conf.tcpPort) + conf.portsShift),
Port(uint16(conf.udpPort) + conf.portsShift))
node = WakuNode.init(conf.nodeKey, conf.libp2pAddress,
Port(uint16(conf.tcpPort) + conf.portsShift), extIp, extTcpPort)
await node.start()
# Subscribe to a topic # Subscribe to a topic
let topic = "foobar" let topic = "foobar"
@ -31,6 +33,7 @@ proc runBackground(conf: WakuNodeConf) {.async.} =
let message = cast[seq[byte]]("hello world") let message = cast[seq[byte]]("hello world")
node.publish(topic, message) node.publish(topic, message)
discard runBackground(conf) # TODO Await with try/except here
discard runBackground()
runForever() runForever()

View File

@ -30,7 +30,7 @@ type
HistoryResponse* = object HistoryResponse* = object
messages*: seq[Message] messages*: seq[Message]
const clientId = "Nimbus Waku v2 node" const clientId* = "Nimbus Waku v2 node"
# NOTE Any difference here in Waku vs Eth2? # NOTE Any difference here in Waku vs Eth2?
# E.g. Devp2p/Libp2p support, etc. # E.g. Devp2p/Libp2p support, etc.