Skip to content

Commit

Permalink
plugin: add hooks example
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Jul 14, 2022
1 parent cfeebd1 commit 1f38f43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/cln_plugin/example/cln_plugin_class_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,6 +16,12 @@ class MyPlugin extends Plugin {
});
}

Future<Map<String, Object>> onRpcCommand(
Plugin plugin, Map<String, Object> 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<Map<String, Object>> notifyMethod(
Expand Down Expand Up @@ -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);
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/cln_plugin/example/cln_plugin_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 1f38f43

Please sign in to comment.