2020-09-10 04:18:35 +00:00
|
|
|
import
|
|
|
|
os, strutils, strformat, chronicles, json_rpc/[rpcclient, rpcserver], nimcrypto/sysrand,
|
2020-09-11 07:49:45 +00:00
|
|
|
stew/byteutils,
|
2020-09-10 04:18:35 +00:00
|
|
|
libp2p/protobuf/minprotobuf,
|
|
|
|
eth/common as eth_common, eth/keys,
|
|
|
|
system,
|
2020-09-11 07:49:45 +00:00
|
|
|
options,
|
|
|
|
../waku_types
|
2020-09-10 04:18:35 +00:00
|
|
|
|
|
|
|
from strutils import rsplit
|
|
|
|
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
|
|
|
|
|
|
|
const sigWakuPath = sourceDir / "wakucallsigs.nim"
|
|
|
|
createRpcSigs(RpcHttpClient, sigWakuPath)
|
|
|
|
|
|
|
|
if paramCount() < 1:
|
|
|
|
echo "Please provide rpcPort as argument."
|
|
|
|
quit(1)
|
|
|
|
|
|
|
|
let rpcPort = Port(parseInt(paramStr(1)))
|
|
|
|
|
|
|
|
echo "Please enter your message:"
|
2020-09-11 07:49:45 +00:00
|
|
|
let raw_input = readLine(stdin)
|
|
|
|
let input = fmt"{raw_input}"
|
|
|
|
echo "Input is:", input
|
2020-09-10 04:18:35 +00:00
|
|
|
|
|
|
|
var node = newRpcHttpClient()
|
|
|
|
waitfor node.connect("localhost", rpcPort)
|
|
|
|
|
2020-10-28 05:19:07 +00:00
|
|
|
let pubSubTopic = "/waku/2/default-waku/proto"
|
2020-09-11 07:49:45 +00:00
|
|
|
let contentTopic = "foobar"
|
|
|
|
var wakuMessage = WakuMessage(payload: input.toBytes(), contentTopic: contentTopic)
|
|
|
|
# XXX This should be WakuMessage type, but need to setup JSON-RPC mapping for that to work
|
|
|
|
var raw_bytes = wakuMessage.encode().buffer
|
|
|
|
var res = waitfor node.wakuPublish2(pubSubTopic, raw_bytes)
|
|
|
|
echo "Waku publish response: ", res
|