Add nimbus_addPeer rpc call

This commit is contained in:
Nikolay Mitev 2022-06-07 12:20:02 +02:00 committed by zah
parent 730013bde3
commit 84a89e918a
1 changed files with 9 additions and 2 deletions

View File

@ -9,8 +9,8 @@
import
std/[strutils, tables],
nimcrypto, eth/common as eth_common, stint, json_rpc/server,
eth/p2p, eth/p2p/enode,
nimcrypto, eth/common as eth_common, stint, json_rpc/server, json_rpc/errors,
eth/p2p, eth/p2p/enode, eth/p2p/peer_pool,
../config, ./hexstrings
type
@ -57,3 +57,10 @@ proc setupCommonRpc*(node: EthereumNode, conf: NimbusConf, server: RpcServer) =
listener: $enode.address.tcpPort
)
)
server.rpc("nimbus_addPeer") do(enode: string) -> bool:
var res = ENode.fromString(enode)
if res.isOk:
asyncCheck node.peerPool.connectToNode(newNode(res.get()))
return true
raise (ref InvalidRequest)(code: -32602, msg: "Invalid ENode")