Skip to content

Commit

Permalink
Merge pull request lightningnetwork#5207 from carlaKC/4727-singleinvoice
Browse files Browse the repository at this point in the history
invoicesrpc: terminate SubscribeSingleInvoice once invoice reaches a final state
  • Loading branch information
cfromknecht authored Apr 14, 2021
2 parents d5aedbc + db1d671 commit 748265d
Show file tree
Hide file tree
Showing 4 changed files with 425 additions and 380 deletions.
5 changes: 5 additions & 0 deletions channeldb/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ func (c ContractState) String() string {
return "Unknown"
}

// IsFinal returns a boolean indicating whether an invoice state is final
func (c ContractState) IsFinal() bool {
return c == ContractSettled || c == ContractCanceled
}

// ContractTerm is a companion struct to the Invoice struct. This struct houses
// the necessary conditions required before the invoice can be considered fully
// settled by the payee.
Expand Down
6 changes: 6 additions & 0 deletions lnrpc/invoicesrpc/invoices_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ func (s *Server) SubscribeSingleInvoice(req *SubscribeSingleInvoiceRequest,
return err
}

// If we have reached a terminal state, close the
// stream with no error.
if newInvoice.State.IsFinal() {
return nil
}

case <-s.quit:
return nil
}
Expand Down
Loading

0 comments on commit 748265d

Please sign in to comment.