mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
invoices+channeldb: add InvoiceUpdater interface and the KV impl
This commit introduces the InvoiceUpdater interface which is meant to abstract and assist the in-memory invoice update procedure with the accompanying database updates. These abstract updater steps will enable further refactoring later while also ensuring that a full SQL implementation of the InvoiceDB interface will be possible.
This commit is contained in:
parent
998156930f
commit
ecbfc46312
2 changed files with 542 additions and 405 deletions
File diff suppressed because it is too large
Load diff
|
@ -2,9 +2,11 @@ package invoices
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
)
|
||||
|
||||
|
@ -162,3 +164,37 @@ type InvoiceSlice struct {
|
|||
// CircuitKey is a tuple of channel ID and HTLC ID, used to uniquely identify
|
||||
// HTLCs in a circuit.
|
||||
type CircuitKey = models.CircuitKey
|
||||
|
||||
// InvoiceUpdater is an interface to abstract away the details of updating an
|
||||
// invoice in the database. The methods of this interface are called during the
|
||||
// in-memory update of an invoice when the database needs to be updated or the
|
||||
// updated state needs to be marked as needing to be written to the database.
|
||||
type InvoiceUpdater interface {
|
||||
// AddHtlc adds a new htlc to the invoice.
|
||||
AddHtlc(circuitKey CircuitKey, newHtlc *InvoiceHTLC) error
|
||||
|
||||
// ResolveHtlc marks an htlc as resolved with the given state.
|
||||
ResolveHtlc(circuitKey CircuitKey, state HtlcState,
|
||||
resolveTime time.Time) error
|
||||
|
||||
// AddAmpHtlcPreimage adds a preimage of an AMP htlc to the AMP invoice
|
||||
// identified by the setID.
|
||||
AddAmpHtlcPreimage(setID [32]byte, circuitKey CircuitKey,
|
||||
preimage lntypes.Preimage) error
|
||||
|
||||
// UpdateInvoiceState updates the invoice state to the new state.
|
||||
UpdateInvoiceState(newState ContractState,
|
||||
preimage *lntypes.Preimage) error
|
||||
|
||||
// UpdateInvoiceAmtPaid updates the invoice amount paid to the new
|
||||
// amount.
|
||||
UpdateInvoiceAmtPaid(amtPaid lnwire.MilliSatoshi) error
|
||||
|
||||
// UpdateAmpState updates the state of the AMP invoice identified by
|
||||
// the setID.
|
||||
UpdateAmpState(setID [32]byte, newState InvoiceStateAMP,
|
||||
circuitKey models.CircuitKey) error
|
||||
|
||||
// Finalize finalizes the update before it is written to the database.
|
||||
Finalize(updateType UpdateType) error
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue