mirror of https://github.com/waku-org/nwaku.git
refactor(wakunode2): Split wankunode2 JSON-RPC setup to its own file
This commit is contained in:
parent
538ee12a25
commit
e16747137e
|
@ -7,20 +7,12 @@ import
|
|||
std/tables,
|
||||
chronos,
|
||||
chronicles,
|
||||
json_rpc/rpcserver,
|
||||
metrics,
|
||||
metrics/chronos_httpserver,
|
||||
stew/results,
|
||||
stew/shims/net,
|
||||
./storage/sqlite,
|
||||
./storage/migration/migration_types,
|
||||
./jsonrpc/[admin_api,
|
||||
debug_api,
|
||||
filter_api,
|
||||
relay_api,
|
||||
store_api,
|
||||
private_api,
|
||||
debug_api],
|
||||
./config,
|
||||
./wakunode2
|
||||
|
||||
|
@ -34,37 +26,6 @@ type
|
|||
# Setup helper functions #
|
||||
##########################
|
||||
|
||||
proc startRpc*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf)
|
||||
{.raises: [Defect, RpcBindError, CatchableError].} =
|
||||
# @TODO: API handlers still raise CatchableError
|
||||
|
||||
let
|
||||
ta = initTAddress(rpcIp, rpcPort)
|
||||
rpcServer = newRpcHttpServer([ta])
|
||||
installDebugApiHandlers(node, rpcServer)
|
||||
|
||||
# Install enabled API handlers:
|
||||
if conf.relay:
|
||||
let topicCache = newTable[string, seq[WakuMessage]]()
|
||||
installRelayApiHandlers(node, rpcServer, topicCache)
|
||||
if conf.rpcPrivate:
|
||||
# Private API access allows WakuRelay functionality that
|
||||
# is backwards compatible with Waku v1.
|
||||
installPrivateApiHandlers(node, rpcServer, node.rng, topicCache)
|
||||
|
||||
if conf.filter:
|
||||
let messageCache = newTable[ContentTopic, seq[WakuMessage]]()
|
||||
installFilterApiHandlers(node, rpcServer, messageCache)
|
||||
|
||||
if conf.store:
|
||||
installStoreApiHandlers(node, rpcServer)
|
||||
|
||||
if conf.rpcAdmin:
|
||||
installAdminApiHandlers(node, rpcServer)
|
||||
|
||||
rpcServer.start()
|
||||
info "RPC Server started", ta
|
||||
|
||||
proc runMigrations*(sqliteDatabase: SqliteDatabase, conf: WakuNodeConf) =
|
||||
# Run migration scripts on persistent storage
|
||||
|
||||
|
|
|
@ -791,11 +791,9 @@ when isMainModule:
|
|||
../../common/utils/nat,
|
||||
./config,
|
||||
./waku_setup,
|
||||
<<<<<<< HEAD
|
||||
./wakunode2_setup_rest,
|
||||
=======
|
||||
./wakunode2_setup_metrics,
|
||||
>>>>>>> 37a9c0c1 (refactor(wakunode2): Split wankunode2 metrics setup to its own file)
|
||||
./wakunode2_setup_rpc,
|
||||
./storage/message/waku_message_store,
|
||||
./storage/peer/waku_peer_storage
|
||||
|
||||
|
@ -1087,7 +1085,7 @@ when isMainModule:
|
|||
## monitoring ports.
|
||||
|
||||
if conf.rpc:
|
||||
startRpc(node, conf.rpcAddress, Port(conf.rpcPort + conf.portsShift), conf)
|
||||
startRpcServer(node, conf.rpcAddress, Port(conf.rpcPort + conf.portsShift), conf)
|
||||
|
||||
if conf.rest:
|
||||
startRestServer(node, conf.restAddress, Port(conf.restPort + conf.portsShift), conf)
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
std/tables,
|
||||
stew/shims/net,
|
||||
chronicles,
|
||||
json_rpc/rpcserver
|
||||
import
|
||||
./config,
|
||||
./wakunode2,
|
||||
./jsonrpc/[admin_api,
|
||||
debug_api,
|
||||
filter_api,
|
||||
relay_api,
|
||||
store_api,
|
||||
private_api,
|
||||
debug_api]
|
||||
|
||||
logScope:
|
||||
topics = "wakunode.setup.rpc"
|
||||
|
||||
|
||||
proc startRpcServer*(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf)
|
||||
{.raises: [Defect, RpcBindError].} =
|
||||
|
||||
let
|
||||
ta = initTAddress(rpcIp, rpcPort)
|
||||
rpcServer = newRpcHttpServer([ta])
|
||||
|
||||
installDebugApiHandlers(node, rpcServer)
|
||||
|
||||
if conf.relay:
|
||||
let topicCache = newTable[string, seq[WakuMessage]]()
|
||||
installRelayApiHandlers(node, rpcServer, topicCache)
|
||||
|
||||
if conf.rpcPrivate:
|
||||
# Private API access allows WakuRelay functionality that
|
||||
# is backwards compatible with Waku v1.
|
||||
installPrivateApiHandlers(node, rpcServer, node.rng, topicCache)
|
||||
|
||||
if conf.filter:
|
||||
let messageCache = newTable[ContentTopic, seq[WakuMessage]]()
|
||||
installFilterApiHandlers(node, rpcServer, messageCache)
|
||||
|
||||
if conf.store:
|
||||
installStoreApiHandlers(node, rpcServer)
|
||||
|
||||
if conf.rpcAdmin:
|
||||
installAdminApiHandlers(node, rpcServer)
|
||||
|
||||
rpcServer.start()
|
||||
info "RPC Server started", ta
|
Loading…
Reference in New Issue