Support wider server sync info in greenfield server info (#2511)

fixes #2498
This commit is contained in:
Andrew Camilleri
2021-05-19 06:07:28 +02:00
committed by GitHub
parent ed7031981b
commit 3b375929c1
7 changed files with 106 additions and 44 deletions

View File

@@ -1,18 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Client.Models;
using BTCPayServer.Data;
using BTCPayServer.HostedServices;
using BTCPayServer.Security;
using BTCPayServer.Services;
using BTCPayServer.Services.Invoices;
using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using NBXplorer.Models;
namespace BTCPayServer.Controllers.GreenField
{
@@ -21,59 +17,41 @@ namespace BTCPayServer.Controllers.GreenField
public class GreenFieldServerInfoController : Controller
{
private readonly BTCPayServerEnvironment _env;
private readonly NBXplorerDashboard _dashBoard;
private readonly StoreRepository _storeRepository;
private readonly UserManager<ApplicationUser> _userManager;
private readonly BTCPayNetworkProvider _networkProvider;
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
private readonly IEnumerable<ISyncSummaryProvider> _summaryProviders;
public GreenFieldServerInfoController(
BTCPayServerEnvironment env,
NBXplorerDashboard dashBoard,
StoreRepository storeRepository,
UserManager<ApplicationUser> userManager,
BTCPayNetworkProvider networkProvider,
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary)
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
IEnumerable<ISyncSummaryProvider>summaryProviders)
{
_env = env;
_dashBoard = dashBoard;
_storeRepository = storeRepository;
_userManager = userManager;
_networkProvider = networkProvider;
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
_summaryProviders = summaryProviders;
}
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpGet("~/api/v1/server/info")]
public async Task<ActionResult> ServerInfo()
{
var stores = await _storeRepository.GetStoresByUserId(_userManager.GetUserId(User));
var supportedPaymentMethods = _paymentMethodHandlerDictionary
.SelectMany(handler => handler.GetSupportedPaymentMethods().Select(id => id.ToString()))
.Distinct();
var syncStatus = _dashBoard.GetAll()
.Where(summary => summary.Network.ShowSyncSummary)
.Select(summary => new ServerInfoSyncStatusData
{
CryptoCode = summary.Network.CryptoCode,
NodeInformation = summary.Status.BitcoinStatus is BitcoinStatus s ? new ServerInfoNodeData()
{
Headers = s.Headers,
Blocks = s.Blocks,
VerificationProgress = s.VerificationProgress
} : null,
ChainHeight = summary.Status.ChainHeight,
SyncHeight = summary.Status.SyncHeight
});
ServerInfoData model = new ServerInfoData
ServerInfoData model = new ServerInfoData2
{
FullySynched = _dashBoard.IsFullySynched(),
SyncStatus = syncStatus,
FullySynched = _summaryProviders.All(provider => provider.AllAvailable()),
SyncStatus = _summaryProviders.SelectMany(provider => provider.GetStatuses()),
Onion = _env.OnionUrl,
Version = _env.Version,
SupportedPaymentMethods = supportedPaymentMethods
};
return Ok(model);
}
public class ServerInfoData2 : ServerInfoData
{
public new IEnumerable<ISyncStatus> SyncStatus { get; set; }
}
}
}