mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 09:34:24 +01:00
cln-plugin: Defer binding the plugin state until after configuring
We had a bit of a chicken-and-egg problem, where we instantiated the `state` to be managed by the `Plugin` during the very first step when creating the `Builder`, but then the state might depend on the configuration we only get later. This would force developers to add placeholders in the form of `Option` into the state, when really they'd never be none after configuring. This defers the binding until after we get the configuration and cleans up the semantics: - `Builder`: declare options, hooks, etc - `ConfiguredPlugin`: we have exchanged the handshake with `lightningd`, now we can construct the `state` accordingly - `Plugin`: Running instance of the plugin Changelog-Changed: cln-plugin: Moved the state binding to the plugin until after the configuration step
This commit is contained in:
@@ -6,7 +6,9 @@ use cln_plugin::{options, Builder, Error, Plugin};
|
||||
use tokio;
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), anyhow::Error> {
|
||||
if let Some(plugin) = Builder::new((), tokio::io::stdin(), tokio::io::stdout())
|
||||
let state = ();
|
||||
|
||||
if let Some(plugin) = Builder::new(tokio::io::stdin(), tokio::io::stdout())
|
||||
.option(options::ConfigOption::new(
|
||||
"test-option",
|
||||
options::Value::Integer(42),
|
||||
@@ -15,7 +17,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||
.rpcmethod("testmethod", "This is a test", testmethod)
|
||||
.subscribe("connect", connect_handler)
|
||||
.hook("peer_connected", peer_connected_handler)
|
||||
.start()
|
||||
.start(state)
|
||||
.await?
|
||||
{
|
||||
plugin.join().await
|
||||
|
||||
Reference in New Issue
Block a user