Add LocalContent call to Portal JSON-RPC API (#1383)

This commit is contained in:
Kim De Mey 2022-12-16 11:00:10 +01:00 committed by GitHub
parent 727b2445b7
commit 3f74f084c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -20,6 +20,7 @@ proc portal_stateOffer(contentKey: string, contentValue: string): int
proc portal_stateRecursiveFindNodes(nodeId: NodeId): seq[Record]
proc portal_stateRecursiveFindContent(contentKey: string): string
proc portal_stateStore(contentKey: string, contentValue: string): bool
proc portal_stateLocalContent(contentKey: string): string
## Portal History Network json-rpc calls
proc portal_historyNodeInfo(): NodeInfo
@ -43,3 +44,4 @@ proc portal_historyOffer(contentKey: string, contentValue: string): int
proc portal_historyRecursiveFindNodes(nodeId: NodeId): seq[Record]
proc portal_historyRecursiveFindContent(contentKey: string): string
proc portal_historyStore(contentKey: string, contentValue: string): bool
proc portal_historyLocalContent(contentKey: string): string

View File

@ -205,3 +205,16 @@ proc installPortalApiHandlers*(
return true
else:
raise newException(ValueError, "Invalid content key")
rpcServer.rpc("portal_" & network & "LocalContent") do(
contentKey: string) -> string:
let
key = ByteList.init(hexToSeqByte(contentKey))
contentId = p.toContentId(key).valueOr:
raise newException(ValueError, "Invalid content key")
let contentResult = p.dbGet(key, contentId)
if contentResult.isOk():
return contentResult.get().toHex()
else:
return "0x0"