From 1048dd516b2fb657a244cdbbbffb8f38086bdf08 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 7 Apr 2018 02:43:35 +0900 Subject: [PATCH] Pass itemDesc to lightning invoice (Fix #104) --- BTCPayServer/BTCPayServer.csproj | 2 +- .../Payments/Lightning/CLightning/CLightningRPCClient.cs | 4 ++-- BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs | 4 ++-- .../Payments/Lightning/Charge/CreateInvoiceRequest.cs | 1 + BTCPayServer/Payments/Lightning/ILightningInvoiceClient.cs | 2 +- .../Payments/Lightning/LightningLikePaymentHandler.cs | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index ade90b49d..41f69b93b 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.0 - 1.0.1.74 + 1.0.1.75 NU1701,CA1816,CA1308,CA1810,CA2208 diff --git a/BTCPayServer/Payments/Lightning/CLightning/CLightningRPCClient.cs b/BTCPayServer/Payments/Lightning/CLightning/CLightningRPCClient.cs index 0293fa244..00c32b84a 100644 --- a/BTCPayServer/Payments/Lightning/CLightning/CLightningRPCClient.cs +++ b/BTCPayServer/Payments/Lightning/CLightning/CLightningRPCClient.cs @@ -174,10 +174,10 @@ namespace BTCPayServer.Payments.Lightning.CLightning } static NBitcoin.DataEncoders.DataEncoder InvoiceIdEncoder = NBitcoin.DataEncoders.Encoders.Base58; - async Task ILightningInvoiceClient.CreateInvoice(LightMoney amount, TimeSpan expiry, CancellationToken cancellation) + async Task ILightningInvoiceClient.CreateInvoice(LightMoney amount, string description, TimeSpan expiry, CancellationToken cancellation) { var id = InvoiceIdEncoder.EncodeData(RandomUtils.GetBytes(20)); - var invoice = await SendCommandAsync("invoice", new object[] { amount.MilliSatoshi, id, "" }, cancellation: cancellation); + var invoice = await SendCommandAsync("invoice", new object[] { amount.MilliSatoshi, id, description ?? "" }, cancellation: cancellation); invoice.Label = id; invoice.MilliSatoshi = amount; invoice.Status = "unpaid"; diff --git a/BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs b/BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs index 27f6eb2bc..f143d90e8 100644 --- a/BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs +++ b/BTCPayServer/Payments/Lightning/Charge/ChargeClient.cs @@ -152,9 +152,9 @@ namespace BTCPayServer.Payments.Lightning.Charge }; } - async Task ILightningInvoiceClient.CreateInvoice(LightMoney amount, TimeSpan expiry, CancellationToken cancellation) + async Task ILightningInvoiceClient.CreateInvoice(LightMoney amount, string description, TimeSpan expiry, CancellationToken cancellation) { - var invoice = await CreateInvoiceAsync(new CreateInvoiceRequest() { Amont = amount, Expiry = expiry }); + var invoice = await CreateInvoiceAsync(new CreateInvoiceRequest() { Amont = amount, Expiry = expiry, Description = description ?? "" }); return new LightningInvoice() { Id = invoice.Id, Amount = amount, BOLT11 = invoice.PayReq, Status = "unpaid" }; } diff --git a/BTCPayServer/Payments/Lightning/Charge/CreateInvoiceRequest.cs b/BTCPayServer/Payments/Lightning/Charge/CreateInvoiceRequest.cs index 9878da96a..0d7e010d7 100644 --- a/BTCPayServer/Payments/Lightning/Charge/CreateInvoiceRequest.cs +++ b/BTCPayServer/Payments/Lightning/Charge/CreateInvoiceRequest.cs @@ -9,5 +9,6 @@ namespace BTCPayServer.Payments.Lightning.Charge { public LightMoney Amont { get; set; } public TimeSpan Expiry { get; set; } + public string Description { get; set; } } } diff --git a/BTCPayServer/Payments/Lightning/ILightningInvoiceClient.cs b/BTCPayServer/Payments/Lightning/ILightningInvoiceClient.cs index b036c68c6..6dae40360 100644 --- a/BTCPayServer/Payments/Lightning/ILightningInvoiceClient.cs +++ b/BTCPayServer/Payments/Lightning/ILightningInvoiceClient.cs @@ -29,7 +29,7 @@ namespace BTCPayServer.Payments.Lightning public interface ILightningInvoiceClient { Task GetInvoice(string invoiceId, CancellationToken cancellation = default(CancellationToken)); - Task CreateInvoice(LightMoney amount, TimeSpan expiry, CancellationToken cancellation = default(CancellationToken)); + Task CreateInvoice(LightMoney amount, string description, TimeSpan expiry, CancellationToken cancellation = default(CancellationToken)); Task Listen(CancellationToken cancellation = default(CancellationToken)); Task GetInfo(CancellationToken cancellation = default(CancellationToken)); } diff --git a/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs b/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs index a853dd3b6..b3c4b928d 100644 --- a/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs @@ -36,7 +36,7 @@ namespace BTCPayServer.Payments.Lightning LightningInvoice lightningInvoice = null; try { - lightningInvoice = await client.CreateInvoice(new LightMoney(due, LightMoneyUnit.BTC), expiry); + lightningInvoice = await client.CreateInvoice(new LightMoney(due, LightMoneyUnit.BTC), invoice.ProductInformation.ItemDesc, expiry); } catch(Exception ex) {