Make fluffy rpc portal call compatible with spec (#1258)

This commit is contained in:
KonradStaniec 2022-10-10 15:15:57 +02:00 committed by GitHub
parent 78f7de1344
commit 0a2f1378e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 30 deletions

View File

@ -1,35 +1,35 @@
## Portal State Network json-rpc calls
proc portal_state_nodeInfo(): NodeInfo
proc portal_state_routingTableInfo(): RoutingTableInfo
proc portal_state_lookupEnr(nodeId: NodeId): Record
proc portal_state_addEnrs(enrs: seq[Record]): bool
proc portal_state_ping(enr: Record): tuple[
proc portal_stateNodeInfo(): NodeInfo
proc portal_stateRoutingTableInfo(): RoutingTableInfo
proc portal_stateLookupEnr(nodeId: NodeId): Record
proc portal_stateAddEnrs(enrs: seq[Record]): bool
proc portal_statePing(enr: Record): tuple[
seqNum: uint64, customPayload: string]
proc portal_state_findNodes(enr: Record): seq[Record]
proc portal_state_findContentRaw(enr: Record, contentKey: string): tuple[
proc portal_stateFindNodes(enr: Record): seq[Record]
proc portal_stateFindContentRaw(enr: Record, contentKey: string): tuple[
connectionId: Option[string],
content: Option[string],
enrs: Option[seq[Record]]]
proc portal_state_findContent(enr: Record, contentKey: string): tuple[
proc portal_stateFindContent(enr: Record, contentKey: string): tuple[
content: Option[string],
enrs: Option[seq[Record]]]
proc portal_state_offer(enr: Record, contentKey: string): bool
proc portal_state_recursiveFindNodes(): seq[Record]
proc portal_stateOffer(enr: Record, contentKey: string): bool
proc portal_stateRecursiveFindNodes(): seq[Record]
## Portal History Network json-rpc calls
proc portal_history_nodeInfo(): NodeInfo
proc portal_history_routingTableInfo(): RoutingTableInfo
proc portal_history_lookupEnr(nodeId: NodeId): Record
proc portal_history_addEnrs(enrs: seq[Record]): bool
proc portal_history_ping(enr: Record): tuple[
proc portal_historyNodeInfo(): NodeInfo
proc portal_historyRoutingTableInfo(): RoutingTableInfo
proc portal_historyLookupEnr(nodeId: NodeId): Record
proc portal_historyAddEnrs(enrs: seq[Record]): bool
proc portal_historyPing(enr: Record): tuple[
seqNum: uint64, customPayload: string]
proc portal_history_findNodes(enr: Record): seq[Record]
proc portal_history_findContentRaw(enr: Record, contentKey: string): tuple[
proc portal_historyFindNodes(enr: Record): seq[Record]
proc portal_historyFindContentRaw(enr: Record, contentKey: string): tuple[
connectionId: Option[string],
content: Option[string],
enrs: Option[seq[Record]]]
proc portal_history_findContent(enr: Record, contentKey: string): tuple[
proc portal_historyFindContent(enr: Record, contentKey: string): tuple[
content: Option[string],
enrs: Option[seq[Record]]]
proc portal_history_offer(enr: Record, contentKey: string): bool
proc portal_history_recursiveFindNodes(): seq[Record]
proc portal_historyOffer(enr: Record, contentKey: string): bool
proc portal_historyRecursiveFindNodes(): seq[Record]

View File

@ -29,20 +29,20 @@ proc installPortalApiHandlers*(
## will look something similar as what exists here now:
## https://github.com/ethereum/portal-network-specs/pull/88
rpcServer.rpc("portal_" & network & "_nodeInfo") do() -> NodeInfo:
rpcServer.rpc("portal_" & network & "NodeInfo") do() -> NodeInfo:
return p.routingTable.getNodeInfo()
rpcServer.rpc("portal_" & network & "_routingTableInfo") do() -> RoutingTableInfo:
rpcServer.rpc("portal_" & network & "RoutingTableInfo") do() -> RoutingTableInfo:
return getRoutingTableInfo(p.routingTable)
rpcServer.rpc("portal_" & network & "_lookupEnr") do(nodeId: NodeId) -> Record:
rpcServer.rpc("portal_" & network & "LookupEnr") do(nodeId: NodeId) -> Record:
let lookup = await p.resolve(nodeId)
if lookup.isSome():
return lookup.get().record
else:
raise newException(ValueError, "Record not found in DHT lookup.")
rpcServer.rpc("portal_" & network & "_addEnrs") do(enrs: seq[Record]) -> bool:
rpcServer.rpc("portal_" & network & "AddEnrs") do(enrs: seq[Record]) -> bool:
for enr in enrs:
let nodeRes = newNode(enr)
if nodeRes.isOk():
@ -52,7 +52,7 @@ proc installPortalApiHandlers*(
return true
rpcServer.rpc("portal_" & network & "_ping") do(
rpcServer.rpc("portal_" & network & "Ping") do(
enr: Record) -> tuple[seqNum: uint64, customPayload: string]:
let
node = toNodeWithAddress(enr)
@ -64,7 +64,7 @@ proc installPortalApiHandlers*(
let p = pong.get()
return (p.enrSeq, p.customPayload.asSeq().toHex())
rpcServer.rpc("portal_" & network & "_findNodes") do(
rpcServer.rpc("portal_" & network & "FindNodes") do(
enr: Record, distances: seq[uint16]) -> seq[Record]:
let
node = toNodeWithAddress(enr)
@ -78,7 +78,7 @@ proc installPortalApiHandlers*(
# according to spec, no k:v pair at all?
# Note: `*_findContentRaw` is actually `*_findContent` call according to
# WIP Portal JSON-RPC API specification. Not sure about the best naming here.
rpcServer.rpc("portal_" & network & "_findContentRaw") do(
rpcServer.rpc("portal_" & network & "FindContentRaw") do(
enr: Record, contentKey: string) -> tuple[
connectionId: Option[string],
content: Option[string],
@ -116,7 +116,7 @@ proc installPortalApiHandlers*(
records.get(), node, enrsResultLimit).map(
proc(n: Node): Record = n.record)))
rpcServer.rpc("portal_" & network & "_findContent") do(
rpcServer.rpc("portal_" & network & "FindContent") do(
enr: Record, contentKey: string) -> tuple[
content: Option[string], enrs: Option[seq[Record]]]:
let
@ -138,7 +138,7 @@ proc installPortalApiHandlers*(
none(string),
some(foundContent.nodes.map(proc(n: Node): Record = n.record)))
rpcServer.rpc("portal_" & network & "_offer") do(
rpcServer.rpc("portal_" & network & "Offer") do(
enr: Record, contentKey: string) -> bool:
# Only allow 1 content key for now
let
@ -150,6 +150,6 @@ proc installPortalApiHandlers*(
else:
return true
rpcServer.rpc("portal_" & network & "_recursiveFindNodes") do() -> seq[Record]:
rpcServer.rpc("portal_" & network & "RecursiveFindNodes") do() -> seq[Record]:
let discovered = await p.queryRandom()
return discovered.map(proc(n: Node): Record = n.record)