invoicesrpc: add SettleInvoice

This commit is contained in:
Joost Jager committed 2019-03-15 10:09:23 +01:00
1 parent 0823c79e4e
commit f450929b65
3 files changed
+187 -39

No files matched your search

+23
View File
@@ -12,6 +12,7 @@ import (
"gopkg.in/macaroon-bakery.v2/bakery"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntypes"
)
@@ -44,6 +45,10 @@ var (
Entity: "invoices",
Action: "read",
}},
"/invoicesrpc.Invoices/SettleInvoice": {{
Entity: "invoices",
Action: "write",
}},
"/invoicesrpc.Invoices/CancelInvoice": {{
Entity: "invoices",
Action: "write",
@@ -196,6 +201,24 @@ func (s *Server) SubscribeSingleInvoice(req *lnrpc.PaymentHash,
}
}
// SettleInvoice settles an accepted invoice. If the invoice is already settled,
// this call will succeed.
func (s *Server) SettleInvoice(ctx context.Context,
in *SettleInvoiceMsg) (*SettleInvoiceResp, error) {
preimage, err := lntypes.MakePreimage(in.Preimage)
if err != nil {
return nil, err
}
err = s.cfg.InvoiceRegistry.SettleHodlInvoice(preimage)
if err != nil && err != channeldb.ErrInvoiceAlreadySettled {
return nil, err
}
return &SettleInvoiceResp{}, nil
}
// CancelInvoice cancels a currently open invoice. If the invoice is already
// canceled, this call will succeed. If the invoice is already settled, it will
// fail.