Add support for WakuMessage and merge publish function (#122)

* Add WakuMessage type

* Add WakuMessage encoding and decoding

Also clean up waku_types module and imports

* Clean up waku_relay module

Imports, remove old text test, make fields and functions public, format.

* Publish WakuMessage

Also fix type mismatch in RPC

* Make publish work in examples, node and protocol

* Parse protobuf content in examples

* Update docs

* Update waku/node/v2/waku_types.nim

* Fix compilation error and disable out of date waku test

Co-authored-by: Kim De Mey <kim.demey@gmail.com>
This commit is contained in:
Oskar Thorén
2020-09-01 17:20:38 +02:00
committed by GitHub
co-authored by Kim De Mey
parent fd2bb36b15
commit f828736e1c
8 changed files with 84 additions and 76 deletions
+10 -4
View File
@@ -11,6 +11,9 @@ import
../../waku/node/v2/[config, wakunode2, waku_types],
../../waku/node/common
type
Topic* = waku_types.Topic
# Node operations happens asynchronously
proc runBackground() {.async.} =
let
@@ -24,13 +27,16 @@ proc runBackground() {.async.} =
await node.start()
# Subscribe to a topic
let topic = "foobar"
proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =
info "Hit subscribe handler", topic=topic, data=data, decoded=cast[string](data)
let topic = cast[Topic]("foobar")
proc handler(topic: Topic, data: seq[byte]) {.async, gcsafe.} =
let message = WakuMessage.init(data).value
let payload = cast[string](message.payload)
info "Hit subscribe handler", topic=topic, payload=payload, contentTopic=message.contentTopic
node.subscribe(topic, handler)
# Publish to a topic
let message = cast[seq[byte]]("hello world")
let payload = cast[seq[byte]]("hello world")
let message = WakuMessage(payload: payload, contentTopic: "foo")
node.publish(topic, message)
# TODO Await with try/except here