@@ -52,7 +52,9 @@ import (
5252 "github.com/lightningnetwork/lnd/build"
5353 "github.com/lightningnetwork/lnd/keychain"
5454 "github.com/lightningnetwork/lnd/lnrpc"
55+ "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
5556 "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
57+ "github.com/lightningnetwork/lnd/lntypes"
5658 "github.com/lightningnetwork/lnd/lnwallet/chainfee"
5759 "github.com/lightningnetwork/lnd/lnwire"
5860 "github.com/lightningnetwork/lnd/record"
@@ -7218,6 +7220,65 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
72187220 "for channel with ID %d: %w" , channelID , err )
72197221 }
72207222
7223+ // If this is a hodl invoice, then we'll copy over the relevant fields,
7224+ // then route this through the invoicerpc instead.
7225+ if req .HodlInvoice != nil {
7226+ payHash , err := lntypes .MakeHash (req .HodlInvoice .PaymentHash )
7227+ if err != nil {
7228+ return nil , fmt .Errorf ("error creating payment " +
7229+ "hash: %w" , err )
7230+ }
7231+
7232+ peerPub , err := btcec .ParsePubKey (peerPubKey [:])
7233+ if err != nil {
7234+ return nil , fmt .Errorf ("error parsing peer " +
7235+ "pubkey: %w" , err )
7236+ }
7237+
7238+ hopHint := []zpay32.HopHint {
7239+ {
7240+ NodeID : peerPub ,
7241+ ChannelID : acceptedQuote .Scid ,
7242+ FeeBaseMSat : uint32 (inboundPolicy .FeeBaseMsat ),
7243+ FeeProportionalMillionths : uint32 (
7244+ inboundPolicy .FeeRateMilliMsat ,
7245+ ),
7246+ CLTVExpiryDelta : uint16 (
7247+ inboundPolicy .TimeLockDelta ,
7248+ ),
7249+ },
7250+ }
7251+
7252+ payReq , err := r .cfg .Lnd .Invoices .AddHoldInvoice (
7253+ ctx , & invoicesrpc.AddInvoiceData {
7254+ Memo : iReq .Memo ,
7255+ Value : lnwire .MilliSatoshi (
7256+ iReq .ValueMsat ,
7257+ ),
7258+ Hash : & payHash ,
7259+ DescriptionHash : iReq .DescriptionHash ,
7260+ Expiry : iReq .Expiry ,
7261+ // We set private to false as we don't want to
7262+ // add any hop hints other than this one.
7263+ Private : false ,
7264+ HodlInvoice : true ,
7265+ RouteHints : [][]zpay32.HopHint {hopHint },
7266+ },
7267+ )
7268+ if err != nil {
7269+ return nil , fmt .Errorf ("error creating hodl invoice: " +
7270+ "%w" , err )
7271+ }
7272+
7273+ return & tchrpc.AddInvoiceResponse {
7274+ AcceptedBuyQuote : acceptedQuote ,
7275+ InvoiceResult : & lnrpc.AddInvoiceResponse {
7276+ PaymentRequest : payReq ,
7277+ },
7278+ }, nil
7279+ }
7280+
7281+ // Otherwise, we'll make this into a normal invoice.
72217282 hopHint := & lnrpc.HopHint {
72227283 NodeId : peerPubKey .String (),
72237284 ChanId : acceptedQuote .Scid ,
0 commit comments