Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lnrpc: Add metadata field to AddInvoice and DecodePayReq #8875

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions itest/lnd_single_hop_invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,16 @@ func testSingleHopInvoice(ht *lntest.HarnessTest) {
require.EqualValues(ht, 20, hopHint.CltvExpiryDelta,
"wrong CltvExpiryDelta")

// Now create an invoice and specify some random metadata.
invoice = &lnrpc.Invoice{
Memo: "metadata",
Value: paymentAmt,
Metadata: []byte("Here's some fancy metadata :)"),
}
invoiceResp = bob.RPC.AddInvoice(invoice)
payreq = bob.RPC.DecodePayReq(invoiceResp.PaymentRequest)
require.Equal(ht, payreq.Metadata,
[]byte("Here's some fancy metadata :)"), "wrong metadata")

ht.CloseChannel(alice, cp)
}
8 changes: 8 additions & 0 deletions lnrpc/invoicesrpc/addinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ type AddInvoiceData struct {
// RouteHints are optional route hints that can each be individually
// used to assist in reaching the invoice's destination.
RouteHints [][]zpay32.HopHint

// Metadata is additional data that is sent along with the payment to
// the payee.
Metadata []byte
}

// paymentHashAndPreimage returns the payment hash and preimage for this invoice
Expand Down Expand Up @@ -439,6 +443,10 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
}
options = append(options, zpay32.PaymentAddr(paymentAddr))

if len(invoice.Metadata) > 0 {
options = append(options, zpay32.Metadata(invoice.Metadata))
}

// Create and encode the payment request as a bech32 (zpay32) string.
creationDate := time.Now()
payReq, err := zpay32.NewInvoice(
Expand Down
5 changes: 5 additions & 0 deletions lnrpc/invoicesrpc/invoices.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@
},
"description": "Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the\ngiven set ID. This field is always populated for AMP invoices, and can be\nused along side LookupInvoice to obtain the HTLC information related to a\ngiven sub-invoice.\nNote: Output only, don't specify for creating an invoice.",
"title": "[EXPERIMENTAL]:"
},
"metadata": {
"type": "string",
"format": "byte",
"description": "Metadata to send along to the payee in the invoice."
}
}
},
Expand Down
2,308 changes: 1,164 additions & 1,144 deletions lnrpc/lightning.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3836,6 +3836,11 @@ message Invoice {
Note: Output only, don't specify for creating an invoice.
*/
map<string, AMPInvoiceState> amp_invoice_state = 28;

/*
Metadata to send along to the payee in the invoice.
*/
bytes metadata = 29;
}

enum InvoiceHTLCState {
Expand Down Expand Up @@ -4289,6 +4294,7 @@ message PayReq {
bytes payment_addr = 11;
int64 num_msat = 12;
map<uint32, Feature> features = 13;
bytes metadata = 14;
}

enum FeatureBit {
Expand Down
9 changes: 9 additions & 0 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5490,6 +5490,11 @@
},
"description": "Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the\ngiven set ID. This field is always populated for AMP invoices, and can be\nused along side LookupInvoice to obtain the HTLC information related to a\ngiven sub-invoice.\nNote: Output only, don't specify for creating an invoice.",
"title": "[EXPERIMENTAL]:"
},
"metadata": {
"type": "string",
"format": "byte",
"description": "Metadata to send along to the payee in the invoice."
}
}
},
Expand Down Expand Up @@ -6299,6 +6304,10 @@
"additionalProperties": {
"$ref": "#/definitions/lnrpcFeature"
}
},
"metadata": {
"type": "string",
"format": "byte"
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5791,6 +5791,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
Private: invoice.Private,
RouteHints: routeHints,
Amp: invoice.IsAmp,
Metadata: invoice.Metadata,
}

if invoice.RPreimage != nil {
Expand Down Expand Up @@ -6998,6 +6999,7 @@ func (r *rpcServer) DecodePayReq(ctx context.Context,
RouteHints: routeHints,
PaymentAddr: paymentAddr,
Features: invoicesrpc.CreateRPCFeatures(payReq.Features),
Metadata: payReq.Metadata,
}, nil
}

Expand Down
Loading