Skip to content

Commit

Permalink
Create setupRpcServer closure to remove code duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
web3-developer committed Sep 18, 2024
1 parent 6e47b9f commit 5dedfba
Showing 1 changed file with 22 additions and 39 deletions.
61 changes: 22 additions & 39 deletions fluffy/fluffy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -209,65 +209,48 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =

## Start the JSON-RPC APIs

if config.rpcEnabled:
let
ta = initTAddress(config.rpcAddress, config.rpcPort)
rpcHttpServer = RpcHttpServer.new()

# Note: Set maxRequestBodySize to 4MB instead of 1MB as there are blocks
# that reach that limit (in hex, for gossip method).
rpcHttpServer.addHttpServer(ta, maxRequestBodySize = 4 * 1_048_576)

rpcHttpServer.installDiscoveryApiHandlers(d)
rpcHttpServer.installWeb3ApiHandlers()
proc setupRpcServer(
rpcServer: RpcHttpServer | RpcWebSocketServer
) {.raises: [CatchableError].} =
rpcServer.installDiscoveryApiHandlers(d)
rpcServer.installWeb3ApiHandlers()
if node.stateNetwork.isSome():
rpcHttpServer.installPortalApiHandlers(
rpcServer.installPortalApiHandlers(
node.stateNetwork.value.portalProtocol, "state"
)
if node.historyNetwork.isSome():
rpcHttpServer.installEthApiHandlers(
rpcServer.installEthApiHandlers(
node.historyNetwork.value, node.beaconLightClient, node.stateNetwork
)
rpcHttpServer.installPortalApiHandlers(
rpcServer.installPortalApiHandlers(
node.historyNetwork.value.portalProtocol, "history"
)
rpcHttpServer.installPortalDebugApiHandlers(
rpcServer.installPortalDebugApiHandlers(
node.historyNetwork.value.portalProtocol, "history"
)
if node.beaconNetwork.isSome():
rpcHttpServer.installPortalApiHandlers(
rpcServer.installPortalApiHandlers(
node.beaconNetwork.value.portalProtocol, "beacon"
)

rpcHttpServer.start()
rpcServer.start()

if config.rpcEnabled:
let
ta = initTAddress(config.rpcAddress, config.rpcPort)
rpcHttpServer = RpcHttpServer.new()
# Note: Set maxRequestBodySize to 4MB instead of 1MB as there are blocks
# that reach that limit (in hex, for gossip method).
rpcHttpServer.addHttpServer(ta, maxRequestBodySize = 4 * 1_048_576)

setupRpcServer(rpcHttpServer)

if config.wsEnabled:
let
ta = initTAddress(config.rpcAddress, config.wsPort)
rpcWsServer = newRpcWebSocketServer(ta, compression = config.wsCompression)

rpcWsServer.installDiscoveryApiHandlers(d)
rpcWsServer.installWeb3ApiHandlers()
if node.stateNetwork.isSome():
rpcWsServer.installPortalApiHandlers(
node.stateNetwork.value.portalProtocol, "state"
)
if node.historyNetwork.isSome():
rpcWsServer.installEthApiHandlers(
node.historyNetwork.value, node.beaconLightClient, node.stateNetwork
)
rpcWsServer.installPortalApiHandlers(
node.historyNetwork.value.portalProtocol, "history"
)
rpcWsServer.installPortalDebugApiHandlers(
node.historyNetwork.value.portalProtocol, "history"
)
if node.beaconNetwork.isSome():
rpcWsServer.installPortalApiHandlers(
node.beaconNetwork.value.portalProtocol, "beacon"
)

rpcWsServer.start()
setupRpcServer(rpcWsServer)

runForever()

Expand Down

0 comments on commit 5dedfba

Please sign in to comment.