multi: restructure invoice Terms field

This commit restructures an invoice's ContractTerms to better encompass
the restrictions placed on settling. For instance, the final ctlv delta
and invoice expiry are moved from the main invoice body (where
additional metadata is stored). Additionally, it moves the State field
outside of the terms since it is rather metadata about the invoice
instead of any terms offered to the sender in the payment request.
This commit is contained in:
Conner Fromknecht committed 2019-11-22 02:25:02 -08:00
1 parent 6cabea563e
commit 3b253e05f6
8 files changed
+81 -82

No files matched your search

+5 -5
View File
@@ -25,12 +25,12 @@ func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) {
// failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0),
Terms: ContractTerm{
Expiry: 4000,
PaymentPreimage: pre,
Value: value,
Features: emptyFeatures,
},
Htlcs: map[CircuitKey]*InvoiceHTLC{},
Expiry: 4000,
Htlcs: map[CircuitKey]*InvoiceHTLC{},
}
i.Memo = []byte("memo")
@@ -114,7 +114,7 @@ func TestInvoiceWorkflow(t *testing.T) {
if err != nil {
t.Fatalf("unable to fetch invoice: %v", err)
}
if dbInvoice2.Terms.State != ContractSettled {
if dbInvoice2.State != ContractSettled {
t.Fatalf("invoice should now be settled but isn't")
}
if dbInvoice2.SettleDate.IsZero() {
@@ -363,7 +363,7 @@ func TestDuplicateSettleInvoice(t *testing.T) {
// We'll update what we expect the settle invoice to be so that our
// comparison below has the correct assumption.
invoice.SettleIndex = 1
invoice.Terms.State = ContractSettled
invoice.State = ContractSettled
invoice.AmtPaid = amt
invoice.SettleDate = dbInvoice.SettleDate
invoice.Htlcs = map[CircuitKey]*InvoiceHTLC{
@@ -679,7 +679,7 @@ func TestQueryInvoices(t *testing.T) {
// settles the invoice with the given amount.
func getUpdateInvoice(amt lnwire.MilliSatoshi) InvoiceUpdateCallback {
return func(invoice *Invoice) (*InvoiceUpdateDesc, error) {
if invoice.Terms.State == ContractSettled {
if invoice.State == ContractSettled {
return nil, ErrInvoiceAlreadySettled
}