Fix: The current preimage of a invoice's lightning payment method should be available via API (#5111)

This commit is contained in:
Nicolas Dorier
2023-06-23 19:12:11 +09:00
committed by GitHub
parent aec84f6d67
commit 53aafcf86b
3 changed files with 9 additions and 1 deletions

View File

@@ -2631,7 +2631,7 @@ namespace BTCPayServer.Tests
for (int i = 0; i < invoices.Length; i++)
{
pm[i] = Assert.Single(await client.GetInvoicePaymentMethods(user.StoreId, (await invoices[i]).Id));
Assert.False(pm[i].AdditionalData.HasValues);
Assert.True(pm[i].AdditionalData.HasValues);
}
// Pay them all at once

View File

@@ -3,6 +3,7 @@ using System.Linq;
using BTCPayServer.Lightning;
using BTCPayServer.Services.Invoices;
using NBitcoin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Payments.Lightning
@@ -10,7 +11,9 @@ namespace BTCPayServer.Payments.Lightning
public class LightningLikePaymentMethodDetails : IPaymentMethodDetails
{
public string BOLT11 { get; set; }
[JsonConverter(typeof(NBitcoin.JsonConverters.UInt256JsonConverter))]
public uint256 PaymentHash { get; set; }
[JsonConverter(typeof(NBitcoin.JsonConverters.UInt256JsonConverter))]
public uint256 Preimage { get; set; }
public string InvoiceId { get; set; }
public string NodeInfo { get; set; }

View File

@@ -1007,6 +1007,11 @@ namespace BTCPayServer.Services.Invoices
};
}
// A bug in previous version of BTCPay Server wasn't properly serializing those fields
if (PaymentMethodDetails["PaymentHash"] is JObject)
PaymentMethodDetails["PaymentHash"] = null;
if (PaymentMethodDetails["Preimage"] is JObject)
PaymentMethodDetails["Preimage"] = null;
IPaymentMethodDetails details = GetId().PaymentType.DeserializePaymentMethodDetails(Network, PaymentMethodDetails.ToString());
switch (details)
{