Skip to content

Commit

Permalink
feat(plugin): implementing the method to generate the invoice to put …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
vincenzopalazzo committed Jul 29, 2023
1 parent 39d202b commit 551e222
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions coffee_plugin/src/plugin/plugin_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Coffee as a core lightning plugin.
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -30,6 +31,7 @@ pub fn build_plugin() -> Result<Plugin<State>, PluginError> {
coffee_install,
coffee_list,
coffee_remote,
coffee_generate_tip,
],
hooks: [],
};
Expand Down Expand Up @@ -124,3 +126,28 @@ fn coffee_remote(plugin: &mut Plugin<State>, request: Value) -> Result<Value, Pl
.map_err(from)?;
Ok(json!({}))
}

#[rpc_method(
rpc_name = "coffee_generate_tip",
description = "Generate the BOLT 12 to add inside a plugin configuration to receive donation"
)]
fn coffee_generate_tip(plugin: &mut Plugin<State>, request: Value) -> Result<Value, PluginError> {
let runtime = Runtime::new().unwrap();
let coffee = plugin.state.coffee();

#[derive(Serialize, Deserialize, Debug)]
struct Offer {
pub bolt12: String,
}

let offer = runtime
.block_on(async {
let mut coffee = coffee.lock().unwrap();
coffee.cln::<Value, Offer>("offer", json!({
"amount": "any",
"description": "Generating BOLT 12 for coffee tips regarding the plugin ...",
})).await
})
.map_err(from)?;
Ok(serde_json::to_value(offer)?)
}

0 comments on commit 551e222

Please sign in to comment.