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 30, 2023
1 parent 1bb3f9b commit 2637950
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions coffee_cmd/src/coffee_term/command_show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn show_remote_list(remote_list: Result<CoffeeRemote, CoffeeError>) -> Resul
Ok(())
}

pub fn show_tips(coffee_tips: &Vec<CoffeeTip>) -> Result<(), CoffeeError> {
pub fn show_tips(coffee_tips: &[CoffeeTip]) -> Result<(), CoffeeError> {
term::println(
term::format::tertiary_bold("●"),
term::format::tertiary("Plugin"),
Expand All @@ -89,7 +89,7 @@ pub fn show_tips(coffee_tips: &Vec<CoffeeTip>) -> Result<(), CoffeeError> {
if tip.status == "completed" {
term::format::positive("●").into()
} else {
term::format::positive("●").into()
term::format::negative("●").into()
},
term::format::highlight(tip.for_plugin.clone().unwrap_or_default()),
term::format::bold(tip.destination.clone().unwrap_or_default()),
Expand Down
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 2637950

Please sign in to comment.