Skip to content

Commit

Permalink
fix: tip function sent unwanted amount and expected wrong response
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
daywalker90 authored and vincenzopalazzo committed Mar 1, 2024
1 parent e14d7d5 commit 71c7f30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 10 additions & 2 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
13 changes: 13 additions & 0 deletions coffee_lib/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,17 @@ pub mod response {
pub amount_sent_msat: u64,
pub warning_partial_completion: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PayResponse {
pub payment_preimage: String,
pub destination: Option<String>,
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<String>,
pub status: String,
}
}

0 comments on commit 71c7f30

Please sign in to comment.