mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
plugin: Add a list of notification topics registered by plugin
We will eventually start emitting and dispatching custom notifications from plugins just like we dispatch internal notifications. In order to get reasonable error messages we need to make sure that the topics plugins are asking for were correctly registered. When doing this we don't really care about whether the plugin that registered the notification is still alive or not (it might have died, but subscribers should stay up and running), so we keep a list of all topics attached to the `struct plugins` which gathers global plugin information.
This commit is contained in:
committed by
Rusty Russell
parent
29155c2fe8
commit
083b41f090
@@ -223,6 +223,7 @@ class Plugin(object):
|
||||
}
|
||||
|
||||
self.options: Dict[str, Dict[str, Any]] = {}
|
||||
self.notification_topics: List[str] = []
|
||||
|
||||
def convert_featurebits(
|
||||
bits: Optional[Union[int, str, bytes]]) -> Optional[str]:
|
||||
@@ -420,6 +421,11 @@ class Plugin(object):
|
||||
self.add_option(name, None, description, opt_type="flag",
|
||||
deprecated=deprecated)
|
||||
|
||||
def add_notification_topic(self, topic: str):
|
||||
"""Announce that the plugin will emit notifications for the topic.
|
||||
"""
|
||||
self.notification_topics.append(topic)
|
||||
|
||||
def get_option(self, name: str) -> str:
|
||||
if name not in self.options:
|
||||
raise ValueError("No option with name {} registered".format(name))
|
||||
@@ -898,6 +904,9 @@ class Plugin(object):
|
||||
'subscriptions': list(self.subscriptions.keys()),
|
||||
'hooks': hooks,
|
||||
'dynamic': self.dynamic,
|
||||
'notifications': [
|
||||
{"method": name} for name in self.notification_topics
|
||||
],
|
||||
}
|
||||
|
||||
# Compact the features a bit, not important.
|
||||
|
||||
Reference in New Issue
Block a user