btcpayserver/BTCPayServer/Controllers/GreenField/GreenfieldServerInfoController.cs

58 lines
2.1 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2020-05-16 23:57:49 +02:00
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Abstractions.Contracts;
2020-05-16 23:57:49 +02:00
using BTCPayServer.Client.Models;
using BTCPayServer.Services;
using BTCPayServer.Services.Invoices;
using Microsoft.AspNetCore.Authorization;
2020-06-30 08:26:19 +02:00
using Microsoft.AspNetCore.Cors;
2020-05-16 23:57:49 +02:00
using Microsoft.AspNetCore.Mvc;
2022-01-14 05:05:23 +01:00
namespace BTCPayServer.Controllers.Greenfield
2020-05-16 23:57:49 +02:00
{
[ApiController]
2020-06-30 08:26:19 +02:00
[EnableCors(CorsPolicies.All)]
2022-01-07 04:17:59 +01:00
public class GreenfieldServerInfoController : Controller
2020-05-16 23:57:49 +02:00
{
private readonly BTCPayServerEnvironment _env;
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
private readonly IEnumerable<ISyncSummaryProvider> _summaryProviders;
2020-05-16 23:57:49 +02:00
2022-01-07 04:17:59 +01:00
public GreenfieldServerInfoController(
2020-06-28 10:55:27 +02:00
BTCPayServerEnvironment env,
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
2021-12-31 08:59:02 +01:00
IEnumerable<ISyncSummaryProvider> summaryProviders)
2020-05-16 23:57:49 +02:00
{
_env = env;
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
_summaryProviders = summaryProviders;
2020-05-16 23:57:49 +02:00
}
2020-06-28 10:55:27 +02:00
2020-05-16 23:57:49 +02:00
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpGet("~/api/v1/server/info")]
public ActionResult ServerInfo()
2020-05-16 23:57:49 +02:00
{
var supportedPaymentMethods = _paymentMethodHandlerDictionary
.SelectMany(handler => handler.GetSupportedPaymentMethods().Select(id => id.ToString()))
.Distinct();
2021-12-31 08:59:02 +01:00
ServerInfoData model = new ServerInfoData2
2020-05-16 23:57:49 +02:00
{
FullySynched = _summaryProviders.All(provider => provider.AllAvailable()),
SyncStatus = _summaryProviders.SelectMany(provider => provider.GetStatuses()),
2020-05-16 23:57:49 +02:00
Onion = _env.OnionUrl,
Version = _env.Version,
SupportedPaymentMethods = supportedPaymentMethods
};
return Ok(model);
}
2021-12-31 08:59:02 +01:00
public class ServerInfoData2 : ServerInfoData
{
public new IEnumerable<ISyncStatus> SyncStatus { get; set; }
}
2020-05-16 23:57:49 +02:00
}
}