2021-05-19 06:07:28 +02:00
|
|
|
using System.Collections.Generic;
|
2020-05-16 23:57:49 +02:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
2020-11-17 13:46:23 +01:00
|
|
|
using BTCPayServer.Abstractions.Constants;
|
2021-05-19 06:07:28 +02:00
|
|
|
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;
|
2021-05-19 06:07:28 +02:00
|
|
|
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,
|
2021-05-19 06:07:28 +02:00
|
|
|
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;
|
2021-05-19 06:07:28 +02:00
|
|
|
_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")]
|
2021-06-06 14:02:15 +02:00
|
|
|
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
|
|
|
|
2021-05-19 06:07:28 +02:00
|
|
|
ServerInfoData model = new ServerInfoData2
|
2020-05-16 23:57:49 +02:00
|
|
|
{
|
2021-05-19 06:07:28 +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
|
|
|
|
2021-05-19 06:07:28 +02:00
|
|
|
public class ServerInfoData2 : ServerInfoData
|
|
|
|
{
|
|
|
|
public new IEnumerable<ISyncStatus> SyncStatus { get; set; }
|
|
|
|
}
|
2020-05-16 23:57:49 +02:00
|
|
|
}
|
|
|
|
}
|