add websocket rpc server

This commit is contained in:
jangko 2021-08-05 14:51:28 +07:00
parent 5e87624315
commit 77092641b5
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 14 additions and 1 deletions

View File

@ -788,7 +788,7 @@ LOCAL SERVICE OPTIONS:
--graphql Enable the HTTP-GraphQL server
--graphqlbind:<value> Set address:port pair GraphQL server will bind (default: localhost:8547)
--ws Enable the Websocket JSON-RPC server
--wsbind:<value> Set address:port pair(s) (comma-separated) Websocket JSON-RPC server will bind to (default: localhost:8546)
--wsbind:<value> Set address:port pair Websocket JSON-RPC server will bind to (default: localhost:8546)
--wsapi:<value> Enable specific set of Websocket RPC API from list (comma-separated) (available: eth, debug)
LOGGING AND DEBUGGING OPTIONS:

View File

@ -40,6 +40,7 @@ type
ethNode*: EthereumNode
state*: NimbusState
graphqlServer*: GraphqlHttpServerRef
wsRpcServer*: RpcWebSocketServer
proc start(nimbus: NimbusNode) =
var conf = getConfiguration()
@ -138,6 +139,18 @@ proc start(nimbus: NimbusNode) =
if RpcFlags.Debug in conf.rpc.flags:
setupDebugRpc(chainDB, nimbus.rpcServer)
# Creating Websocket RPC Server
if RpcFlags.Enabled in conf.ws.flags:
doAssert(conf.ws.binds.len > 0)
nimbus.wsRpcServer = newRpcWebSocketServer(conf.ws.binds[0])
setupCommonRpc(nimbus.ethNode, nimbus.wsRpcServer)
# Enable Websocket RPC APIs based on RPC flags and protocol flags
if RpcFlags.Eth in conf.ws.flags and ProtocolFlags.Eth in conf.net.protocols:
setupEthRpc(nimbus.ethNode, chainDB, nimbus.wsRpcServer)
if RpcFlags.Debug in conf.ws.flags:
setupDebugRpc(chainDB, nimbus.wsRpcServer)
## Starting servers
if RpcFlags.Enabled in conf.rpc.flags:
nimbus.rpcServer.rpc("admin_quit") do() -> string: