mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-19 12:01:27 +02:00
channeldb+invoices: move invoice cancel logic into registry
This commit is a continuation of the centralization of invoice state transition logic in the invoice registry.
This commit is contained in:
@@ -634,7 +634,24 @@ func (i *InvoiceRegistry) CancelInvoice(payHash lntypes.Hash) error {
|
||||
|
||||
log.Debugf("Invoice(%v): canceling invoice", payHash)
|
||||
|
||||
invoice, err := i.cdb.CancelInvoice(payHash)
|
||||
updateInvoice := func(invoice *channeldb.Invoice) (
|
||||
*channeldb.InvoiceUpdateDesc, error) {
|
||||
|
||||
switch invoice.Terms.State {
|
||||
case channeldb.ContractSettled:
|
||||
return nil, channeldb.ErrInvoiceAlreadySettled
|
||||
case channeldb.ContractCanceled:
|
||||
return nil, channeldb.ErrInvoiceAlreadyCanceled
|
||||
}
|
||||
|
||||
// Move invoice to the canceled state.
|
||||
return &channeldb.InvoiceUpdateDesc{
|
||||
AmtPaid: 0,
|
||||
State: channeldb.ContractCanceled,
|
||||
}, nil
|
||||
}
|
||||
|
||||
invoice, err := i.cdb.UpdateInvoice(payHash, updateInvoice)
|
||||
|
||||
// Implement idempotency by returning success if the invoice was already
|
||||
// canceled.
|
||||
|
Reference in New Issue
Block a user