This commit is contained in:
jangko 2021-08-05 14:11:14 +07:00
commit 7213d3e67a
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 27 additions and 10 deletions

View File

@ -8,13 +8,15 @@
{.push raises: [Defect].} {.push raises: [Defect].}
import import
confutils, confutils/std/net, chronicles, uri, confutils, confutils/std/net, chronicles,
eth/keys, eth/net/nat, eth/p2p/discoveryv5/[enr, node] eth/keys, eth/net/nat, eth/p2p/discoveryv5/[enr, node],
json_rpc/rpcproxy
const const
DefaultListenAddress* = (static ValidIpAddress.init("0.0.0.0")) DefaultListenAddress* = (static ValidIpAddress.init("0.0.0.0"))
DefaultAdminListenAddress* = (static ValidIpAddress.init("127.0.0.1")) DefaultAdminListenAddress* = (static ValidIpAddress.init("127.0.0.1"))
DefaultProxyAddress* = (static "http://127.0.0.1:8546") DefaultProxyAddress* = (static "http://127.0.0.1:8546")
DefaultClientConfig* = getHttpClientConfig(DefaultProxyAddress)
type type
PortalCmd* = enum PortalCmd* = enum
@ -96,9 +98,9 @@ type
# it makes little sense to have default value here in final release, but until then # it makes little sense to have default value here in final release, but until then
# it would be troublesome to add some fake uri param every time # it would be troublesome to add some fake uri param every time
proxyUri* {. proxyUri* {.
defaultValue: DefaultProxyAddress defaultValue: DefaultClientConfig
desc: "uri of client to get data for unimplemented rpc methods" desc: "uri of client to get data for unimplemented rpc methods"
name: "proxy-uri" .}: string name: "proxy-uri" .}: ClientConfig
case cmd* {. case cmd* {.
command command
@ -141,3 +143,18 @@ proc parseCmdArg*(T: type PrivateKey, p: TaintedString): T
proc completeCmdArg*(T: type PrivateKey, val: TaintedString): seq[string] = proc completeCmdArg*(T: type PrivateKey, val: TaintedString): seq[string] =
return @[] return @[]
proc parseCmdArg*(T: type ClientConfig, p: TaintedString): T
{.raises: [Defect, ConfigurationError].} =
let uri = parseUri(p)
if (uri.scheme == "http" or uri.scheme == "https"):
getHttpClientConfig(p)
elif (uri.scheme == "ws" or uri.scheme == "wss"):
getWebSocketClientConfig(p)
else:
raise newException(
ConfigurationError, "Proxy uri should have defined scheme (http/https/ws/wss)"
)
proc completeCmdArg*(T: type ClientConfig, val: TaintedString): seq[string] =
return @[]

View File

@ -68,11 +68,11 @@ proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
if config.rpcEnabled: if config.rpcEnabled:
let ta = initTAddress(config.rpcAddress, config.rpcPort) let ta = initTAddress(config.rpcAddress, config.rpcPort)
var rpcHttpServerWithProxy = newRpcHttpProxy([ta]) var rpcHttpServerWithProxy = RpcProxy.new([ta], config.proxyUri)
rpcHttpServerWithProxy.installEthApiHandlers() rpcHttpServerWithProxy.installEthApiHandlers()
# 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(config.proxyUri) waitFor rpcHttpServerWithProxy.start()
let bridgeClient = initializeBridgeClient(config.bridgeUri) let bridgeClient = initializeBridgeClient(config.bridgeUri)

View File

@ -20,7 +20,7 @@ import
# Can be done by just forwarding the rpc call, or by adding a call here, but # Can be done by just forwarding the rpc call, or by adding a call here, but
# that would introduce a unnecessary serializing/deserializing step. # that would introduce a unnecessary serializing/deserializing step.
proc installEthApiHandlers*(rpcServerWithProxy: var RpcHttpProxy) proc installEthApiHandlers*(rpcServerWithProxy: var RpcProxy)
{.raises: [Defect, CatchableError].} = {.raises: [Defect, CatchableError].} =
# Supported API # Supported API
@ -96,4 +96,4 @@ proc installEthApiHandlers*(rpcServerWithProxy: var RpcHttpProxy)
rpcServerWithProxy.registerProxyMethod("eth_syncing") rpcServerWithProxy.registerProxyMethod("eth_syncing")
rpcServerWithProxy.registerProxyMethod("eth_uninstallFilter") rpcServerWithProxy.registerProxyMethod("eth_uninstallFilter")

2
vendor/nim-json-rpc vendored

@ -1 +1 @@
Subproject commit a138c410c5c482ba8352a19e2e3b8d1850d4823f Subproject commit a1715e33ac6f3e2951cdae9643ebad393fb58eb2

2
vendor/nim-websock vendored

@ -1 +1 @@
Subproject commit eabf183e6de46ebea3087bb860ab03cf6dba44ac Subproject commit 00440b6effcdfd1b75bfcca1b65d80a3ca298606