From 84387992ec34b4ea2bb8a26e9ebd6281f3395f68 Mon Sep 17 00:00:00 2001 From: positiveblue Date: Wed, 1 Feb 2023 04:50:01 -0800 Subject: [PATCH] invoices: add `UpdateType` to `InvoiceUpdateDesc` Make the kind of update explicit in the `InvoiceUpdateDesc` struct. --- invoices/invoices.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/invoices/invoices.go b/invoices/invoices.go index 7a99a46c6..24447223d 100644 --- a/invoices/invoices.go +++ b/invoices/invoices.go @@ -656,6 +656,51 @@ type HtlcAcceptDesc struct { AMP *InvoiceHtlcAMPData } +// UpdateType is an enum that describes the type of update that was applied to +// an invoice. +type UpdateType uint8 + +const ( + // UnknownUpdate indicates that the UpdateType has not been set for a + // given udpate. This kind of updates are not allowed. + UnknownUpdate UpdateType = iota + + // CancelHTLCsUpdate indicates that this update cancels one or more + // HTLCs. + CancelHTLCsUpdate + + // AddHTLCsUpdate indicates that this update adds one or more HTLCs. + AddHTLCsUpdate + + // SettleHodlInvoiceUpdate indicates that this update settles one or + // more HTLCs from a hodl invoice. + SettleHodlInvoiceUpdate + + // CancelInvoiceUpdate indicates that this update is trying to cancel + // an invoice. + CancelInvoiceUpdate +) + +// String returns a human readable string for the UpdateType. +func (u UpdateType) String() string { + switch u { + case CancelHTLCsUpdate: + return "CancelHTLCsUpdate" + + case AddHTLCsUpdate: + return "AddHTLCsUpdate" + + case SettleHodlInvoiceUpdate: + return "SettleHodlInvoiceUpdate" + + case CancelInvoiceUpdate: + return "CancelInvoiceUpdate" + + default: + return fmt.Sprintf("unknown invoice update type: %d", u) + } +} + // InvoiceUpdateDesc describes the changes that should be applied to the // invoice. type InvoiceUpdateDesc struct { @@ -674,6 +719,9 @@ type InvoiceUpdateDesc struct { // to be more efficient by ensuring we don't need to read out the // entire HTLC set each timee an HTLC is to be cancelled. SetID *SetID + + // UpdateType indicates what type of update is being applied. + UpdateType UpdateType } // InvoiceStateUpdateDesc describes an invoice-level state transition.