From 3f74f084c306479ddc9afa8ae7bd5f9e683dfaf7 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Fri, 16 Dec 2022 11:00:10 +0100 Subject: [PATCH] Add LocalContent call to Portal JSON-RPC API (#1383) --- fluffy/rpc/rpc_calls/rpc_portal_calls.nim | 2 ++ fluffy/rpc/rpc_portal_api.nim | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/fluffy/rpc/rpc_calls/rpc_portal_calls.nim b/fluffy/rpc/rpc_calls/rpc_portal_calls.nim index 3cdae6d46..2b39fd195 100644 --- a/fluffy/rpc/rpc_calls/rpc_portal_calls.nim +++ b/fluffy/rpc/rpc_calls/rpc_portal_calls.nim @@ -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 diff --git a/fluffy/rpc/rpc_portal_api.nim b/fluffy/rpc/rpc_portal_api.nim index e3b97a2e2..bacc821d0 100644 --- a/fluffy/rpc/rpc_portal_api.nim +++ b/fluffy/rpc/rpc_portal_api.nim @@ -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"