From 03e54c0c1799e23978c3591704d2d4e1e1001ff6 Mon Sep 17 00:00:00 2001 From: wireless90 <12537739+wireless90@users.noreply.github.com> Date: Fri, 17 May 2024 02:05:49 +0800 Subject: [PATCH] Added nodehealthstatus --- IotaSDK.NET/Client.cs | 25 +++++++++++---- IotaSDK.NET/Common/Interfaces/IClient.cs | 5 +++ .../Queries/GetNode/GetNodeQuery.cs | 14 ++++++++ .../Queries/GetNode/GetNodeQueryHandler.cs | 32 +++++++++++++++++++ .../GetNodeHealthStatusQuery.cs | 16 ++++++++++ .../GetNodeHealthStatusQueryHandler.cs | 32 +++++++++++++++++++ .../GetNodeHealthStatusQueryModelData.cs | 12 +++++++ README.md | 2 ++ 8 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQuery.cs create mode 100644 IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQueryHandler.cs create mode 100644 IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQuery.cs create mode 100644 IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQueryHandler.cs create mode 100644 IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQueryModelData.cs diff --git a/IotaSDK.NET/Client.cs b/IotaSDK.NET/Client.cs index 1fa533a..12af893 100644 --- a/IotaSDK.NET/Client.cs +++ b/IotaSDK.NET/Client.cs @@ -1,16 +1,19 @@ using IotaSDK.NET.Common.Interfaces; using IotaSDK.NET.Common.Models; -using IotaSDK.NET.Contexts.ClientContext.Queries.GetOutput; using IotaSDK.NET.Contexts.ClientContext.Commands.RequestFundsFromFaucet; +using IotaSDK.NET.Contexts.ClientContext.Queries.GetNftOutputIds; +using IotaSDK.NET.Contexts.ClientContext.Queries.GetNode; +using IotaSDK.NET.Contexts.ClientContext.Queries.GetNodeHealthStatus; +using IotaSDK.NET.Contexts.ClientContext.Queries.GetOutput; +using IotaSDK.NET.Contexts.ClientContext.Queries.GetOutputs; using IotaSDK.NET.Domain.Faucet; +using IotaSDK.NET.Domain.Network; +using IotaSDK.NET.Domain.Outputs; +using IotaSDK.NET.Domain.Queries; using MediatR; using System; -using System.Threading.Tasks; -using IotaSDK.NET.Domain.Outputs; using System.Collections.Generic; -using IotaSDK.NET.Contexts.ClientContext.Queries.GetOutputs; -using IotaSDK.NET.Domain.Queries; -using IotaSDK.NET.Contexts.ClientContext.Queries.GetNftOutputIds; +using System.Threading.Tasks; namespace IotaSDK.NET { @@ -48,5 +51,15 @@ public async Task> GetNftOutputIdsAsync(L { return await _mediator.Send(new GetNftOutputIdsQuery(_clientHandle, nftQueryParameters)); } + + public async Task> GetHealthyNodeAsync() + { + return await _mediator.Send(new GetNodeQuery(_clientHandle)); + } + + public async Task> GetNodeHealthStatusAsync(string url) + { + return await _mediator.Send(new GetNodeHealthStatusQuery(_clientHandle, url)); + } } } diff --git a/IotaSDK.NET/Common/Interfaces/IClient.cs b/IotaSDK.NET/Common/Interfaces/IClient.cs index af402c9..77b3d72 100644 --- a/IotaSDK.NET/Common/Interfaces/IClient.cs +++ b/IotaSDK.NET/Common/Interfaces/IClient.cs @@ -1,5 +1,6 @@ using IotaSDK.NET.Common.Models; using IotaSDK.NET.Domain.Faucet; +using IotaSDK.NET.Domain.Network; using IotaSDK.NET.Domain.Outputs; using IotaSDK.NET.Domain.Queries; using System.Collections.Generic; @@ -13,6 +14,10 @@ public interface IClient Task>> GetOutputsAsync(List outputIds); Task> RequestFundsFromFaucetAsync(string bech32Address); + Task> GetHealthyNodeAsync(); + + Task> GetNodeHealthStatusAsync(string url); + Task> GetNftOutputIdsAsync(List nftQueryParameters); } } diff --git a/IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQuery.cs b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQuery.cs new file mode 100644 index 0000000..af33dd3 --- /dev/null +++ b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQuery.cs @@ -0,0 +1,14 @@ +using IotaSDK.NET.Common.Interfaces; +using IotaSDK.NET.Common.Models; +using IotaSDK.NET.Domain.Network; +using System; + +namespace IotaSDK.NET.Contexts.ClientContext.Queries.GetNode +{ + internal class GetNodeQuery : ClientRequest> + { + public GetNodeQuery(IntPtr clientHandle) : base(clientHandle) + { + } + } +} diff --git a/IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQueryHandler.cs b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQueryHandler.cs new file mode 100644 index 0000000..aefde3c --- /dev/null +++ b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQueryHandler.cs @@ -0,0 +1,32 @@ +using IotaSDK.NET.Common.Exceptions; +using IotaSDK.NET.Common.Models; +using IotaSDK.NET.Common.Rust; +using IotaSDK.NET.Domain.Network; +using MediatR; +using System.Threading; +using System.Threading.Tasks; + +namespace IotaSDK.NET.Contexts.ClientContext.Queries.GetNode +{ + internal class GetNodeQueryHandler : IRequestHandler> + { + private readonly RustBridgeClient _rustBridgeClient; + + public GetNodeQueryHandler(RustBridgeClient rustBridgeClient) + { + _rustBridgeClient = rustBridgeClient; + } + + public async Task> Handle(GetNodeQuery request, CancellationToken cancellationToken) + { + IotaSDKModel model = new IotaSDKModel("getNode"); + var json = model.AsJson(); + + string? clientResponse = await _rustBridgeClient.CallClientMethodAsync(request.ClientHandle, json); + + IotaSDKException.CheckForException(clientResponse!); + + return IotaSDKResponse.CreateInstance(clientResponse); + } + } +} diff --git a/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQuery.cs b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQuery.cs new file mode 100644 index 0000000..9f4be71 --- /dev/null +++ b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQuery.cs @@ -0,0 +1,16 @@ +using IotaSDK.NET.Common.Interfaces; +using IotaSDK.NET.Common.Models; +using System; + +namespace IotaSDK.NET.Contexts.ClientContext.Queries.GetNodeHealthStatus +{ + internal class GetNodeHealthStatusQuery : ClientRequest> + { + public GetNodeHealthStatusQuery(IntPtr clientHandle, string url) : base(clientHandle) + { + Url = url; + } + + public string Url { get; } + } +} diff --git a/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQueryHandler.cs b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQueryHandler.cs new file mode 100644 index 0000000..1bf3c25 --- /dev/null +++ b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQueryHandler.cs @@ -0,0 +1,32 @@ +using IotaSDK.NET.Common.Exceptions; +using IotaSDK.NET.Common.Models; +using IotaSDK.NET.Common.Rust; +using MediatR; +using System.Threading; +using System.Threading.Tasks; + +namespace IotaSDK.NET.Contexts.ClientContext.Queries.GetNodeHealthStatus +{ + internal class GetNodeHealthStatusQueryHandler : IRequestHandler> + { + private readonly RustBridgeClient _client; + + public GetNodeHealthStatusQueryHandler(RustBridgeClient client) + { + _client = client; + } + + public async Task> Handle(GetNodeHealthStatusQuery request, CancellationToken cancellationToken) + { + var modelData = new GetNodeHealthStatusQueryModelData(request.Url); + var model = new IotaSDKModel("getHealth", modelData); + var json = model.AsJson(); + + string? clientResponse = await _client.CallClientMethodAsync(request.ClientHandle, json); + + IotaSDKException.CheckForException(clientResponse!); + + return IotaSDKResponse.CreateInstance(clientResponse); + } + } +} diff --git a/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQueryModelData.cs b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQueryModelData.cs new file mode 100644 index 0000000..d7ffa0a --- /dev/null +++ b/IotaSDK.NET/Contexts/ClientContext/Queries/GetNodeHealthStatus/GetNodeHealthStatusQueryModelData.cs @@ -0,0 +1,12 @@ +namespace IotaSDK.NET.Contexts.ClientContext.Queries.GetNodeHealthStatus +{ + internal class GetNodeHealthStatusQueryModelData + { + public GetNodeHealthStatusQueryModelData(string url) + { + Url = url; + } + + public string Url { get; } + } +} diff --git a/README.md b/README.md index b7cbae9..4f629fe 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,8 @@ To install,
  • GetNftOutputIds
  • +
  • GetNode
  • +
  • GetNodeHealthStatus
  • GetOutput
  • GetOutputs