From 5e3ffc468b4e9b27a9c914208525497c856e3e49 Mon Sep 17 00:00:00 2001 From: Shahana Farooqui Date: Sat, 15 Jul 2023 00:22:14 -0700 Subject: [PATCH] plugins/clnrest: removing notifications queue in favor of websocket server --- plugins/clnrest/README.md | 3 --- plugins/clnrest/utilities/rpc_plugin.py | 14 -------------- plugins/clnrest/utilities/rpc_routes.py | 16 +--------------- 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/plugins/clnrest/README.md b/plugins/clnrest/README.md index c83abd115..a09e7523a 100644 --- a/plugins/clnrest/README.md +++ b/plugins/clnrest/README.md @@ -26,9 +26,6 @@ If `rest-port` is not specified, the plugin will disable itself. With the default configurations, the Swagger user interface will be available at https://127.0.0.1:3010/. The POST method requires `rune` and `nodeid` headers for authorization. ### cURL -Example curl command for GET: - `curl -k https://127.0.0.1:3010/v1/notifications` - Example curl command for POST will also require `rune` and `nodeid` headers like below: `curl -k -X POST 'https://127.0.0.1:3010/v1/getinfo' -H 'Rune: ' -H 'Nodeid: '` diff --git a/plugins/clnrest/utilities/rpc_plugin.py b/plugins/clnrest/utilities/rpc_plugin.py index fb45cf0b8..c376ded2e 100644 --- a/plugins/clnrest/utilities/rpc_plugin.py +++ b/plugins/clnrest/utilities/rpc_plugin.py @@ -1,23 +1,9 @@ import os -import sys -from multiprocessing import Manager from pyln.client import Plugin plugin = Plugin(autopatch=False) -manager = Manager() -queue = manager.Queue() plugin.add_option(name="rest-certs", default=os.getcwd(), description="Path for certificates (for https)", opt_type="string", deprecated=False) plugin.add_option(name="rest-protocol", default="https", description="REST server protocol", opt_type="string", deprecated=False) plugin.add_option(name="rest-host", default="127.0.0.1", description="REST server host", opt_type="string", deprecated=False) plugin.add_option(name="rest-port", default=None, description="REST server port to listen", opt_type="int", deprecated=False) - - -@plugin.subscribe("*") -def on_any_notification(request, **kwargs): - plugin.log("Notification: {}".format(kwargs), "debug") - if request.method == 'shutdown': - # A plugin which subscribes to shutdown is expected to exit itself. - sys.exit(0) - else: - queue.put(str(kwargs) + "\n") diff --git a/plugins/clnrest/utilities/rpc_routes.py b/plugins/clnrest/utilities/rpc_routes.py index 11a5da3e3..5b26885e8 100644 --- a/plugins/clnrest/utilities/rpc_routes.py +++ b/plugins/clnrest/utilities/rpc_routes.py @@ -1,5 +1,5 @@ import json5 -from flask import request, make_response, Response, stream_with_context +from flask import request, make_response from flask_restx import Namespace, Resource from .shared import call_rpc_method, verify_rune, process_help_response from .rpc_plugin import plugin @@ -56,17 +56,3 @@ class RpcMethodResource(Resource): except Exception as err: plugin.log(f"Error: {err}", "error") return json5.loads(str(err)), 500 - - -@rpcns.route("/notifications") -class NotificationsResource(Resource): - def get(self): - try: - def notifications_stream(): - while True: - from .rpc_plugin import queue - yield queue.get() - return Response(stream_with_context(notifications_stream()), mimetype="text/event-stream") - - except Exception as err: - return json5.loads(str(err)), 500