parent
82f99dc3c0
commit
ec1af91370
|
@ -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
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue