invoiceregistry: update AddInvoice to return addIndex of new invoice

This commit is contained in:
Olaoluwa Osuntokun 2018-06-29 18:06:49 -07:00
parent 904342b9e8
commit 9c1ed7fc7d
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

View File

@ -252,8 +252,10 @@ func (i *invoiceRegistry) AddDebugInvoice(amt btcutil.Amount, preimage chainhash
// the passed preimage. Additionally, any memo or receipt data provided will // the passed preimage. Additionally, any memo or receipt data provided will
// also be stored on-disk. Once this invoice is added, subsystems within the // also be stored on-disk. Once this invoice is added, subsystems within the
// daemon add/forward HTLCs are able to obtain the proper preimage required for // daemon add/forward HTLCs are able to obtain the proper preimage required for
// redemption in the case that we're the final destination. // redemption in the case that we're the final destination. We also return the
func (i *invoiceRegistry) AddInvoice(invoice *channeldb.Invoice) error { // addIndex of the newly created invoice which monotonically increases for each
// new invoice added.
func (i *invoiceRegistry) AddInvoice(invoice *channeldb.Invoice) (uint64, error) {
i.Lock() i.Lock()
defer i.Unlock() defer i.Unlock()
@ -261,15 +263,16 @@ func (i *invoiceRegistry) AddInvoice(invoice *channeldb.Invoice) error {
return spew.Sdump(invoice) return spew.Sdump(invoice)
})) }))
if err := i.cdb.AddInvoice(invoice); err != nil { addIndex, err := i.cdb.AddInvoice(invoice)
return err if err != nil {
return 0, err
} }
// We'll launch a new goroutine to notify all of our active listeners // We'll launch a new goroutine to notify all of our active listeners
// that a new invoice was just added. // that a new invoice was just added.
i.notifyClients(invoice, false) i.notifyClients(invoice, false)
return nil return addIndex, nil
} }
// LookupInvoice looks up an invoice by its payment hash (R-Hash), if found // LookupInvoice looks up an invoice by its payment hash (R-Hash), if found