You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Juno supports plugins that satisfy the `JunoPlugin` interface, enabling developers to extend and customize Juno's behaviour and functionality by dynamically loading external plugins during runtime.
6
+
7
+
The `JunoPlugin` interface provides a structured way for plugins to interact with the blockchain by sending notifications when new blocks are added or reverted. This ensures state consistency, especially during blockchain reorganizations, while abstracting away the complexity of implementing block syncing and revert logic.
8
+
9
+
## JunoPlugin Interface
10
+
11
+
Your plugin must implement the `JunoPlugin` interface, which includes methods for initializing, shutting down, and handling new and reverted blocks.
RevertBlock(from, to *BlockAndStateUpdate, reverseStateDiff *core.StateDiff) error
19
+
}
20
+
```
21
+
22
+
**Init**: Called when the plugin is initialized. This can be used to set up database connections or any other necessary resources.
23
+
24
+
**Shutdown**: Called when the Juno node is shut down. This can be used to clean up resources like database connections.
25
+
26
+
**NewBlock**: Triggered when a new block is synced by the Juno client. Juno will send the block, the corresponding state update, and any new classes. Importantly, Juno waits for the plugin to finish processing this function call before continuing. This ensures that the plugin completes its task before Juno proceeds with the blockchain sync.
27
+
28
+
**RevertBlock**: Called during a blockchain reorganization (reorg). Juno will invoke this method for each block that needs to be reverted. Similar to NewBlock, the client will wait for the plugin to finish handling the revert before moving on to the next block.
29
+
30
+
## Example plugin
31
+
32
+
Here is a basic example of a plugin that satisfies the `JunoPlugin` interface:
33
+
34
+
```go
35
+
// go:generate go build -buildmode=plugin -o ../../build/plugin.so ./example.go
36
+
type examplePlugin string
37
+
38
+
// Important: "JunoPluginInstance" needs to be exported for Juno to load the plugin correctly
Once you have written your plugin, you can compile it into a shared object file (.so) using the following command:
73
+
74
+
```shell
75
+
go build -buildmode=plugin -o ./plugin.so /path/to/your/plugin.go
76
+
```
77
+
78
+
This command compiles the plugin into a shared object file (`plugin.so`), which can then be loaded by the Juno client using the `--plugin-path` flag.
79
+
80
+
## Running Juno with the plugin
81
+
82
+
Once your plugin has been compiled into a `.so` file, you can run Juno with your plugin by providing the `--plugin-path` flag. This flag tells Juno where to find and load your plugin at runtime.
0 commit comments