From 71c7f3062a07afd5540118ac504d5c5ad442eb4b Mon Sep 17 00:00:00 2001 From: daywalker90 Date: Tue, 27 Feb 2024 15:34:37 +0100 Subject: [PATCH] fix: tip function sent unwanted amount and expected wrong response When fetching an invoice with an amount and then paying that invoice cln will error if you sent an amount on the pay command aswell Tip also expected an incompatible CoffeeTip response from pay e.g. pay does not have a field 'for_plugin' --- coffee_core/src/coffee.rs | 12 ++++++++++-- coffee_lib/src/types/mod.rs | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 1bf247e..78257fa 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -586,15 +586,23 @@ impl PluginManager for CoffeeManager { }), ) .await?; - let tip: CoffeeTip = self + let pay: PayResponse = self .cln( "pay", json!({ "bolt11": invoice.invoice, - "amount_msat": amount_msat, }), ) .await?; + let tip = CoffeeTip { + for_plugin: plugin.name(), + invoice: invoice.invoice, + status: pay.status, + destination: pay.destination, + amount_msat: pay.amount_msat, + amount_sent_msat: pay.amount_sent_msat, + warning_partial_completion: pay.warning_partial_completion, + }; Ok(tip) } diff --git a/coffee_lib/src/types/mod.rs b/coffee_lib/src/types/mod.rs index addca3d..f47bcdc 100644 --- a/coffee_lib/src/types/mod.rs +++ b/coffee_lib/src/types/mod.rs @@ -258,4 +258,17 @@ pub mod response { pub amount_sent_msat: u64, pub warning_partial_completion: Option, } + + #[derive(Clone, Debug, Serialize, Deserialize)] + pub struct PayResponse { + pub payment_preimage: String, + pub destination: Option, + pub payment_hash: String, + pub created_at: f64, + pub parts: u32, + pub amount_msat: u64, + pub amount_sent_msat: u64, + pub warning_partial_completion: Option, + pub status: String, + } }