Greenfield: Add missing invoice metadata to Lightning Address (#6084)

* Greenfield: Add missing invoice metadata to Lightning Address

Closes #6067.

* Update BTCPayServer/wwwroot/swagger/v1/swagger.template.stores-lightning-addresses.json
This commit is contained in:
d11n 2024-07-04 15:42:02 +02:00 committed by Dennis Reimann
parent 201d6cfe70
commit 8aae388d95
No known key found for this signature in database
GPG key ID: 5009E1797F03F8D0
4 changed files with 31 additions and 7 deletions

View file

@ -1,3 +1,5 @@
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Client.Models; namespace BTCPayServer.Client.Models;
public class LightningAddressData public class LightningAddressData
@ -6,5 +8,5 @@ public class LightningAddressData
public string CurrencyCode { get; set; } public string CurrencyCode { get; set; }
public decimal? Min { get; set; } public decimal? Min { get; set; }
public decimal? Max { get; set; } public decimal? Max { get; set; }
public JObject InvoiceMetadata { get; set; }
} }

View file

@ -3468,6 +3468,7 @@ namespace BTCPayServer.Tests
var store2 = (await adminClient.CreateStore(new CreateStoreRequest() { Name = "test2" })).Id; var store2 = (await adminClient.CreateStore(new CreateStoreRequest() { Name = "test2" })).Id;
var address1 = Guid.NewGuid().ToString("n").Substring(0, 8); var address1 = Guid.NewGuid().ToString("n").Substring(0, 8);
var address2 = Guid.NewGuid().ToString("n").Substring(0, 8); var address2 = Guid.NewGuid().ToString("n").Substring(0, 8);
var address3 = Guid.NewGuid().ToString("n").Substring(0, 8);
Assert.Empty(await adminClient.GetStoreLightningAddresses(store.Id)); Assert.Empty(await adminClient.GetStoreLightningAddresses(store.Id));
Assert.Empty(await adminClient.GetStoreLightningAddresses(store2)); Assert.Empty(await adminClient.GetStoreLightningAddresses(store2));
@ -3495,6 +3496,17 @@ namespace BTCPayServer.Tests
await adminClient.RemoveStoreLightningAddress(store2, address2); await adminClient.RemoveStoreLightningAddress(store2, address2);
Assert.Empty(await adminClient.GetStoreLightningAddresses(store2)); Assert.Empty(await adminClient.GetStoreLightningAddresses(store2));
var store3 = (await adminClient.CreateStore(new CreateStoreRequest { Name = "test3" })).Id;
Assert.Empty(await adminClient.GetStoreLightningAddresses(store3));
var metadata = JObject.FromObject(new { test = 123 });
await adminClient.AddOrUpdateStoreLightningAddress(store3, address3, new LightningAddressData
{
InvoiceMetadata = metadata
});
var lnAddresses = await adminClient.GetStoreLightningAddresses(store3);
Assert.Single(lnAddresses);
Assert.Equal(metadata, lnAddresses[0].InvoiceMetadata);
} }
[Fact(Timeout = 60 * 2 * 1000)] [Fact(Timeout = 60 * 2 * 1000)]

View file

@ -1,4 +1,5 @@
#nullable enable #nullable enable
using System;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -8,6 +9,8 @@ using BTCPayServer.Data;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using AuthenticationSchemes = BTCPayServer.Abstractions.Constants.AuthenticationSchemes; using AuthenticationSchemes = BTCPayServer.Abstractions.Constants.AuthenticationSchemes;
using LightningAddressData = BTCPayServer.Client.Models.LightningAddressData; using LightningAddressData = BTCPayServer.Client.Models.LightningAddressData;
@ -31,12 +34,13 @@ namespace BTCPayServer.Controllers.Greenfield
var blob = data.GetBlob(); var blob = data.GetBlob();
if (blob is null) if (blob is null)
return new LightningAddressData(); return new LightningAddressData();
return new LightningAddressData() return new LightningAddressData
{ {
Username = data.Username, Username = data.Username,
Max = blob.Max, Max = blob.Max,
Min = blob.Min, Min = blob.Min,
CurrencyCode = blob.CurrencyCode CurrencyCode = blob.CurrencyCode,
InvoiceMetadata = blob.InvoiceMetadata
}; };
} }
@ -84,15 +88,16 @@ namespace BTCPayServer.Controllers.Greenfield
return this.CreateValidationError(ModelState); return this.CreateValidationError(ModelState);
} }
if (await _lightningAddressService.Set(new Data.LightningAddressData() if (await _lightningAddressService.Set(new Data.LightningAddressData
{ {
StoreDataId = storeId, StoreDataId = storeId,
Username = username Username = username
}.SetBlob(new LightningAddressDataBlob() }.SetBlob(new LightningAddressDataBlob
{ {
Max = data.Max, Max = data.Max,
Min = data.Min, Min = data.Min,
CurrencyCode = data.CurrencyCode CurrencyCode = data.CurrencyCode,
InvoiceMetadata = data.InvoiceMetadata
}))) })))
{ {
return await GetStoreLightningAddress(storeId, username); return await GetStoreLightningAddress(storeId, username);

View file

@ -244,6 +244,11 @@
"type": "string", "type": "string",
"nullable": true, "nullable": true,
"description": "The maximum amount in sats this ln address allows" "description": "The maximum amount in sats this ln address allows"
},
"invoiceMetadata": {
"type": "object",
"nullable": true,
"description": "The invoice metadata as JSON."
} }
} }
} }