implement "net_nodeInfo" rpc

fixes #569
This commit is contained in:
jangko 2021-05-19 16:35:13 +07:00
parent 82f99dc3c0
commit ec1af91370
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 28 additions and 3 deletions

View File

@ -8,10 +8,22 @@
# those terms. # those terms.
import import
strutils, tables, std/[strutils, tables],
nimcrypto, eth/common as eth_common, stint, json_rpc/server, nimcrypto, eth/common as eth_common, stint, json_rpc/server,
eth/p2p, eth/p2p, eth/p2p/enode,
../config, hexstrings ../config, ./hexstrings
type
NodePorts = object
discovery: string
listener : string
NodeInfo = object
id : string # UInt256 hex
name : string
enode : string # Enode string
ip : string # address string
ports : NodePorts
proc setupCommonRPC*(node: EthereumNode, server: RpcServer) = proc setupCommonRPC*(node: EthereumNode, server: RpcServer) =
server.rpc("web3_clientVersion") do() -> string: server.rpc("web3_clientVersion") do() -> string:
@ -33,3 +45,16 @@ proc setupCommonRPC*(node: EthereumNode, server: RpcServer) =
server.rpc("net_peerCount") do() -> HexQuantityStr: server.rpc("net_peerCount") do() -> HexQuantityStr:
let peerCount = uint node.peerPool.connectedNodes.len let peerCount = uint node.peerPool.connectedNodes.len
result = encodeQuantity(peerCount) result = encodeQuantity(peerCount)
server.rpc("net_nodeInfo") do() -> NodeInfo:
let enode = toEnode(node)
result = NodeInfo(
id: node.discovery.thisNode.id.toHex,
name: NimbusIdent,
enode: $enode,
ip: $enode.address.ip,
ports: NodePorts(
discovery: $enode.address.udpPort,
listener: $enode.address.tcpPort
)
)