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