Merge pull request #1583 from NicolasDorier/refactor/serverinfo

Refactor server info data structure
This commit is contained in:
Nicolas Dorier 2020-05-20 03:43:39 +09:00 committed by GitHub
commit 3d1122be7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 47 deletions

View file

@ -4,11 +4,6 @@ namespace BTCPayServer.Client.Models
{
public class ServerInfoData
{
/// <summary>
/// detailed status information
/// </summary>
public ServerInfoStatusData Status { get; set; }
/// <summary>
/// the BTCPay Server version
/// </summary>
@ -23,15 +18,12 @@ namespace BTCPayServer.Client.Models
/// the payment methods this server supports
/// </summary>
public IEnumerable<string> SupportedPaymentMethods { get; set; }
}
public class ServerInfoStatusData
{
/// <summary>
/// are all chains fully synched
/// </summary>
public bool FullySynched { get; set; }
/// <summary>
/// detailed sync information per chain
/// </summary>
@ -41,7 +33,15 @@ namespace BTCPayServer.Client.Models
public class ServerInfoSyncStatusData
{
public string CryptoCode { get; set; }
public int BlockHeaders { get; set; }
public float Progress { get; set; }
public int ChainHeight { get; set; }
public int? SyncHeight { get; set; }
public ServerInfoNodeData NodeInformation { get; set; }
}
public class ServerInfoNodeData
{
public int Headers { get; set; }
public int Blocks { get; set; }
public double VerificationProgress { get; set; }
}
}

View file

@ -345,12 +345,11 @@ namespace BTCPayServer.Tests
Assert.NotNull(serverInfoData);
Assert.NotNull(serverInfoData.Version);
Assert.NotNull(serverInfoData.Onion);
Assert.NotNull(serverInfoData.Status);
Assert.True(serverInfoData.Status.FullySynched);
Assert.True(serverInfoData.FullySynched);
Assert.Contains("BTC", serverInfoData.SupportedPaymentMethods);
Assert.Contains("BTC_LightningLike", serverInfoData.SupportedPaymentMethods);
Assert.NotNull(serverInfoData.Status.SyncStatus);
Assert.Single(serverInfoData.Status.SyncStatus.Select(s => s.CryptoCode == "BTC"));
Assert.NotNull(serverInfoData.SyncStatus);
Assert.Single(serverInfoData.SyncStatus.Select(s => s.CryptoCode == "BTC"));
}
}
@ -428,7 +427,7 @@ namespace BTCPayServer.Tests
[Fact(Timeout = TestTimeout)]
[Trait("Fast", "Fast")]
public async Task DecimalStringJsonConverterTests()
public void DecimalStringJsonConverterTests()
{
JsonReader Get(string val)
{

View file

@ -223,5 +223,5 @@
<_ContentIncludedByDefault Remove="Views\Authorization\Authorize.cshtml" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties wwwroot_4swagger_4v1_4swagger_1template_1json__JsonSchema="https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json" /></VisualStudio></ProjectExtensions>
<ProjectExtensions><VisualStudio><UserProperties wwwroot_4swagger_4v1_4swagger_1template_1json__JsonSchema="https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json" wwwroot_4swagger_4v1_4swagger_1template_1serverinfo_1json__JsonSchema="https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json" /></VisualStudio></ProjectExtensions>
</Project>

View file

@ -10,6 +10,7 @@ using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using NBXplorer.Models;
namespace BTCPayServer.Controllers.GreenField
{
@ -52,17 +53,19 @@ namespace BTCPayServer.Controllers.GreenField
.Select(summary => new ServerInfoSyncStatusData
{
CryptoCode = summary.Network.CryptoCode,
BlockHeaders = summary.Status.ChainHeight,
Progress = summary.Status.SyncHeight.GetValueOrDefault(0) / (float)summary.Status.ChainHeight
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
});
ServerInfoStatusData status = new ServerInfoStatusData
{
FullySynched = _dashBoard.IsFullySynched(),
SyncStatus = syncStatus
};
ServerInfoData model = new ServerInfoData
{
Status = status,
FullySynched = _dashBoard.IsFullySynched(),
SyncStatus = syncStatus,
Onion = _env.OnionUrl,
Version = _env.Version,
SupportedPaymentMethods = supportedPaymentMethods

View file

@ -34,9 +34,6 @@
"ApplicationServerInfoData": {
"type": "object",
"properties": {
"status": {
"$ref": "#/components/schemas/ApplicationServerInfoStatusData"
},
"version": {
"type": "string",
"description": "BTCPay Server version"
@ -51,13 +48,7 @@
"items": {
"type": "string"
}
}
}
},
"ApplicationServerInfoStatusData": {
"type": "object",
"description": "Detailed sync status",
"properties": {
},
"fullySynched": {
"type": "boolean",
"description": "True if the instance is fully synchronized, according to NBXplorer"
@ -70,22 +61,48 @@
}
}
},
"ApplicationServerInfoNodeStatusData": {
"type": "object",
"nullable": true,
"description": "Detailed sync status of the internal full node",
"properties": {
"headers": {
"type": "integer",
"description": "The height of the chain of header of the internal full node"
},
"blocks": {
"type": "integer",
"description": "The height of the latest validated block of the internal full node"
},
"verificationProgress": {
"type": "number",
"format": "double",
"minimum": 0.0,
"maximum": 1.0,
"description": "The current synchronization progress"
}
}
},
"ApplicationServerInfoSyncStatusData": {
"type": "object",
"description": "Detailed sync status",
"properties": {
"cryptoCode": {
"type": "string",
"description": "True if the instance is fully synchronized, according to NBXplorer"
"description": "The CryptoCode of the crypto currency (eg. BTC)"
},
"blockHeaders": {
"nodeInformation": {
"$ref": "#/components/schemas/ApplicationServerInfoNodeStatusData"
},
"chainHeight": {
"type": "integer",
"description": "True if the instance is fully synchronized, according to NBXplorer"
"description": "The height of the chain of header of the internal indexer"
},
"progress": {
"syncHeight": {
"type": "number",
"format": "double",
"description": "True if the instance is fully synchronized, according to NBXplorer"
"format": "integer",
"nullable": true,
"description": "The height of the latest indexed block of the internal indexer"
}
}
}

View file

@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.101 AS builder
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.202 AS builder
WORKDIR /source
COPY nuget.config nuget.config
COPY Build/Common.csproj Build/Common.csproj
@ -16,7 +16,7 @@ COPY BTCPayServer/. BTCPayServer/.
COPY Build/Version.csproj Build/Version.csproj
RUN cd BTCPayServer && dotnet publish --output /app/ --configuration Release
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.1-buster-slim
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.4-buster-slim
RUN apt-get update && apt-get install -y --no-install-recommends iproute2 openssh-client \
&& rm -rf /var/lib/apt/lists/*

View file

@ -1,5 +1,5 @@
# This is a manifest image, will pull the image with the same arch as the builder machine
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.101 AS builder
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.202 AS builder
RUN apt-get update \
&& apt-get install -qq --no-install-recommends qemu qemu-user-static qemu-user binfmt-support
@ -21,7 +21,7 @@ COPY Build/Version.csproj Build/Version.csproj
RUN cd BTCPayServer && dotnet publish --output /app/ --configuration Release
# Force the builder machine to take make an arm runtime image. This is fine as long as the builder does not run any program
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.1-buster-slim-arm32v7
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.4-buster-slim-arm32v7
COPY --from=builder /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static
RUN apt-get update && apt-get install -y --no-install-recommends iproute2 openssh-client \
&& rm -rf /var/lib/apt/lists/*

View file

@ -1,5 +1,5 @@
# This is a manifest image, will pull the image with the same arch as the builder machine
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.101 AS builder
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.202 AS builder
RUN apt-get update \
&& apt-get install -qq --no-install-recommends qemu qemu-user-static qemu-user binfmt-support
@ -21,7 +21,7 @@ COPY Build/Version.csproj Build/Version.csproj
RUN cd BTCPayServer && dotnet publish --output /app/ --configuration Release
# Force the builder machine to take make an arm runtime image. This is fine as long as the builder does not run any program
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.1-buster-slim-arm64v8
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.4-buster-slim-arm64v8
COPY --from=builder /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static
RUN apt-get update && apt-get install -y --no-install-recommends iproute2 openssh-client \
&& rm -rf /var/lib/apt/lists/*