Skip to content

Commit

Permalink
Adjust lnurl_pay to new error model
Browse files Browse the repository at this point in the history
  • Loading branch information
dleutenegger committed Nov 6, 2023
1 parent 0f9442b commit 5ed953a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
25 changes: 14 additions & 11 deletions libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,20 @@ impl BreezServices {

let payment = match self.send_payment(pay_req).await {
Ok(p) => Ok(p),
Err(SdkError::SendPaymentFailed { err }) => {
let invoice = parse_invoice(cb.pr.as_str())?;

return Ok(LnUrlPayResult::PayError {
data: LnUrlPayErrorData {
payment_hash: invoice.payment_hash,
reason: err,
},
});
}
Err(e) => Err(e),
Err(e) => match e {
SendPaymentError::InvalidInvoice { .. } => Err(e),
SendPaymentError::ServiceConnectivity { .. } => Err(e),
_ => {
let invoice = parse_invoice(cb.pr.as_str())?;

return Ok(LnUrlPayResult::PayError {
data: LnUrlPayErrorData {
payment_hash: invoice.payment_hash,
reason: e.to_string(),
},
});
}
},
}?
.payment;
let details = match &payment.details {
Expand Down
8 changes: 8 additions & 0 deletions libs/sdk-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,14 @@ impl From<InvoiceError> for SendPaymentError {
}
}

impl From<InvoiceError> for LnUrlPayError {
fn from(err: InvoiceError) -> Self {
Self::InvalidInvoice {
err: err.to_string(),
}
}
}

impl From<NodeError> for SendPaymentError {
fn from(value: NodeError) -> Self {
match value {
Expand Down

0 comments on commit 5ed953a

Please sign in to comment.