API: Add description hash to CreateLightningInvoiceRequest (#3559)

Co-authored-by: Andrew Camilleri <evilkukka@gmail.com>
This commit is contained in:
d11n 2022-03-17 10:15:27 +01:00 committed by GitHub
parent ce6cd40b92
commit 23049439c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View file

@ -1,6 +1,6 @@
using System;
using BTCPayServer.Lightning;
using BTCPayServer.Lightning.JsonConverters;
using NBitcoin;
using Newtonsoft.Json;
namespace BTCPayServer.Client.Models
@ -11,15 +11,19 @@ namespace BTCPayServer.Client.Models
{
}
public CreateLightningInvoiceRequest(LightMoney amount, string description, TimeSpan expiry)
{
Amount = amount;
Description = description;
Expiry = expiry;
}
[JsonConverter(typeof(BTCPayServer.Client.JsonConverters.LightMoneyJsonConverter))]
[JsonConverter(typeof(JsonConverters.LightMoneyJsonConverter))]
public LightMoney Amount { get; set; }
public string Description { get; set; }
[JsonConverter(typeof(NBitcoin.JsonConverters.UInt256JsonConverter))]
public uint256 DescriptionHash { get; set; }
[JsonConverter(typeof(JsonConverters.TimeSpanJsonConverter.Seconds))]
public TimeSpan Expiry { get; set; }
public bool PrivateRouteHints { get; set; }

View file

@ -225,12 +225,16 @@ namespace BTCPayServer.Controllers.Greenfield
try
{
var invoice = await lightningClient.CreateInvoice(
new CreateInvoiceParams(request.Amount, request.Description, request.Expiry)
var param = request.DescriptionHash != null
? new CreateInvoiceParams(request.Amount, request.DescriptionHash, request.Expiry)
{
PrivateRouteHints = request.PrivateRouteHints
},
CancellationToken.None);
PrivateRouteHints = request.PrivateRouteHints, Description = request.Description
}
: new CreateInvoiceParams(request.Amount, request.Description, request.Expiry)
{
PrivateRouteHints = request.PrivateRouteHints, DescriptionHash = request.DescriptionHash
};
var invoice = await lightningClient.CreateInvoice(param, CancellationToken.None);
return Ok(ToModel(invoice));
}
catch (Exception ex)

View file

@ -25,6 +25,12 @@
"nullable": true,
"description": "Description of the invoice in the BOLT11"
},
"descriptionHash": {
"type": "string",
"format": "hex",
"nullable": true,
"description": "Description hash of the invoice in the BOLT11"
},
"expiry": {
"description": "Expiration time in seconds",
"allOf": [ {"$ref": "#/components/schemas/TimeSpanSeconds"}]