@@ -59,6 +59,7 @@ def __init__(self, name: str, func: Callable[..., JSONType],
5959 self .description = description
6060 self .before : List [str ] = []
6161 self .after : List [str ] = []
62+ self .filters : Optional [List [Union [str , int ]]] = None
6263
6364 def get_usage (self ):
6465 # Handles out-of-order use of parameters like:
@@ -546,7 +547,8 @@ def decorator(f: Callable[..., JSONType]) -> Callable[..., JSONType]:
546547 def add_hook (self , name : str , func : Callable [..., JSONType ],
547548 background : bool = False ,
548549 before : Optional [List [str ]] = None ,
549- after : Optional [List [str ]] = None ) -> None :
550+ after : Optional [List [str ]] = None ,
551+ filters : Optional [List [Union [str , int ]]] = None ) -> None :
550552 """Register a hook that is called synchronously by lightningd on events
551553 """
552554 if name in self .methods :
@@ -574,17 +576,19 @@ def add_hook(self, name: str, func: Callable[..., JSONType],
574576 method .after = []
575577 if after :
576578 method .after = after
579+ method .filters = filters
577580 self .methods [name ] = method
578581
579582 def hook (self , method_name : str ,
580583 before : List [str ] = None ,
581- after : List [str ] = None ) -> JsonDecoratorType :
584+ after : List [str ] = None ,
585+ filters : List [Union [str , int ]] = None ) -> JsonDecoratorType :
582586 """Decorator to add a plugin hook to the dispatch table.
583587
584588 Internally uses add_hook.
585589 """
586590 def decorator (f : Callable [..., JSONType ]) -> Callable [..., JSONType ]:
587- self .add_hook (method_name , f , background = False , before = before , after = after )
591+ self .add_hook (method_name , f , background = False , before = before , after = after , filters = filters )
588592 return f
589593 return decorator
590594
@@ -961,9 +965,12 @@ def _getmanifest(self, **kwargs) -> JSONType:
961965 continue
962966
963967 if method .mtype == MethodType .HOOK :
964- hooks .append ({'name' : method .name ,
965- 'before' : method .before ,
966- 'after' : method .after })
968+ hook = {'name' : method .name ,
969+ 'before' : method .before ,
970+ 'after' : method .after }
971+ if method .filters :
972+ hook ['filters' ] = method .filters
973+ hooks .append (hook )
967974 continue
968975
969976 # For compatibility with lightningd prior to 24.08, we must
0 commit comments