mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 07:35:03 +01:00
fix: lnd check total total amount
This commit is contained in:
@@ -11,9 +11,12 @@ pub enum Error {
|
||||
/// Unknown invoice
|
||||
#[error("Unknown invoice")]
|
||||
UnknownInvoice,
|
||||
/// Connection Error
|
||||
/// Connection error
|
||||
#[error("LND connection error")]
|
||||
Connection,
|
||||
/// Payment failed
|
||||
#[error("LND payment failed")]
|
||||
PaymentFailed,
|
||||
}
|
||||
|
||||
impl From<Error> for cdk::cdk_lightning::Error {
|
||||
|
||||
@@ -189,19 +189,27 @@ impl MintLightning for Lnd {
|
||||
.lightning()
|
||||
.send_payment_sync(fedimint_tonic_lnd::tonic::Request::new(pay_req))
|
||||
.await
|
||||
.unwrap()
|
||||
.map_err(|_| Error::PaymentFailed)?
|
||||
.into_inner();
|
||||
|
||||
let total_spent = payment_response
|
||||
let total_amount = payment_response
|
||||
.payment_route
|
||||
.map_or(0, |route| route.total_fees_msat / MSAT_IN_SAT as i64)
|
||||
.map_or(0, |route| route.total_amt_msat / MSAT_IN_SAT as i64)
|
||||
as u64;
|
||||
|
||||
let (status, payment_preimage) = match total_amount == 0 {
|
||||
true => (MeltQuoteState::Unpaid, None),
|
||||
false => (
|
||||
MeltQuoteState::Paid,
|
||||
Some(hex::encode(payment_response.payment_preimage)),
|
||||
),
|
||||
};
|
||||
|
||||
Ok(PayInvoiceResponse {
|
||||
payment_hash: hex::encode(payment_response.payment_hash),
|
||||
payment_preimage: Some(hex::encode(payment_response.payment_preimage)),
|
||||
status: MeltQuoteState::Paid,
|
||||
total_spent: total_spent.into(),
|
||||
payment_preimage,
|
||||
status,
|
||||
total_spent: total_amount.into(),
|
||||
unit: CurrencyUnit::Sat,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user