mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
[FEATURE] Use rpc proxy (#747)
This commit is contained in:
parent
a59a2c61b6
commit
1c5c2cba8b
@ -14,6 +14,7 @@ import
|
|||||||
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")
|
||||||
|
|
||||||
type
|
type
|
||||||
PortalCmd* = enum
|
PortalCmd* = enum
|
||||||
@ -92,6 +93,13 @@ type
|
|||||||
desc: "if provided, enables getting data from bridge node"
|
desc: "if provided, enables getting data from bridge node"
|
||||||
name: "bridge-client-uri" .}: Option[string]
|
name: "bridge-client-uri" .}: Option[string]
|
||||||
|
|
||||||
|
# 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
|
||||||
|
proxyUri* {.
|
||||||
|
defaultValue: DefaultProxyAddress
|
||||||
|
desc: "uri of client to get data for unimplemented rpc methods"
|
||||||
|
name: "proxy-uri" .}: string
|
||||||
|
|
||||||
case cmd* {.
|
case cmd* {.
|
||||||
command
|
command
|
||||||
defaultValue: noCommand .}: PortalCmd
|
defaultValue: noCommand .}: PortalCmd
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
confutils, confutils/std/net, chronicles, chronicles/topics_registry,
|
confutils, confutils/std/net, chronicles, chronicles/topics_registry,
|
||||||
chronos, metrics, metrics/chronos_httpserver, json_rpc/clients/httpclient, json_rpc/servers/httpserver,
|
chronos, metrics, metrics/chronos_httpserver, json_rpc/clients/httpclient, json_rpc/rpcproxy,
|
||||||
eth/keys, eth/net/nat,
|
eth/keys, eth/net/nat,
|
||||||
eth/p2p/discoveryv5/protocol as discv5_protocol,
|
eth/p2p/discoveryv5/protocol as discv5_protocol,
|
||||||
eth/p2p/portal/protocol as portal_protocol,
|
eth/p2p/portal/protocol as portal_protocol,
|
||||||
@ -68,11 +68,12 @@ proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
|
|||||||
except Exception as exc: raiseAssert exc.msg
|
except Exception as exc: raiseAssert exc.msg
|
||||||
|
|
||||||
if config.rpcEnabled:
|
if config.rpcEnabled:
|
||||||
let
|
let ta = initTAddress(config.rpcAddress, config.rpcPort)
|
||||||
ta = initTAddress(config.rpcAddress, config.rpcPort)
|
var rpcHttpServerWithProxy = newRpcHttpProxy([$ta])
|
||||||
rpcHttpServer = newRpcHttpServer([ta])
|
rpcHttpServerWithProxy.installEthApiHandlers()
|
||||||
rpcHttpServer.installEthApiHandlers()
|
# TODO for now we can only proxy to local node (or remote one without ssl) to make it possible
|
||||||
rpcHttpServer.start()
|
# 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)
|
||||||
|
|
||||||
let bridgeClient = initializeBridgeClient(config.bridgeUri)
|
let bridgeClient = initializeBridgeClient(config.bridgeUri)
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
json_rpc/rpcserver
|
json_rpc/rpcproxy
|
||||||
|
|
||||||
# Subset of Eth JSON-RPC API: https://eth.wiki/json-rpc/API
|
# Subset of Eth JSON-RPC API: https://eth.wiki/json-rpc/API
|
||||||
# Supported subset will eventually be found here:
|
# Supported subset will eventually be found here:
|
||||||
@ -20,80 +20,80 @@ 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*(rpcServer: RpcServer)
|
proc installEthApiHandlers*(rpcServerWithProxy: var RpcHttpProxy)
|
||||||
{.raises: [Defect, CatchableError].} =
|
{.raises: [Defect, CatchableError].} =
|
||||||
|
|
||||||
# Supported API
|
# Supported API
|
||||||
rpcServer.rpc("eth_blockNumber") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_blockNumber")
|
||||||
|
|
||||||
rpcServer.rpc("eth_call") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_call")
|
||||||
|
|
||||||
rpcServer.rpc("eth_chainId") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_chainId")
|
||||||
|
|
||||||
rpcServer.rpc("eth_estimateGas") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_estimateGas")
|
||||||
|
|
||||||
rpcServer.rpc("eth_feeHistory") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_feeHistory")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getBalance") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getBalance")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getBlockByHash") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getBlockByHash")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getBlockByNumber") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getBlockByNumber")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getBlockTransactionCountByHash") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getBlockTransactionCountByHash")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getBlockTransactionCountByNumber") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getBlockTransactionCountByNumber")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getCode") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getCode")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getRawTransactionByHash") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getRawTransactionByHash")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getRawTransactionByBlockHashAndIndex") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getRawTransactionByBlockHashAndIndex")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getRawTransactionByBlockNumberAndIndex") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getRawTransactionByBlockNumberAndIndex")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getStorageAt") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getStorageAt")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getTransactionByBlockHashAndIndex") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionByBlockHashAndIndex")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getTransactionByBlockNumberAndIndex") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionByBlockNumberAndIndex")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getTransactionByHash") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionByHash")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getTransactionCount") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionCount")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getTransactionReceipt") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getTransactionReceipt")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getUncleByBlockHashAndIndex") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getUncleByBlockHashAndIndex")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getUncleByBlockNumberAndIndex") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getUncleByBlockNumberAndIndex")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getUncleCountByBlockHash") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getUncleCountByBlockHash")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getUncleCountByBlockNumber") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getUncleCountByBlockNumber")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getProof") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getProof")
|
||||||
|
|
||||||
rpcServer.rpc("eth_sendRawTransaction") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_sendRawTransaction")
|
||||||
|
|
||||||
# Optional API
|
# Optional API
|
||||||
|
|
||||||
rpcServer.rpc("eth_gasPrice") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_gasPrice")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getFilterChanges") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getFilterChanges")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getFilterLogs") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getFilterLogs")
|
||||||
|
|
||||||
rpcServer.rpc("eth_getLogs") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_getLogs")
|
||||||
|
|
||||||
rpcServer.rpc("eth_newBlockFilter") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_newBlockFilter")
|
||||||
|
|
||||||
rpcServer.rpc("eth_newFilter") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_newFilter")
|
||||||
|
|
||||||
rpcServer.rpc("eth_newPendingTransactionFilter") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_newPendingTransactionFilter")
|
||||||
|
|
||||||
rpcServer.rpc("eth_pendingTransactions") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_pendingTransactions")
|
||||||
|
|
||||||
rpcServer.rpc("eth_syncing") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_syncing")
|
||||||
|
|
||||||
rpcServer.rpc("eth_uninstallFilter") do (): discard
|
rpcServerWithProxy.registerProxyMethod("eth_uninstallFilter")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user