channeldb/invoices: add IsAMP and IsKeysend helpers

The only way to know if an invoice is AMP, Keysend, etc is to look at
its shape/characteristics. This commit adds a couple of helper functions
to encapsulate the logic of these checks.

If all these types cannot intersect: an invoice cannot be AMP and
Keysend or Keysend and Bolt12, etc it could be useful to add an extra
field to store this information instead of relying on checking how the
invoice looks like.
This commit is contained in:
positiveblue committed 2023-01-20 03:43:39 -08:00
1 parent 0eb07c944c
commit 8563e1f409
3 files changed
+74 -44

No files matched your search

+2 -4
View File
@@ -150,8 +150,6 @@ func CreateRPCInvoice(invoice *invoices.Invoice,
rpcHtlcs = append(rpcHtlcs, &rpcHtlc)
}
isAmp := invoice.Terms.Features.HasFeature(lnwire.AMPOptional)
rpcInvoice := &lnrpc.Invoice{
Memo: string(invoice.Memo),
RHash: rHash,
@@ -175,9 +173,9 @@ func CreateRPCInvoice(invoice *invoices.Invoice,
State: state,
Htlcs: rpcHtlcs,
Features: CreateRPCFeatures(invoice.Terms.Features),
IsKeysend: len(invoice.PaymentRequest) == 0 && !isAmp,
IsKeysend: invoice.IsKeysend(),
PaymentAddr: invoice.Terms.PaymentAddr[:],
IsAmp: isAmp,
IsAmp: invoice.IsAMP(),
}
rpcInvoice.AmpInvoiceState = make(map[string]*lnrpc.AMPInvoiceState)