Skip to content

Commit f6e7195

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 f6e7195

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

coffee_plugin/src/plugin/plugin_mod.rs

+26
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

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

0 commit comments

Comments
 (0)