[FEATURE] Stub for bridge client (#739)
* [FEATURE] Stub for bridge client * [FEATURE] Add client to fluffy runner * [FEATURE] Fix params in logs * [FEATURE] Rename config option
This commit is contained in:
parent
6574d5187d
commit
65ea8a12a9
|
@ -87,6 +87,11 @@ type
|
|||
defaultValue: DefaultAdminListenAddress
|
||||
name: "rpc-address" }: ValidIpAddress
|
||||
|
||||
bridgeUri* {.
|
||||
defaultValue: none(string)
|
||||
desc: "if provided, enables getting data from bridge node"
|
||||
name: "bridge-client-uri" .}: Option[string]
|
||||
|
||||
case cmd* {.
|
||||
command
|
||||
defaultValue: noCommand .}: PortalCmd
|
||||
|
|
|
@ -9,11 +9,27 @@
|
|||
|
||||
import
|
||||
confutils, confutils/std/net, chronicles, chronicles/topics_registry,
|
||||
chronos, metrics, metrics/chronos_httpserver, json_rpc/servers/httpserver,
|
||||
chronos, metrics, metrics/chronos_httpserver, json_rpc/clients/httpclient, json_rpc/servers/httpserver,
|
||||
eth/keys, eth/net/nat,
|
||||
eth/p2p/discoveryv5/protocol as discv5_protocol,
|
||||
eth/p2p/portal/protocol as portal_protocol,
|
||||
./conf, ./rpc/eth_api
|
||||
./conf, ./rpc/eth_api, ./rpc/bridge_client
|
||||
|
||||
|
||||
proc initializeBridgeClient(maybeUri: Option[string]): Option[BridgeClient] =
|
||||
try:
|
||||
if (maybeUri.isSome()):
|
||||
let uri = maybeUri.unsafeGet()
|
||||
# TODO: Add possiblity to start client on differnt transports based on uri.
|
||||
let httpClient = newRpcHttpClient()
|
||||
waitFor httpClient.connect(uri)
|
||||
notice "Initialized bridge client:", uri = uri
|
||||
return some[BridgeClient](httpClient)
|
||||
else:
|
||||
return none(BridgeClient)
|
||||
except CatchableError as err:
|
||||
notice "Failed to initialize bridge client", error = err.msg
|
||||
return none(BridgeClient)
|
||||
|
||||
proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
|
||||
let
|
||||
|
@ -58,6 +74,8 @@ proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
|
|||
rpcHttpServer.installEthApiHandlers()
|
||||
rpcHttpServer.start()
|
||||
|
||||
let bridgeClient = initializeBridgeClient(config.bridgeUri)
|
||||
|
||||
d.start()
|
||||
|
||||
runForever()
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# Nimbus
|
||||
# Copyright (c) 2021 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
std/json,
|
||||
eth/common, chronos, json_rpc/rpcclient
|
||||
|
||||
# Specification of api https://github.com/ethereum/stateless-ethereum-specs/blob/master/portal-bridge-nodes.md#api
|
||||
# TODO after nethermind plugin will be ready we can get few responses from those endpoints, to create mock client to test if we
|
||||
# properly parse respones
|
||||
type
|
||||
BridgeClient* = RpcClient
|
||||
|
||||
# bridge_waitNewCanonicalChain
|
||||
proc waitNewCanonicalChain*(bridgeClient: BridgeClient): Future[void] {.async, raises: [Defect, CatchableError].} = discard
|
||||
|
||||
#bridge_getBlockChanges
|
||||
proc getBlockChanges*(bridgeClient: BridgeClient, blockHash: Hash256): Future[AccessList] {.async, raises: [Defect, CatchableError].} = discard
|
||||
|
||||
#bridge_getItemWitness"
|
||||
proc getItemWitness*(bridgeClient: BridgeClient, blockHash: Hash256, acctAddr: EthAddress, slotAddr: StorageKey):
|
||||
Future[seq[seq[byte]]] {.async, raises: [Defect, CatchableError].} = discard
|
||||
|
||||
#bridge_getNextItem
|
||||
proc getNextItem*(bridgeClient: BridgeClient, blockHash: Hash256, acctAddr: EthAddress, slotAddr: StorageKey):
|
||||
Future[(EthAddress, StorageKey)] {.async, raises: [Defect, CatchableError].} = discard
|
||||
|
||||
proc close*(bridgeClient: BridgeClient): Future[void] {.async, raises: [Defect, CatchableError].} =
|
||||
await bridgeClient.close()
|
Loading…
Reference in New Issue