Have one generic installPortalApiHandlers to be used for different Portal networks (#893)
This commit is contained in:
parent
77cc9b6215
commit
5f4ea7822c
|
@ -103,8 +103,8 @@ proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
|
||||||
var rpcHttpServerWithProxy = RpcProxy.new([ta], config.proxyUri)
|
var rpcHttpServerWithProxy = RpcProxy.new([ta], config.proxyUri)
|
||||||
rpcHttpServerWithProxy.installEthApiHandlers()
|
rpcHttpServerWithProxy.installEthApiHandlers()
|
||||||
rpcHttpServerWithProxy.installDiscoveryApiHandlers(d)
|
rpcHttpServerWithProxy.installDiscoveryApiHandlers(d)
|
||||||
rpcHttpServerWithProxy.installPortalStateApiHandlers(stateNetwork.portalProtocol)
|
rpcHttpServerWithProxy.installPortalApiHandlers(stateNetwork.portalProtocol, "state")
|
||||||
rpcHttpServerWithProxy.installPortalHistoryApiHandlers(historyNetwork.portalProtocol)
|
rpcHttpServerWithProxy.installPortalApiHandlers(stateNetwork.portalProtocol, "history")
|
||||||
# TODO for now we can only proxy to local node (or remote one without ssl) to make it possible
|
# TODO for now we can only proxy to local node (or remote one without ssl) to make it possible
|
||||||
# to call infura https://github.com/status-im/nim-json-rpc/pull/101 needs to get merged for http client to support https/
|
# to call infura https://github.com/status-im/nim-json-rpc/pull/101 needs to get merged for http client to support https/
|
||||||
waitFor rpcHttpServerWithProxy.start()
|
waitFor rpcHttpServerWithProxy.start()
|
||||||
|
|
|
@ -12,26 +12,23 @@ import
|
||||||
../network/wire/portal_protocol,
|
../network/wire/portal_protocol,
|
||||||
./rpc_types
|
./rpc_types
|
||||||
|
|
||||||
# TODO:
|
export rpcserver
|
||||||
# Trying to make this dynamic by passing in a network sub string results in:
|
|
||||||
|
# Note:
|
||||||
|
# Using a string for the network parameter will give an error in the rpc macro:
|
||||||
# Error: Invalid node kind nnkInfix for macros.`$`
|
# Error: Invalid node kind nnkInfix for macros.`$`
|
||||||
proc installPortalStateApiHandlers*(rpcServerWithProxy: var RpcProxy, p: PortalProtocol)
|
# Using a static string works but some sandwich problem seems to be happening,
|
||||||
|
# as the proc becomes generic, where the rpc macro from router.nim can no longer
|
||||||
|
# be found, which is why we export rpcserver which should export router.
|
||||||
|
proc installPortalApiHandlers*(
|
||||||
|
rpcServerWithProxy: var RpcProxy, p: PortalProtocol, network: static string)
|
||||||
{.raises: [Defect, CatchableError].} =
|
{.raises: [Defect, CatchableError].} =
|
||||||
## Portal routing table and portal wire json-rpc API is not yet defined but
|
## Portal routing table and portal wire json-rpc API is not yet defined but
|
||||||
## will look something similar as what exists here now:
|
## will look something similar as what exists here now:
|
||||||
## https://github.com/ethereum/portal-network-specs/pull/88
|
## https://github.com/ethereum/portal-network-specs/pull/88
|
||||||
|
|
||||||
rpcServerWithProxy.rpc("portal_state_nodeInfo") do() -> NodeInfo:
|
rpcServerWithProxy.rpc("portal_" & network & "_nodeInfo") do() -> NodeInfo:
|
||||||
return p.routingTable.getNodeInfo()
|
return p.routingTable.getNodeInfo()
|
||||||
|
|
||||||
rpcServerWithProxy.rpc("portal_state_routingTableInfo") do() -> RoutingTableInfo:
|
rpcServerWithProxy.rpc("portal_" & network & "_routingTableInfo") do() -> RoutingTableInfo:
|
||||||
return getRoutingTableInfo(p.routingTable)
|
|
||||||
|
|
||||||
proc installPortalHistoryApiHandlers*(rpcServerWithProxy: var RpcProxy, p: PortalProtocol)
|
|
||||||
{.raises: [Defect, CatchableError].} =
|
|
||||||
|
|
||||||
rpcServerWithProxy.rpc("portal_history_nodeInfo") do() -> NodeInfo:
|
|
||||||
return p.routingTable.getNodeInfo()
|
|
||||||
|
|
||||||
rpcServerWithProxy.rpc("portal_history_routingTableInfo") do() -> RoutingTableInfo:
|
|
||||||
return getRoutingTableInfo(p.routingTable)
|
return getRoutingTableInfo(p.routingTable)
|
||||||
|
|
Loading…
Reference in New Issue