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,
|
std/tables,
|
||||||
chronos,
|
chronos,
|
||||||
chronicles,
|
chronicles,
|
||||||
json_rpc/rpcserver,
|
|
||||||
metrics,
|
metrics,
|
||||||
metrics/chronos_httpserver,
|
metrics/chronos_httpserver,
|
||||||
stew/results,
|
stew/results,
|
||||||
stew/shims/net,
|
stew/shims/net,
|
||||||
./storage/sqlite,
|
./storage/sqlite,
|
||||||
./storage/migration/migration_types,
|
./storage/migration/migration_types,
|
||||||
./jsonrpc/[admin_api,
|
|
||||||
debug_api,
|
|
||||||
filter_api,
|
|
||||||
relay_api,
|
|
||||||
store_api,
|
|
||||||
private_api,
|
|
||||||
debug_api],
|
|
||||||
./config,
|
./config,
|
||||||
./wakunode2
|
./wakunode2
|
||||||
|
|
||||||
|
@ -34,37 +26,6 @@ type
|
||||||
# Setup helper functions #
|
# 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) =
|
proc runMigrations*(sqliteDatabase: SqliteDatabase, conf: WakuNodeConf) =
|
||||||
# Run migration scripts on persistent storage
|
# Run migration scripts on persistent storage
|
||||||
|
|
||||||
|
|
|
@ -791,11 +791,9 @@ when isMainModule:
|
||||||
../../common/utils/nat,
|
../../common/utils/nat,
|
||||||
./config,
|
./config,
|
||||||
./waku_setup,
|
./waku_setup,
|
||||||
<<<<<<< HEAD
|
|
||||||
./wakunode2_setup_rest,
|
./wakunode2_setup_rest,
|
||||||
=======
|
|
||||||
./wakunode2_setup_metrics,
|
./wakunode2_setup_metrics,
|
||||||
>>>>>>> 37a9c0c1 (refactor(wakunode2): Split wankunode2 metrics setup to its own file)
|
./wakunode2_setup_rpc,
|
||||||
./storage/message/waku_message_store,
|
./storage/message/waku_message_store,
|
||||||
./storage/peer/waku_peer_storage
|
./storage/peer/waku_peer_storage
|
||||||
|
|
||||||
|
@ -1087,7 +1085,7 @@ when isMainModule:
|
||||||
## monitoring ports.
|
## monitoring ports.
|
||||||
|
|
||||||
if conf.rpc:
|
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:
|
if conf.rest:
|
||||||
startRestServer(node, conf.restAddress, Port(conf.restPort + conf.portsShift), conf)
|
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