2022-11-04 09:52:27 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2022-07-17 14:25:21 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
std/tables,
|
|
|
|
stew/shims/net,
|
|
|
|
chronicles,
|
|
|
|
json_rpc/rpcserver
|
|
|
|
import
|
2022-10-18 17:35:26 +00:00
|
|
|
../../waku/v2/protocol/waku_message,
|
|
|
|
../../waku/v2/node/waku_node,
|
|
|
|
../../waku/v2/node/jsonrpc/[admin_api,
|
|
|
|
debug_api,
|
|
|
|
filter_api,
|
|
|
|
relay_api,
|
|
|
|
store_api,
|
|
|
|
private_api,
|
|
|
|
debug_api],
|
|
|
|
./config
|
2022-07-17 14:25:21 +00:00
|
|
|
|
|
|
|
logScope:
|
2022-11-04 08:40:13 +00:00
|
|
|
topics = "wakunode jsonrpc"
|
2022-07-17 14:25:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf)
|
2022-11-15 21:03:06 +00:00
|
|
|
{.raises: [RpcBindError].} =
|
2022-07-17 14:25:21 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
ta = initTAddress(rpcIp, rpcPort)
|
|
|
|
rpcServer = newRpcHttpServer([ta])
|
|
|
|
|
|
|
|
installDebugApiHandlers(node, rpcServer)
|
|
|
|
|
2022-11-15 21:03:06 +00:00
|
|
|
# TODO: Move to setup protocols proc
|
2022-07-17 14:25:21 +00:00
|
|
|
if conf.relay:
|
2022-11-15 21:03:06 +00:00
|
|
|
let topicCache = newTable[PubsubTopic, seq[WakuMessage]]()
|
2022-07-17 14:25:21 +00:00
|
|
|
installRelayApiHandlers(node, rpcServer, topicCache)
|
|
|
|
|
|
|
|
if conf.rpcPrivate:
|
|
|
|
# Private API access allows WakuRelay functionality that
|
|
|
|
# is backwards compatible with Waku v1.
|
2022-09-07 15:31:27 +00:00
|
|
|
installPrivateApiHandlers(node, rpcServer, topicCache)
|
2022-07-17 14:25:21 +00:00
|
|
|
|
2022-11-15 21:03:06 +00:00
|
|
|
# TODO: Move to setup protocols proc
|
|
|
|
if conf.filternode != "":
|
2022-07-17 14:25:21 +00:00
|
|
|
let messageCache = newTable[ContentTopic, seq[WakuMessage]]()
|
|
|
|
installFilterApiHandlers(node, rpcServer, messageCache)
|
|
|
|
|
2022-11-15 21:03:06 +00:00
|
|
|
# TODO: Move to setup protocols proc
|
|
|
|
if conf.storenode != "":
|
2022-07-17 14:25:21 +00:00
|
|
|
installStoreApiHandlers(node, rpcServer)
|
|
|
|
|
|
|
|
if conf.rpcAdmin:
|
|
|
|
installAdminApiHandlers(node, rpcServer)
|
|
|
|
|
|
|
|
rpcServer.start()
|
2022-11-15 21:03:06 +00:00
|
|
|
info "RPC Server started", address=ta
|