invoices+channeldb: move invoice state check to invoiceregistry

This commit is contained in:
Joost Jager 2019-06-10 12:02:06 +02:00
parent e45d4d703a
commit 18c025151a
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
3 changed files with 13 additions and 11 deletions

@ -662,5 +662,9 @@ func TestQueryInvoices(t *testing.T) {
} }
func checkHtlcParameters(invoice *Invoice) error { func checkHtlcParameters(invoice *Invoice) error {
if invoice.Terms.State == ContractSettled {
return ErrInvoiceAlreadySettled
}
return nil return nil
} }

@ -1003,17 +1003,6 @@ func acceptOrSettleInvoice(invoices, settleIndex *bbolt.Bucket,
return nil, err return nil, err
} }
state := invoice.Terms.State
switch {
case state == ContractAccepted:
return &invoice, ErrInvoiceAlreadyAccepted
case state == ContractSettled:
return &invoice, ErrInvoiceAlreadySettled
case state == ContractCanceled:
return &invoice, ErrInvoiceAlreadyCanceled
}
// If the invoice is still open, check the htlc parameters. // If the invoice is still open, check the htlc parameters.
if err := checkHtlcParameters(&invoice); err != nil { if err := checkHtlcParameters(&invoice); err != nil {
return &invoice, err return &invoice, err

@ -526,6 +526,15 @@ func (i *InvoiceRegistry) LookupInvoice(rHash lntypes.Hash) (channeldb.Invoice,
func (i *InvoiceRegistry) checkHtlcParameters(invoice *channeldb.Invoice, func (i *InvoiceRegistry) checkHtlcParameters(invoice *channeldb.Invoice,
amtPaid lnwire.MilliSatoshi, htlcExpiry uint32, currentHeight int32) error { amtPaid lnwire.MilliSatoshi, htlcExpiry uint32, currentHeight int32) error {
switch invoice.Terms.State {
case channeldb.ContractAccepted:
return channeldb.ErrInvoiceAlreadyAccepted
case channeldb.ContractSettled:
return channeldb.ErrInvoiceAlreadySettled
case channeldb.ContractCanceled:
return channeldb.ErrInvoiceAlreadyCanceled
}
expiry, err := i.decodeFinalCltvExpiry(string(invoice.PaymentRequest)) expiry, err := i.decodeFinalCltvExpiry(string(invoice.PaymentRequest))
if err != nil { if err != nil {
return err return err