From 8bcb0acf1a6995de201d81641018078498738ea9 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 16 Aug 2023 14:02:22 +0530 Subject: [PATCH] test(rln-relay): rpc handler to support waku rln relay (#1852) --- waku/node/jsonrpc/relay/handlers.nim | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/waku/node/jsonrpc/relay/handlers.nim b/waku/node/jsonrpc/relay/handlers.nim index e4ec71dd94..8da7269958 100644 --- a/waku/node/jsonrpc/relay/handlers.nim +++ b/waku/node/jsonrpc/relay/handlers.nim @@ -17,6 +17,13 @@ import ../../message_cache, ../message +from std/times import getTime +from std/times import toUnix + +when defined(rln): + import + ../../../waku_rln_relay + logScope: topics = "waku node jsonrpc relay_api" @@ -77,7 +84,7 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC if payloadRes.isErr(): raise newException(ValueError, "invalid payload format: " & payloadRes.error) - let message = WakuMessage( + var message = WakuMessage( payload: payloadRes.value, # TODO: Fail if the message doesn't have a content topic contentTopic: msg.contentTopic.get(DefaultContentTopic), @@ -85,6 +92,13 @@ proc installRelayApiHandlers*(node: WakuNode, server: RpcServer, cache: MessageC timestamp: msg.timestamp.get(Timestamp(0)), ephemeral: msg.ephemeral.get(false) ) + + when defined(rln): + if not node.wakuRlnRelay.isNil(): + let success = node.wakuRlnRelay.appendRLNProof(message, + float64(getTime().toUnix())) + if not success: + raise newException(ValueError, "Failed to append RLN proof to message") let publishFut = node.publish(topic, message)