invoicesrpc: add SettleInvoice
This commit is contained in:
3 files changed
+187
-39
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user