lnrpc/invoices: add hold invoice rpc

This commit is contained in:
Joost Jager committed 2019-03-15 10:08:58 +01:00
1 parent 19f79613df
commit fcdc8f0e83
6 files changed
+395 -29

No files matched your search

+47
View File
@@ -11,6 +11,7 @@ import (
"google.golang.org/grpc"
"gopkg.in/macaroon-bakery.v2/bakery"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntypes"
)
@@ -47,6 +48,10 @@ var (
Entity: "invoices",
Action: "write",
}},
"/invoicesrpc.Invoices/AddHoldInvoice": {{
Entity: "invoices",
Action: "write",
}},
}
// DefaultInvoicesMacFilename is the default name of the invoices
@@ -211,3 +216,45 @@ func (s *Server) CancelInvoice(ctx context.Context,
return &CancelInvoiceResp{}, nil
}
// AddHoldInvoice attempts to add a new hold invoice to the invoice database.
// Any duplicated invoices are rejected, therefore all invoices *must* have a
// unique payment hash.
func (s *Server) AddHoldInvoice(ctx context.Context,
invoice *AddHoldInvoiceRequest) (*AddHoldInvoiceResp, error) {
addInvoiceCfg := &AddInvoiceConfig{
AddInvoice: s.cfg.InvoiceRegistry.AddInvoice,
IsChannelActive: s.cfg.IsChannelActive,
ChainParams: s.cfg.ChainParams,
NodeSigner: s.cfg.NodeSigner,
MaxPaymentMSat: s.cfg.MaxPaymentMSat,
DefaultCLTVExpiry: s.cfg.DefaultCLTVExpiry,
ChanDB: s.cfg.ChanDB,
}
hash, err := lntypes.MakeHash(invoice.Hash)
if err != nil {
return nil, err
}
addInvoiceData := &AddInvoiceData{
Memo: invoice.Memo,
Hash: &hash,
Value: btcutil.Amount(invoice.Value),
DescriptionHash: invoice.DescriptionHash,
Expiry: invoice.Expiry,
FallbackAddr: invoice.FallbackAddr,
CltvExpiry: invoice.CltvExpiry,
Private: invoice.Private,
}
_, dbInvoice, err := AddInvoice(ctx, addInvoiceCfg, addInvoiceData)
if err != nil {
return nil, err
}
return &AddHoldInvoiceResp{
PaymentRequest: string(dbInvoice.PaymentRequest),
}, nil
}