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

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

View File

@ -2657,7 +2657,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
return nil, err
}
i := &channeldb.Invoice{
newInvoice := &channeldb.Invoice{
CreationDate: creationDate,
Memo: []byte(invoice.Memo),
Receipt: invoice.Receipt,
@ -2666,22 +2666,24 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
Value: amtMSat,
},
}
copy(i.Terms.PaymentPreimage[:], paymentPreimage[:])
copy(newInvoice.Terms.PaymentPreimage[:], paymentPreimage[:])
rpcsLog.Tracef("[addinvoice] adding new invoice %v",
newLogClosure(func() string {
return spew.Sdump(i)
return spew.Sdump(newInvoice)
}),
)
// 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 &lnrpc.AddInvoiceResponse{
RHash: rHash[:],
PaymentRequest: payReqString,
AddIndex: addIndex,
}, nil
}