Add Portal eth json-rpc stubs and Portal content file (#720)
* Bump nim-json-rpc module * Add eth json rpc stubs * Add portal content file
This commit is contained in:
parent
cad1b5a678
commit
4ce9b5883c
|
@ -0,0 +1,48 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
# https://github.com/ethereum/stateless-ethereum-specs/blob/master/state-network.md#content
|
||||||
|
|
||||||
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
import
|
||||||
|
nimcrypto/[sha2, hash], eth/ssz/ssz_serialization
|
||||||
|
|
||||||
|
type
|
||||||
|
ByteList* = List[byte, 2048]
|
||||||
|
|
||||||
|
ContentType* = enum
|
||||||
|
Account = 0x01
|
||||||
|
ContractStorage = 0x02
|
||||||
|
ContractBytecode = 0x03
|
||||||
|
|
||||||
|
NetworkId* = uint16
|
||||||
|
|
||||||
|
NodeHash* = List[byte, 32] # MDigest[32 * 8] - sha256
|
||||||
|
|
||||||
|
CodeHash* = List[byte, 32] # MDigest[32 * 8] - keccak256
|
||||||
|
|
||||||
|
Address* = List[byte, 20]
|
||||||
|
|
||||||
|
ContentKey* = object
|
||||||
|
# TODO: How shall we deal with the different ContentKey structures?
|
||||||
|
networkId: NetworkId
|
||||||
|
contentType: ContentType
|
||||||
|
address: Address
|
||||||
|
triePath: ByteList
|
||||||
|
nodeHash: NodeHash
|
||||||
|
|
||||||
|
ContentId* = MDigest[32 * 8]
|
||||||
|
|
||||||
|
template toSszType*(x: auto): auto =
|
||||||
|
mixin toSszType
|
||||||
|
|
||||||
|
when x is ContentType: uint8(x)
|
||||||
|
else: x
|
||||||
|
|
||||||
|
func toContentId*(contentKey: ContentKey): ContentId =
|
||||||
|
sha2.sha_256.digest(SSZ.encode(contentKey))
|
|
@ -9,11 +9,11 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
confutils, confutils/std/net, chronicles, chronicles/topics_registry,
|
confutils, confutils/std/net, chronicles, chronicles/topics_registry,
|
||||||
chronos, metrics, metrics/chronos_httpserver,
|
chronos, metrics, metrics/chronos_httpserver, json_rpc/servers/httpserver,
|
||||||
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,
|
||||||
./conf
|
./conf, ./rpc/eth_api
|
||||||
|
|
||||||
proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
|
proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
|
||||||
let
|
let
|
||||||
|
@ -51,6 +51,13 @@ proc run(config: PortalConf) {.raises: [CatchableError, Defect].} =
|
||||||
# TODO: Ideally we don't have the Exception here
|
# TODO: Ideally we don't have the Exception here
|
||||||
except Exception as exc: raiseAssert exc.msg
|
except Exception as exc: raiseAssert exc.msg
|
||||||
|
|
||||||
|
if config.rpcEnabled:
|
||||||
|
let
|
||||||
|
ta = initTAddress(config.rpcAddress, config.rpcPort)
|
||||||
|
rpcHttpServer = newRpcHttpServer([ta])
|
||||||
|
rpcHttpServer.installEthApiHandlers()
|
||||||
|
rpcHttpServer.start()
|
||||||
|
|
||||||
d.start()
|
d.start()
|
||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
# 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
|
||||||
|
json_rpc/rpcserver
|
||||||
|
|
||||||
|
# Subset of Eth JSON-RPC API: https://eth.wiki/json-rpc/API
|
||||||
|
# Supported subset will eventually be found here:
|
||||||
|
# https://github.com/ethereum/stateless-ethereum-specs/blob/master/portal-network.md#json-rpc-api
|
||||||
|
#
|
||||||
|
# In order to already support these calls before every part of the Portal
|
||||||
|
# Network is up, one plan is to get the data directly from an external client
|
||||||
|
# through RPC calls. Practically just playing a proxy to that client.
|
||||||
|
# Can be done by just forwarding the rpc call, or by adding a call here, but
|
||||||
|
# that would introduce a unnecessary serializing/deserializing step.
|
||||||
|
|
||||||
|
proc installEthApiHandlers*(rpcServer: RpcServer)
|
||||||
|
{.raises: [Defect, CatchableError].} =
|
||||||
|
|
||||||
|
# Supported API
|
||||||
|
rpcServer.rpc("eth_blockNumber") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_call") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_chainId") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_estimateGas") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_feeHistory") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getBalance") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getBlockByHash") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getBlockByNumber") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getBlockTransactionCountByHash") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getBlockTransactionCountByNumber") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getCode") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getRawTransactionByHash") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getRawTransactionByBlockHashAndIndex") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getRawTransactionByBlockNumberAndIndex") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getStorageAt") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getTransactionByBlockHashAndIndex") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getTransactionByBlockNumberAndIndex") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getTransactionByHash") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getTransactionCount") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getTransactionReceipt") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getUncleByBlockHashAndIndex") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getUncleByBlockNumberAndIndex") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getUncleCountByBlockHash") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getUncleCountByBlockNumber") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getProof") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_sendRawTransaction") do (): discard
|
||||||
|
|
||||||
|
# Optional API
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_gasPrice") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getFilterChanges") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getFilterLogs") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_getLogs") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_newBlockFilter") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_newFilter") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_newPendingTransactionFilter") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_pendingTransactions") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_syncing") do (): discard
|
||||||
|
|
||||||
|
rpcServer.rpc("eth_uninstallFilter") do (): discard
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4eb39203ebd391c77d16a1c387dc8a6b7d90bc69
|
Subproject commit 22c342bcc11515c69d59b53819bd38ab813d9b93
|
Loading…
Reference in New Issue