invoices+htlcswitch+lnrpc: cancel invoice

This commit is contained in:
Joost Jager committed 2019-02-06 07:29:18 +01:00
1 parent 9cd88a04b7
commit 1b87fbfab2
13 files changed
+1020 -590

No files matched your search

+32 -2
View File
@@ -8,10 +8,11 @@ import (
"os"
"path/filepath"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntypes"
"google.golang.org/grpc"
"gopkg.in/macaroon-bakery.v2/bakery"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntypes"
)
const (
@@ -26,6 +27,10 @@ var (
// macaroonOps are the set of capabilities that our minted macaroon (if
// it doesn't already exist) will have.
macaroonOps = []bakery.Op{
{
Entity: "invoices",
Action: "write",
},
{
Entity: "invoices",
Action: "read",
@@ -38,6 +43,10 @@ var (
Entity: "invoices",
Action: "read",
}},
"/invoicesrpc.Invoices/CancelInvoice": {{
Entity: "invoices",
Action: "write",
}},
}
// DefaultInvoicesMacFilename is the default name of the invoices
@@ -181,3 +190,24 @@ func (s *Server) SubscribeSingleInvoice(req *lnrpc.PaymentHash,
}
}
}
// 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.
func (s *Server) CancelInvoice(ctx context.Context,
in *CancelInvoiceMsg) (*CancelInvoiceResp, error) {
paymentHash, err := lntypes.NewHash(in.PaymentHash)
if err != nil {
return nil, err
}
err = s.cfg.InvoiceRegistry.CancelInvoice(*paymentHash)
if err != nil {
return nil, err
}
log.Infof("Canceled invoice %v", paymentHash)
return &CancelInvoiceResp{}, nil
}