@@ -2,7 +2,6 @@ package lndclient
22
33import  (
44	"context" 
5- 	"errors" 
65	"fmt" 
76	"io" 
87	"sync" 
@@ -89,9 +88,18 @@ type InvoicesClient interface {
8988		handler  InvoiceHtlcModifyHandler ) error 
9089}
9190
92- // InvoiceUpdate contains a state update for an invoice. 
91+ // InvoiceUpdate embeds an Invoice to expose the complete invoice view along 
92+ // with the legacy satoshis-paid field used by existing callers. 
9393type  InvoiceUpdate  struct  {
94- 	State    invpkg.ContractState 
94+ 	// Invoice holds the current state of the invoice. 
95+ 	Invoice 
96+ 
97+ 	// AmtPaid is the amount that was accepted for this invoice, in sats. 
98+ 	// This will ONLY be set if this invoice has been settled or accepted. 
99+ 	// We provide this field as if the invoice was created with a zero 
100+ 	// value, then we need to record what amount was ultimately accepted. 
101+ 	// Additionally, it's possible that the sender paid MORE that was 
102+ 	// specified in the original invoice. So we'll record that here as well. 
95103	AmtPaid  btcutil.Amount 
96104}
97105
@@ -203,17 +211,19 @@ func (s *invoicesClient) SubscribeSingleInvoice(ctx context.Context,
203211				return 
204212			}
205213
206- 			state , err  :=  fromRPCInvoiceState (invoice . State )
214+ 			clientInvoice , err  :=  unmarshalInvoice (invoice )
207215			if  err  !=  nil  {
208216				errChan  <-  err 
209217				return 
210218			}
211219
212- 			select  {
213- 			case  updateChan  <-  InvoiceUpdate {
214- 				State :   state ,
220+ 			invoiceUpdate  :=  InvoiceUpdate {
221+ 				Invoice : * clientInvoice ,
215222				AmtPaid : btcutil .Amount (invoice .AmtPaidSat ),
216- 			}:
223+ 			}
224+ 
225+ 			select  {
226+ 			case  updateChan  <-  invoiceUpdate :
217227			case  <- ctx .Done ():
218228				return 
219229			}
@@ -254,26 +264,6 @@ func (s *invoicesClient) AddHoldInvoice(ctx context.Context,
254264	return  resp .PaymentRequest , nil 
255265}
256266
257- func  fromRPCInvoiceState (state  lnrpc.Invoice_InvoiceState ) (
258- 	invpkg.ContractState , error ) {
259- 
260- 	switch  state  {
261- 	case  lnrpc .Invoice_OPEN :
262- 		return  invpkg .ContractOpen , nil 
263- 
264- 	case  lnrpc .Invoice_ACCEPTED :
265- 		return  invpkg .ContractAccepted , nil 
266- 
267- 	case  lnrpc .Invoice_SETTLED :
268- 		return  invpkg .ContractSettled , nil 
269- 
270- 	case  lnrpc .Invoice_CANCELED :
271- 		return  invpkg .ContractCanceled , nil 
272- 	}
273- 
274- 	return  0 , errors .New ("unknown state" )
275- }
276- 
277267// HtlcModifier is a bidirectional streaming RPC that allows a client to 
278268// intercept and modify the HTLCs that attempt to settle the given invoice. The 
279269// server will send HTLCs of invoices to the client and the client can modify 
0 commit comments