rpc: list the payment hash in invoice related responses
Previously only the pre-image was listed, but for the convenience of the consumers of this RPC service, we now also return the payment hash itself.
This commit is contained in:
parent
c41d673c7b
commit
7fe02c7bf6
10
rpcserver.go
10
rpcserver.go
|
@ -476,6 +476,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
|
||||||
if err := channel.DeleteState(); err != nil {
|
if err := channel.DeleteState(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// TODO(roasbeef): also unregister link?
|
||||||
return fmt.Errorf("channel has been closed by remote party")
|
return fmt.Errorf("channel has been closed by remote party")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1252,6 +1253,7 @@ func (r *rpcServer) LookupInvoice(ctx context.Context,
|
||||||
return &lnrpc.Invoice{
|
return &lnrpc.Invoice{
|
||||||
Memo: string(invoice.Memo[:]),
|
Memo: string(invoice.Memo[:]),
|
||||||
Receipt: invoice.Receipt[:],
|
Receipt: invoice.Receipt[:],
|
||||||
|
RHash: rHash,
|
||||||
RPreimage: preimage[:],
|
RPreimage: preimage[:],
|
||||||
Value: int64(invoice.Terms.Value),
|
Value: int64(invoice.Terms.Value),
|
||||||
CreationDate: invoice.CreationDate.Unix(),
|
CreationDate: invoice.CreationDate.Unix(),
|
||||||
|
@ -1278,9 +1280,12 @@ func (r *rpcServer) ListInvoices(ctx context.Context,
|
||||||
for i, dbInvoice := range dbInvoices {
|
for i, dbInvoice := range dbInvoices {
|
||||||
invoiceAmount := dbInvoice.Terms.Value
|
invoiceAmount := dbInvoice.Terms.Value
|
||||||
paymentPreimge := dbInvoice.Terms.PaymentPreimage[:]
|
paymentPreimge := dbInvoice.Terms.PaymentPreimage[:]
|
||||||
|
rHash := sha256.Sum256(paymentPreimge)
|
||||||
|
|
||||||
invoice := &lnrpc.Invoice{
|
invoice := &lnrpc.Invoice{
|
||||||
Memo: string(dbInvoice.Memo[:]),
|
Memo: string(dbInvoice.Memo[:]),
|
||||||
Receipt: dbInvoice.Receipt[:],
|
Receipt: dbInvoice.Receipt[:],
|
||||||
|
RHash: rHash[:],
|
||||||
RPreimage: paymentPreimge,
|
RPreimage: paymentPreimge,
|
||||||
Value: int64(invoiceAmount),
|
Value: int64(invoiceAmount),
|
||||||
Settled: dbInvoice.Terms.Settled,
|
Settled: dbInvoice.Terms.Settled,
|
||||||
|
@ -1312,10 +1317,13 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
|
||||||
select {
|
select {
|
||||||
// TODO(roasbeef): include newly added invoices?
|
// TODO(roasbeef): include newly added invoices?
|
||||||
case settledInvoice := <-invoiceClient.SettledInvoices:
|
case settledInvoice := <-invoiceClient.SettledInvoices:
|
||||||
|
preImage := settledInvoice.Terms.PaymentPreimage[:]
|
||||||
|
rHash := sha256.Sum256(preImage)
|
||||||
invoice := &lnrpc.Invoice{
|
invoice := &lnrpc.Invoice{
|
||||||
Memo: string(settledInvoice.Memo[:]),
|
Memo: string(settledInvoice.Memo[:]),
|
||||||
Receipt: settledInvoice.Receipt[:],
|
Receipt: settledInvoice.Receipt[:],
|
||||||
RPreimage: settledInvoice.Terms.PaymentPreimage[:],
|
RHash: rHash[:],
|
||||||
|
RPreimage: preImage,
|
||||||
Value: int64(settledInvoice.Terms.Value),
|
Value: int64(settledInvoice.Terms.Value),
|
||||||
Settled: settledInvoice.Terms.Settled,
|
Settled: settledInvoice.Terms.Settled,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user