mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Support wider server sync info in greenfield server info (#2511)
fixes #2498
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace BTCPayServer.Abstractions.Contracts
|
namespace BTCPayServer.Abstractions.Contracts
|
||||||
{
|
{
|
||||||
public interface ISyncSummaryProvider
|
public interface ISyncSummaryProvider
|
||||||
@@ -5,5 +7,12 @@ namespace BTCPayServer.Abstractions.Contracts
|
|||||||
bool AllAvailable();
|
bool AllAvailable();
|
||||||
|
|
||||||
string Partial { get; }
|
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>
|
/// <summary>
|
||||||
/// detailed sync information per chain
|
/// detailed sync information per chain
|
||||||
/// </summary>
|
/// </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 string CryptoCode { get; set; }
|
||||||
|
public virtual bool Available { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ServerInfoSyncStatusData: SyncStatus
|
||||||
|
{
|
||||||
public int ChainHeight { get; set; }
|
public int ChainHeight { get; set; }
|
||||||
public int? SyncHeight { get; set; }
|
public int? SyncHeight { get; set; }
|
||||||
public ServerInfoNodeData NodeInformation { get; set; }
|
public ServerInfoNodeData NodeInformation { get; set; }
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Abstractions.Constants;
|
using BTCPayServer.Abstractions.Constants;
|
||||||
|
using BTCPayServer.Abstractions.Contracts;
|
||||||
using BTCPayServer.Client.Models;
|
using BTCPayServer.Client.Models;
|
||||||
using BTCPayServer.Data;
|
|
||||||
using BTCPayServer.HostedServices;
|
|
||||||
using BTCPayServer.Security;
|
|
||||||
using BTCPayServer.Services;
|
using BTCPayServer.Services;
|
||||||
using BTCPayServer.Services.Invoices;
|
using BTCPayServer.Services.Invoices;
|
||||||
using BTCPayServer.Services.Stores;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NBXplorer.Models;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Controllers.GreenField
|
namespace BTCPayServer.Controllers.GreenField
|
||||||
{
|
{
|
||||||
@@ -21,59 +17,41 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
public class GreenFieldServerInfoController : Controller
|
public class GreenFieldServerInfoController : Controller
|
||||||
{
|
{
|
||||||
private readonly BTCPayServerEnvironment _env;
|
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 PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
|
||||||
|
private readonly IEnumerable<ISyncSummaryProvider> _summaryProviders;
|
||||||
|
|
||||||
public GreenFieldServerInfoController(
|
public GreenFieldServerInfoController(
|
||||||
BTCPayServerEnvironment env,
|
BTCPayServerEnvironment env,
|
||||||
NBXplorerDashboard dashBoard,
|
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
|
||||||
StoreRepository storeRepository,
|
IEnumerable<ISyncSummaryProvider>summaryProviders)
|
||||||
UserManager<ApplicationUser> userManager,
|
|
||||||
BTCPayNetworkProvider networkProvider,
|
|
||||||
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary)
|
|
||||||
{
|
{
|
||||||
_env = env;
|
_env = env;
|
||||||
_dashBoard = dashBoard;
|
|
||||||
_storeRepository = storeRepository;
|
|
||||||
_userManager = userManager;
|
|
||||||
_networkProvider = networkProvider;
|
|
||||||
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
|
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
|
||||||
|
_summaryProviders = summaryProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||||
[HttpGet("~/api/v1/server/info")]
|
[HttpGet("~/api/v1/server/info")]
|
||||||
public async Task<ActionResult> ServerInfo()
|
public async Task<ActionResult> ServerInfo()
|
||||||
{
|
{
|
||||||
var stores = await _storeRepository.GetStoresByUserId(_userManager.GetUserId(User));
|
|
||||||
var supportedPaymentMethods = _paymentMethodHandlerDictionary
|
var supportedPaymentMethods = _paymentMethodHandlerDictionary
|
||||||
.SelectMany(handler => handler.GetSupportedPaymentMethods().Select(id => id.ToString()))
|
.SelectMany(handler => handler.GetSupportedPaymentMethods().Select(id => id.ToString()))
|
||||||
.Distinct();
|
.Distinct();
|
||||||
var syncStatus = _dashBoard.GetAll()
|
|
||||||
.Where(summary => summary.Network.ShowSyncSummary)
|
ServerInfoData model = new ServerInfoData2
|
||||||
.Select(summary => new ServerInfoSyncStatusData
|
|
||||||
{
|
{
|
||||||
CryptoCode = summary.Network.CryptoCode,
|
FullySynched = _summaryProviders.All(provider => provider.AllAvailable()),
|
||||||
NodeInformation = summary.Status.BitcoinStatus is BitcoinStatus s ? new ServerInfoNodeData()
|
SyncStatus = _summaryProviders.SelectMany(provider => provider.GetStatuses()),
|
||||||
{
|
|
||||||
Headers = s.Headers,
|
|
||||||
Blocks = s.Blocks,
|
|
||||||
VerificationProgress = s.VerificationProgress
|
|
||||||
} : null,
|
|
||||||
ChainHeight = summary.Status.ChainHeight,
|
|
||||||
SyncHeight = summary.Status.SyncHeight
|
|
||||||
});
|
|
||||||
ServerInfoData model = new ServerInfoData
|
|
||||||
{
|
|
||||||
FullySynched = _dashBoard.IsFullySynched(),
|
|
||||||
SyncStatus = syncStatus,
|
|
||||||
Onion = _env.OnionUrl,
|
Onion = _env.OnionUrl,
|
||||||
Version = _env.Version,
|
Version = _env.Version,
|
||||||
SupportedPaymentMethods = supportedPaymentMethods
|
SupportedPaymentMethods = supportedPaymentMethods
|
||||||
};
|
};
|
||||||
return Ok(model);
|
return Ok(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ServerInfoData2 : ServerInfoData
|
||||||
|
{
|
||||||
|
public new IEnumerable<ISyncStatus> SyncStatus { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#if ALTCOINS
|
#if ALTCOINS
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using BTCPayServer.Abstractions.Contracts;
|
using BTCPayServer.Abstractions.Contracts;
|
||||||
|
|
||||||
namespace BTCPayServer.Services.Altcoins.Ethereum.Services
|
namespace BTCPayServer.Services.Altcoins.Ethereum.Services
|
||||||
@@ -6,10 +8,12 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services
|
|||||||
public class EthereumSyncSummaryProvider : ISyncSummaryProvider
|
public class EthereumSyncSummaryProvider : ISyncSummaryProvider
|
||||||
{
|
{
|
||||||
private readonly EthereumService _ethereumService;
|
private readonly EthereumService _ethereumService;
|
||||||
|
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
|
||||||
|
|
||||||
public EthereumSyncSummaryProvider(EthereumService ethereumService)
|
public EthereumSyncSummaryProvider(EthereumService ethereumService, BTCPayNetworkProvider btcPayNetworkProvider)
|
||||||
{
|
{
|
||||||
_ethereumService = ethereumService;
|
_ethereumService = ethereumService;
|
||||||
|
_btcPayNetworkProvider = btcPayNetworkProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AllAvailable()
|
public bool AllAvailable()
|
||||||
@@ -18,6 +22,24 @@ namespace BTCPayServer.Services.Altcoins.Ethereum.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Partial { get; } = "Ethereum/ETHSyncSummary";
|
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
|
#endif
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ namespace BTCPayServer.Services.Altcoins.Monero.Services
|
|||||||
{
|
{
|
||||||
private readonly MoneroLikeConfiguration _moneroLikeConfiguration;
|
private readonly MoneroLikeConfiguration _moneroLikeConfiguration;
|
||||||
private readonly EventAggregator _eventAggregator;
|
private readonly EventAggregator _eventAggregator;
|
||||||
private readonly BTCPayServerEnvironment _btcPayServerEnvironment;
|
|
||||||
public ImmutableDictionary<string, JsonRpcClient> DaemonRpcClients;
|
public ImmutableDictionary<string, JsonRpcClient> DaemonRpcClients;
|
||||||
public ImmutableDictionary<string, JsonRpcClient> WalletRpcClients;
|
public ImmutableDictionary<string, JsonRpcClient> WalletRpcClients;
|
||||||
|
|
||||||
@@ -24,11 +23,10 @@ namespace BTCPayServer.Services.Altcoins.Monero.Services
|
|||||||
|
|
||||||
public ConcurrentDictionary<string, MoneroLikeSummary> Summaries => _summaries;
|
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;
|
_moneroLikeConfiguration = moneroLikeConfiguration;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_btcPayServerEnvironment = btcPayServerEnvironment;
|
|
||||||
DaemonRpcClients =
|
DaemonRpcClients =
|
||||||
_moneroLikeConfiguration.MoneroLikeConfigurationItems.ToImmutableDictionary(pair => pair.Key,
|
_moneroLikeConfiguration.MoneroLikeConfigurationItems.ToImmutableDictionary(pair => pair.Key,
|
||||||
pair => new JsonRpcClient(pair.Value.DaemonRpcUri, "", "", httpClientFactory.CreateClient()));
|
pair => new JsonRpcClient(pair.Value.DaemonRpcUri, "", "", httpClientFactory.CreateClient()));
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#if ALTCOINS
|
#if ALTCOINS
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BTCPayServer.Abstractions.Contracts;
|
using BTCPayServer.Abstractions.Contracts;
|
||||||
|
using BTCPayServer.Client.Models;
|
||||||
|
|
||||||
namespace BTCPayServer.Services.Altcoins.Monero.Services
|
namespace BTCPayServer.Services.Altcoins.Monero.Services
|
||||||
{
|
{
|
||||||
@@ -19,6 +21,26 @@ namespace BTCPayServer.Services.Altcoins.Monero.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Partial { get; } = "Monero/MoneroSyncSummary";
|
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
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using BTCPayServer.Abstractions.Contracts;
|
using BTCPayServer.Abstractions.Contracts;
|
||||||
|
using BTCPayServer.Client.Models;
|
||||||
using BTCPayServer.HostedServices;
|
using BTCPayServer.HostedServices;
|
||||||
|
using NBXplorer.Models;
|
||||||
|
|
||||||
namespace BTCPayServer.Services
|
namespace BTCPayServer.Services
|
||||||
{
|
{
|
||||||
@@ -18,5 +22,29 @@ namespace BTCPayServer.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Partial { get; } = "Bitcoin/NBXSyncSummary";
|
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
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user