mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 21:32:27 +01:00
Support wider server sync info in greenfield server info (#2511)
fixes #2498
This commit is contained in:
parent
ed7031981b
commit
3b375929c1
@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BTCPayServer.Abstractions.Contracts
|
||||
{
|
||||
public interface ISyncSummaryProvider
|
||||
@ -5,5 +7,12 @@ namespace BTCPayServer.Abstractions.Contracts
|
||||
bool AllAvailable();
|
||||
|
||||
string Partial { get; }
|
||||
IEnumerable<ISyncStatus> GetStatuses();
|
||||
}
|
||||
|
||||
public interface ISyncStatus
|
||||
{
|
||||
public string CryptoCode { get; set; }
|
||||
public bool Available { get; }
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,17 @@ namespace BTCPayServer.Client.Models
|
||||
/// <summary>
|
||||
/// detailed sync information per chain
|
||||
/// </summary>
|
||||
public IEnumerable<ServerInfoSyncStatusData> SyncStatus { get; set; }
|
||||
public IEnumerable<SyncStatus> SyncStatus { get; set; }
|
||||
}
|
||||
|
||||
public class ServerInfoSyncStatusData
|
||||
|
||||
public class SyncStatus
|
||||
{
|
||||
public string CryptoCode { get; set; }
|
||||
public virtual bool Available { get; set; }
|
||||
}
|
||||
|
||||
public class ServerInfoSyncStatusData: SyncStatus
|
||||
{
|
||||
public int ChainHeight { get; set; }
|
||||
public int? SyncHeight { get; set; }
|
||||
public ServerInfoNodeData NodeInformation { get; set; }
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
#if ALTCOINS
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
|
||||
namespace BTCPayServer.Services.Altcoins.Ethereum.Services
|
||||
@ -6,10 +8,12 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services
|
||||
public class EthereumSyncSummaryProvider : ISyncSummaryProvider
|
||||
{
|
||||
private readonly EthereumService _ethereumService;
|
||||
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
|
||||
|
||||
public EthereumSyncSummaryProvider(EthereumService ethereumService)
|
||||
public EthereumSyncSummaryProvider(EthereumService ethereumService, BTCPayNetworkProvider btcPayNetworkProvider)
|
||||
{
|
||||
_ethereumService = ethereumService;
|
||||
_btcPayNetworkProvider = btcPayNetworkProvider;
|
||||
}
|
||||
|
||||
public bool AllAvailable()
|
||||
@ -18,6 +22,24 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services
|
||||
}
|
||||
|
||||
public string Partial { get; } = "Ethereum/ETHSyncSummary";
|
||||
public IEnumerable<ISyncStatus> GetStatuses()
|
||||
{
|
||||
return _btcPayNetworkProvider
|
||||
.GetAll()
|
||||
.OfType<EthereumBTCPayNetwork>()
|
||||
.Where(network => !(network is ERC20BTCPayNetwork))
|
||||
.Select(network => network.CryptoCode).Select(network => new SyncStatus()
|
||||
{
|
||||
CryptoCode = network,
|
||||
Available = _ethereumService.IsAvailable(network, out _)
|
||||
});
|
||||
}
|
||||
|
||||
public class SyncStatus : ISyncStatus
|
||||
{
|
||||
public string CryptoCode { get; set; }
|
||||
public bool Available { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -15,7 +15,6 @@ namespace BTCPayServer.Services.Altcoins.Monero.Services
|
||||
{
|
||||
private readonly MoneroLikeConfiguration _moneroLikeConfiguration;
|
||||
private readonly EventAggregator _eventAggregator;
|
||||
private readonly BTCPayServerEnvironment _btcPayServerEnvironment;
|
||||
public ImmutableDictionary<string, JsonRpcClient> DaemonRpcClients;
|
||||
public ImmutableDictionary<string, JsonRpcClient> WalletRpcClients;
|
||||
|
||||
@ -24,11 +23,10 @@ namespace BTCPayServer.Services.Altcoins.Monero.Services
|
||||
|
||||
public ConcurrentDictionary<string, MoneroLikeSummary> Summaries => _summaries;
|
||||
|
||||
public MoneroRPCProvider(MoneroLikeConfiguration moneroLikeConfiguration, EventAggregator eventAggregator, IHttpClientFactory httpClientFactory, BTCPayServerEnvironment btcPayServerEnvironment)
|
||||
public MoneroRPCProvider(MoneroLikeConfiguration moneroLikeConfiguration, EventAggregator eventAggregator, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_moneroLikeConfiguration = moneroLikeConfiguration;
|
||||
_eventAggregator = eventAggregator;
|
||||
_btcPayServerEnvironment = btcPayServerEnvironment;
|
||||
DaemonRpcClients =
|
||||
_moneroLikeConfiguration.MoneroLikeConfigurationItems.ToImmutableDictionary(pair => pair.Key,
|
||||
pair => new JsonRpcClient(pair.Value.DaemonRpcUri, "", "", httpClientFactory.CreateClient()));
|
||||
|
@ -1,6 +1,8 @@
|
||||
#if ALTCOINS
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
using BTCPayServer.Client.Models;
|
||||
|
||||
namespace BTCPayServer.Services.Altcoins.Monero.Services
|
||||
{
|
||||
@ -19,6 +21,26 @@ namespace BTCPayServer.Services.Altcoins.Monero.Services
|
||||
}
|
||||
|
||||
public string Partial { get; } = "Monero/MoneroSyncSummary";
|
||||
public IEnumerable<ISyncStatus> GetStatuses()
|
||||
{
|
||||
return _moneroRpcProvider.Summaries.Select(pair => new MoneroSyncStatus()
|
||||
{
|
||||
Summary = pair.Value, CryptoCode = pair.Key
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class MoneroSyncStatus: SyncStatus, ISyncStatus
|
||||
{
|
||||
public override bool Available
|
||||
{
|
||||
get
|
||||
{
|
||||
return Summary?.WalletAvailable ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
public MoneroRPCProvider.MoneroLikeSummary Summary { get; set; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,5 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.HostedServices;
|
||||
using NBXplorer.Models;
|
||||
|
||||
namespace BTCPayServer.Services
|
||||
{
|
||||
@ -18,5 +22,29 @@ namespace BTCPayServer.Services
|
||||
}
|
||||
|
||||
public string Partial { get; } = "Bitcoin/NBXSyncSummary";
|
||||
public IEnumerable<ISyncStatus> GetStatuses()
|
||||
{
|
||||
return _nbXplorerDashboard.GetAll()
|
||||
.Where(summary => summary.Network.ShowSyncSummary)
|
||||
.Select(summary => new ServerInfoSyncStatusData2
|
||||
{
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
public class ServerInfoSyncStatusData2: ServerInfoSyncStatusData, ISyncStatus
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user