Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: identify lightning payment failed in melt #118

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cashu/cashu.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,10 @@ const (
MintingDisabledErrCode CashuErrCode = 20003
MintQuoteInvalidSigErrCode CashuErrCode = 20008

LightningPaymentErrCode CashuErrCode = 20004
MeltQuotePendingErrCode CashuErrCode = 20005
MeltQuoteAlreadyPaidErrCode CashuErrCode = 20006

//LightningPaymentErrCode CashuErrCode = 20008
MeltQuoteErrCode CashuErrCode = 20009
)

Expand All @@ -503,6 +503,7 @@ var (
DuplicateProofs = Error{Detail: "duplicate proofs", Code: InvalidProofErrCode}
QuoteNotExistErr = Error{Detail: "quote does not exist", Code: MeltQuoteErrCode}
QuotePending = Error{Detail: "quote is pending", Code: MeltQuotePendingErrCode}
LightningPaymentFailed = Error{Detail: "Lightning payment failed", Code: LightningPaymentErrCode}
MeltQuoteAlreadyPaid = Error{Detail: "quote already paid", Code: MeltQuoteAlreadyPaidErrCode}
MeltAmountExceededErr = Error{Detail: "max amount for melting exceeded", Code: AmountLimitExceeded}
MeltQuoteForRequestExists = Error{Detail: "melt quote for payment request already exists", Code: MeltQuoteErrCode}
Expand Down
22 changes: 15 additions & 7 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,14 +913,22 @@ func (w *Wallet) Melt(quoteId string) (*nut05.PostMeltQuoteBolt11Response, error
}
meltBolt11Response, err := client.PostMeltBolt11(mint.mintURL, meltBolt11Request)
if err != nil {
// if there was error with melt, remove proofs from pending and save them for use
if err := w.db.SaveProofs(proofs); err != nil {
return nil, fmt.Errorf("error storing proofs: %v", err)
}
if err := w.db.DeletePendingProofsByQuoteId(quote.QuoteId); err != nil {
return nil, fmt.Errorf("error removing pending proofs: %v", err)
if cashuErr, ok := err.(cashu.Error); ok {
if cashuErr.Code == cashu.LightningPaymentErrCode {
// only remove proofs from pending and save them for use
// if got specific error that payment failed
if err := w.db.SaveProofs(proofs); err != nil {
return nil, fmt.Errorf("error storing proofs: %v", err)
}
if err := w.db.DeletePendingProofsByQuoteId(quote.QuoteId); err != nil {
return nil, fmt.Errorf("error removing pending proofs: %v", err)
}
return nil, err
}
} else {
// for any other errors leave proofs as pending
return nil, fmt.Errorf("error doing melt request: %v. Proofs are pending", err)
}
return nil, err
}

switch meltBolt11Response.State {
Expand Down