From e22182af369d1827410a5a21f0a4424c4919372b Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 8 Sep 2023 15:57:20 +0200 Subject: [PATCH] lightning_client: allow empty hash on AMP invoices --- lightning_client.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lightning_client.go b/lightning_client.go index d6c1316..e1aa8c6 100644 --- a/lightning_client.go +++ b/lightning_client.go @@ -1737,9 +1737,23 @@ func (s *lightningClient) LookupInvoice(ctx context.Context, // unmarshalInvoice creates an invoice from the rpc response provided. func unmarshalInvoice(resp *lnrpc.Invoice) (*Invoice, error) { - hash, err := lntypes.MakeHash(resp.RHash) - if err != nil { - return nil, err + var ( + hash lntypes.Hash + err error + ) + switch { + case !resp.IsAmp && len(resp.RHash) == 0: + return nil, fmt.Errorf("non-AMP invoice is missing hash") + + case resp.IsAmp && len(resp.RHash) == 0: + // AMP invoices do not have an invoice-level hash, so we just + // leave it empty. + + default: + hash, err = lntypes.MakeHash(resp.RHash) + if err != nil { + return nil, err + } } invoice := &Invoice{