Refactor server info data structure

This commit is contained in:
nicolas.dorier
2020-05-20 03:08:37 +09:00
parent 501a21b89e
commit 1d092a15fb
5 changed files with 60 additions and 41 deletions

View File

@@ -4,11 +4,6 @@ namespace BTCPayServer.Client.Models
{ {
public class ServerInfoData public class ServerInfoData
{ {
/// <summary>
/// detailed status information
/// </summary>
public ServerInfoStatusData Status { get; set; }
/// <summary> /// <summary>
/// the BTCPay Server version /// the BTCPay Server version
/// </summary> /// </summary>
@@ -23,10 +18,7 @@ namespace BTCPayServer.Client.Models
/// the payment methods this server supports /// the payment methods this server supports
/// </summary> /// </summary>
public IEnumerable<string> SupportedPaymentMethods { get; set; } public IEnumerable<string> SupportedPaymentMethods { get; set; }
}
public class ServerInfoStatusData
{
/// <summary> /// <summary>
/// are all chains fully synched /// are all chains fully synched
/// </summary> /// </summary>
@@ -41,7 +33,15 @@ namespace BTCPayServer.Client.Models
public class ServerInfoSyncStatusData public class ServerInfoSyncStatusData
{ {
public string CryptoCode { get; set; } public string CryptoCode { get; set; }
public int BlockHeaders { get; set; } public int ChainHeight { get; set; }
public float Progress { 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);
Assert.NotNull(serverInfoData.Version); Assert.NotNull(serverInfoData.Version);
Assert.NotNull(serverInfoData.Onion); Assert.NotNull(serverInfoData.Onion);
Assert.NotNull(serverInfoData.Status); Assert.True(serverInfoData.FullySynched);
Assert.True(serverInfoData.Status.FullySynched);
Assert.Contains("BTC", serverInfoData.SupportedPaymentMethods); Assert.Contains("BTC", serverInfoData.SupportedPaymentMethods);
Assert.Contains("BTC_LightningLike", serverInfoData.SupportedPaymentMethods); Assert.Contains("BTC_LightningLike", serverInfoData.SupportedPaymentMethods);
Assert.NotNull(serverInfoData.Status.SyncStatus); Assert.NotNull(serverInfoData.SyncStatus);
Assert.Single(serverInfoData.Status.SyncStatus.Select(s => s.CryptoCode == "BTC")); Assert.Single(serverInfoData.SyncStatus.Select(s => s.CryptoCode == "BTC"));
} }
} }
@@ -428,7 +427,7 @@ namespace BTCPayServer.Tests
[Fact(Timeout = TestTimeout)] [Fact(Timeout = TestTimeout)]
[Trait("Fast", "Fast")] [Trait("Fast", "Fast")]
public async Task DecimalStringJsonConverterTests() public void DecimalStringJsonConverterTests()
{ {
JsonReader Get(string val) JsonReader Get(string val)
{ {

View File

@@ -223,5 +223,5 @@
<_ContentIncludedByDefault Remove="Views\Authorization\Authorize.cshtml" /> <_ContentIncludedByDefault Remove="Views\Authorization\Authorize.cshtml" />
</ItemGroup> </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> </Project>

View File

@@ -10,6 +10,7 @@ using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NBXplorer.Models;
namespace BTCPayServer.Controllers.GreenField namespace BTCPayServer.Controllers.GreenField
{ {
@@ -52,17 +53,19 @@ namespace BTCPayServer.Controllers.GreenField
.Select(summary => new ServerInfoSyncStatusData .Select(summary => new ServerInfoSyncStatusData
{ {
CryptoCode = summary.Network.CryptoCode, CryptoCode = summary.Network.CryptoCode,
BlockHeaders = summary.Status.ChainHeight, NodeInformation = summary.Status.BitcoinStatus is BitcoinStatus s ? new ServerInfoNodeData()
Progress = summary.Status.SyncHeight.GetValueOrDefault(0) / (float)summary.Status.ChainHeight
});
ServerInfoStatusData status = new ServerInfoStatusData
{ {
FullySynched = _dashBoard.IsFullySynched(), Headers = s.Headers,
SyncStatus = syncStatus Blocks = s.Blocks,
}; VerificationProgress = s.VerificationProgress
}: null,
ChainHeight = summary.Status.ChainHeight,
SyncHeight = summary.Status.SyncHeight
});
ServerInfoData model = new ServerInfoData ServerInfoData model = new ServerInfoData
{ {
Status = status, FullySynched = _dashBoard.IsFullySynched(),
SyncStatus = syncStatus,
Onion = _env.OnionUrl, Onion = _env.OnionUrl,
Version = _env.Version, Version = _env.Version,
SupportedPaymentMethods = supportedPaymentMethods SupportedPaymentMethods = supportedPaymentMethods

View File

@@ -34,9 +34,6 @@
"ApplicationServerInfoData": { "ApplicationServerInfoData": {
"type": "object", "type": "object",
"properties": { "properties": {
"status": {
"$ref": "#/components/schemas/ApplicationServerInfoStatusData"
},
"version": { "version": {
"type": "string", "type": "string",
"description": "BTCPay Server version" "description": "BTCPay Server version"
@@ -51,13 +48,7 @@
"items": { "items": {
"type": "string" "type": "string"
} }
}
}
}, },
"ApplicationServerInfoStatusData": {
"type": "object",
"description": "Detailed sync status",
"properties": {
"fullySynched": { "fullySynched": {
"type": "boolean", "type": "boolean",
"description": "True if the instance is fully synchronized, according to NBXplorer" "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": { "ApplicationServerInfoSyncStatusData": {
"type": "object", "type": "object",
"description": "Detailed sync status", "description": "Detailed sync status",
"properties": { "properties": {
"cryptoCode": { "cryptoCode": {
"type": "string", "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", "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", "type": "number",
"format": "double", "format": "integer",
"description": "True if the instance is fully synchronized, according to NBXplorer" "nullable": true,
"description": "The height of the latest indexed block of the internal indexer"
} }
} }
} }