rpc: populate response of AddInvoice w/ add index of new invoice

This commit is contained in:
Olaoluwa Osuntokun committed 2018-07-06 12:22:02 -07:00
1 parent 00de6f11b1
commit 904342b9e8
1 file changed
+6 -4
+6 -4
View File
@@ -2657,7 +2657,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
return nil, err return nil, err
} }
i := &channeldb.Invoice{ newInvoice := &channeldb.Invoice{
CreationDate: creationDate, CreationDate: creationDate,
Memo: []byte(invoice.Memo), Memo: []byte(invoice.Memo),
Receipt: invoice.Receipt, Receipt: invoice.Receipt,
@@ -2666,22 +2666,24 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
Value: amtMSat, Value: amtMSat,
}, },
} }
copy(i.Terms.PaymentPreimage[:], paymentPreimage[:]) copy(newInvoice.Terms.PaymentPreimage[:], paymentPreimage[:])
rpcsLog.Tracef("[addinvoice] adding new invoice %v", rpcsLog.Tracef("[addinvoice] adding new invoice %v",
newLogClosure(func() string { newLogClosure(func() string {
return spew.Sdump(i) return spew.Sdump(newInvoice)
}), }),
) )
// With all sanity checks passed, write the invoice to the database. // With all sanity checks passed, write the invoice to the database.
if err := r.server.invoices.AddInvoice(i); err != nil { addIndex, err := r.server.invoices.AddInvoice(newInvoice)
if err != nil {
return nil, err return nil, err
} }
return &lnrpc.AddInvoiceResponse{ return &lnrpc.AddInvoiceResponse{
RHash: rHash[:], RHash: rHash[:],
PaymentRequest: payReqString, PaymentRequest: payReqString,
AddIndex: addIndex,
}, nil }, nil
} }