Skip to content

Commit

Permalink
Use admin prefix for nodeInfo and addPeer JSON-RPCs (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeme authored Oct 3, 2023
1 parent 395580f commit 1bb389a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion hive_integration/nimbus/enode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Immediately abort the script on any error encountered
set -e

TARGET_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"net_nodeInfo","params":[],"id":1}' "localhost:8545" )
TARGET_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}' "localhost:8545" )

TARGET_ENODE=$(echo ${TARGET_RESPONSE}| jq -r '.result.enode')
echo "$TARGET_ENODE"
29 changes: 16 additions & 13 deletions nimbus/rpc/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,24 @@ proc setupCommonRpc*(node: EthereumNode, conf: NimbusConf, server: RpcServer) =
let peerCount = uint node.numPeers
result = encodeQuantity(peerCount)

server.rpc("net_nodeInfo") do() -> NodeInfo:
let enode = toENode(node)
let nodeId = toNodeId(node.keys.pubkey)
result = NodeInfo(
id: nodeId.toHex,
name: conf.agentString,
enode: $enode,
ip: $enode.address.ip,
ports: NodePorts(
discovery: $enode.address.udpPort,
listener: $enode.address.tcpPort
server.rpc("admin_nodeInfo") do() -> NodeInfo:
let
enode = toENode(node)
nodeId = toNodeId(node.keys.pubkey)
nodeInfo = NodeInfo(
id: nodeId.toHex,
name: conf.agentString,
enode: $enode,
ip: $enode.address.ip,
ports: NodePorts(
discovery: $enode.address.udpPort,
listener: $enode.address.tcpPort
)
)
)

server.rpc("nimbus_addPeer") do(enode: string) -> bool:
return nodeInfo

server.rpc("admin_addPeer") do(enode: string) -> bool:
var res = ENode.fromString(enode)
if res.isOk:
asyncSpawn node.connectToNode(res.get())
Expand Down

0 comments on commit 1bb389a

Please sign in to comment.