Pass itemDesc to lightning invoice (Fix #104)

This commit is contained in:
nicolas.dorier 2018-04-07 02:43:35 +09:00
parent 42f44327f0
commit 1048dd516b
6 changed files with 8 additions and 7 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>1.0.1.74</Version> <Version>1.0.1.75</Version>
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn> <NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -174,10 +174,10 @@ namespace BTCPayServer.Payments.Lightning.CLightning
} }
static NBitcoin.DataEncoders.DataEncoder InvoiceIdEncoder = NBitcoin.DataEncoders.Encoders.Base58; static NBitcoin.DataEncoders.DataEncoder InvoiceIdEncoder = NBitcoin.DataEncoders.Encoders.Base58;
async Task<LightningInvoice> ILightningInvoiceClient.CreateInvoice(LightMoney amount, TimeSpan expiry, CancellationToken cancellation) async Task<LightningInvoice> ILightningInvoiceClient.CreateInvoice(LightMoney amount, string description, TimeSpan expiry, CancellationToken cancellation)
{ {
var id = InvoiceIdEncoder.EncodeData(RandomUtils.GetBytes(20)); var id = InvoiceIdEncoder.EncodeData(RandomUtils.GetBytes(20));
var invoice = await SendCommandAsync<CLightningInvoice>("invoice", new object[] { amount.MilliSatoshi, id, "" }, cancellation: cancellation); var invoice = await SendCommandAsync<CLightningInvoice>("invoice", new object[] { amount.MilliSatoshi, id, description ?? "" }, cancellation: cancellation);
invoice.Label = id; invoice.Label = id;
invoice.MilliSatoshi = amount; invoice.MilliSatoshi = amount;
invoice.Status = "unpaid"; invoice.Status = "unpaid";

View File

@ -152,9 +152,9 @@ namespace BTCPayServer.Payments.Lightning.Charge
}; };
} }
async Task<LightningInvoice> ILightningInvoiceClient.CreateInvoice(LightMoney amount, TimeSpan expiry, CancellationToken cancellation) async Task<LightningInvoice> 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" }; return new LightningInvoice() { Id = invoice.Id, Amount = amount, BOLT11 = invoice.PayReq, Status = "unpaid" };
} }

View File

@ -9,5 +9,6 @@ namespace BTCPayServer.Payments.Lightning.Charge
{ {
public LightMoney Amont { get; set; } public LightMoney Amont { get; set; }
public TimeSpan Expiry { get; set; } public TimeSpan Expiry { get; set; }
public string Description { get; set; }
} }
} }

View File

@ -29,7 +29,7 @@ namespace BTCPayServer.Payments.Lightning
public interface ILightningInvoiceClient public interface ILightningInvoiceClient
{ {
Task<LightningInvoice> GetInvoice(string invoiceId, CancellationToken cancellation = default(CancellationToken)); Task<LightningInvoice> GetInvoice(string invoiceId, CancellationToken cancellation = default(CancellationToken));
Task<LightningInvoice> CreateInvoice(LightMoney amount, TimeSpan expiry, CancellationToken cancellation = default(CancellationToken)); Task<LightningInvoice> CreateInvoice(LightMoney amount, string description, TimeSpan expiry, CancellationToken cancellation = default(CancellationToken));
Task<ILightningListenInvoiceSession> Listen(CancellationToken cancellation = default(CancellationToken)); Task<ILightningListenInvoiceSession> Listen(CancellationToken cancellation = default(CancellationToken));
Task<LightningNodeInformation> GetInfo(CancellationToken cancellation = default(CancellationToken)); Task<LightningNodeInformation> GetInfo(CancellationToken cancellation = default(CancellationToken));
} }

View File

@ -36,7 +36,7 @@ namespace BTCPayServer.Payments.Lightning
LightningInvoice lightningInvoice = null; LightningInvoice lightningInvoice = null;
try 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) catch(Exception ex)
{ {