Skip to content

Commit 551e222

Browse files
feat(plugin): implementing the method to generate the invoice to put inside the coffee conf
This commit assume that the developer of the plugins is running a lightning node and is allow to receive payments with lightning. So this is a helper method that help you to generate an BOLT 12 invoice without understand how to do it :) Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 39d202b commit 551e222

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

coffee_plugin/src/plugin/plugin_mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! Coffee as a core lightning plugin.
33
use std::fmt::Display;
44

5+
use serde::{Deserialize, Serialize};
56
use serde_json::{json, Value};
67
use tokio::runtime::Runtime;
78

@@ -30,6 +31,7 @@ pub fn build_plugin() -> Result<Plugin<State>, PluginError> {
3031
coffee_install,
3132
coffee_list,
3233
coffee_remote,
34+
coffee_generate_tip,
3335
],
3436
hooks: [],
3537
};
@@ -124,3 +126,28 @@ fn coffee_remote(plugin: &mut Plugin<State>, request: Value) -> Result<Value, Pl
124126
.map_err(from)?;
125127
Ok(json!({}))
126128
}
129+
130+
#[rpc_method(
131+
rpc_name = "coffee_generate_tip",
132+
description = "Generate the BOLT 12 to add inside a plugin configuration to receive donation"
133+
)]
134+
fn coffee_generate_tip(plugin: &mut Plugin<State>, request: Value) -> Result<Value, PluginError> {
135+
let runtime = Runtime::new().unwrap();
136+
let coffee = plugin.state.coffee();
137+
138+
#[derive(Serialize, Deserialize, Debug)]
139+
struct Offer {
140+
pub bolt12: String,
141+
}
142+
143+
let offer = runtime
144+
.block_on(async {
145+
let mut coffee = coffee.lock().unwrap();
146+
coffee.cln::<Value, Offer>("offer", json!({
147+
"amount": "any",
148+
"description": "Generating BOLT 12 for coffee tips regarding the plugin ...",
149+
})).await
150+
})
151+
.map_err(from)?;
152+
Ok(serde_json::to_value(offer)?)
153+
}

0 commit comments

Comments
 (0)