From 1f38f43c4d68cfbce2453a92db50f0c4d41f1c87 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Thu, 14 Jul 2022 21:23:38 +0100 Subject: [PATCH] plugin: add hooks example Signed-off-by: Vincenzo Palazzo --- .../cln_plugin/example/cln_plugin_class_example.dart | 11 ++++++++++- packages/cln_plugin/example/cln_plugin_example.dart | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/cln_plugin/example/cln_plugin_class_example.dart b/packages/cln_plugin/example/cln_plugin_class_example.dart index 36dc026..ea7d093 100644 --- a/packages/cln_plugin/example/cln_plugin_class_example.dart +++ b/packages/cln_plugin/example/cln_plugin_class_example.dart @@ -5,7 +5,6 @@ import 'package:cln_plugin/cln_plugin.dart'; /// /// This involve the possibility to develop in a more OOP style the /// code, but also to keep the code clean a simple to read. - class MyPlugin extends Plugin { /// This is a method that is registered to be called by the plugin /// where core lightning will require it. @@ -17,6 +16,12 @@ class MyPlugin extends Plugin { }); } + Future> onRpcCommand( + Plugin plugin, Map request) { + log(level: "info", message: "hook info"); + return Future(() => {"result": "continue"}); + } + /// This is a method that is subscribed to be called in response to /// a notification emitted by core lightning. Future> notifyMethod( @@ -44,6 +49,10 @@ class MyPlugin extends Plugin { /// This is the standard way to subscribe to a core lightning /// notification. registerSubscriptions(event: 'connect', callback: notifyMethod); + + /// Register an hook that it is triggered by core lightning when + /// any rpc command is executed. + registerHook(name: "rpc_command", callback: onRpcCommand); } } diff --git a/packages/cln_plugin/example/cln_plugin_example.dart b/packages/cln_plugin/example/cln_plugin_example.dart index e2470bb..c0f7397 100644 --- a/packages/cln_plugin/example/cln_plugin_example.dart +++ b/packages/cln_plugin/example/cln_plugin_example.dart @@ -30,5 +30,11 @@ void main() { def: "World", description: "What name should I call you?", deprecated: false); + plugin.registerHook( + name: "rpc_command", + callback: (plugin, request) { + plugin.log(level: "info", message: "hook info"); + return Future(() => {"result": "continue"}); + }); plugin.start(); }