Skip to content

Commit

Permalink
Added nodehealthstatus
Browse files Browse the repository at this point in the history
  • Loading branch information
wireless90 committed May 16, 2024
1 parent be325ef commit 03e54c0
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 6 deletions.
25 changes: 19 additions & 6 deletions IotaSDK.NET/Client.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -48,5 +51,15 @@ public async Task<IotaSDKResponse<ClientOutputsResponse>> GetNftOutputIdsAsync(L
{
return await _mediator.Send(new GetNftOutputIdsQuery(_clientHandle, nftQueryParameters));
}

public async Task<IotaSDKResponse<Node>> GetHealthyNodeAsync()
{
return await _mediator.Send(new GetNodeQuery(_clientHandle));
}

public async Task<IotaSDKResponse<bool>> GetNodeHealthStatusAsync(string url)
{
return await _mediator.Send(new GetNodeHealthStatusQuery(_clientHandle, url));
}
}
}
5 changes: 5 additions & 0 deletions IotaSDK.NET/Common/Interfaces/IClient.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +14,10 @@ public interface IClient
Task<IotaSDKResponse<List<ClientOutputResponse>>> GetOutputsAsync(List<string> outputIds);
Task<IotaSDKResponse<FaucetResponse>> RequestFundsFromFaucetAsync(string bech32Address);

Task<IotaSDKResponse<Node>> GetHealthyNodeAsync();

Task<IotaSDKResponse<bool>> GetNodeHealthStatusAsync(string url);

Task<IotaSDKResponse<ClientOutputsResponse>> GetNftOutputIdsAsync(List<INftQueryParameter> nftQueryParameters);
}
}
14 changes: 14 additions & 0 deletions IotaSDK.NET/Contexts/ClientContext/Queries/GetNode/GetNodeQuery.cs
Original file line number Diff line number Diff line change
@@ -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<IotaSDKResponse<Node>>
{
public GetNodeQuery(IntPtr clientHandle) : base(clientHandle)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -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<GetNodeQuery, IotaSDKResponse<Node>>
{
private readonly RustBridgeClient _rustBridgeClient;

public GetNodeQueryHandler(RustBridgeClient rustBridgeClient)
{
_rustBridgeClient = rustBridgeClient;
}

public async Task<IotaSDKResponse<Node>> 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<Node>.CreateInstance(clientResponse);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<IotaSDKResponse<bool>>
{
public GetNodeHealthStatusQuery(IntPtr clientHandle, string url) : base(clientHandle)
{
Url = url;
}

public string Url { get; }
}
}
Original file line number Diff line number Diff line change
@@ -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<GetNodeHealthStatusQuery, IotaSDKResponse<bool>>
{
private readonly RustBridgeClient _client;

public GetNodeHealthStatusQueryHandler(RustBridgeClient client)
{
_client = client;
}

public async Task<IotaSDKResponse<bool>> Handle(GetNodeHealthStatusQuery request, CancellationToken cancellationToken)
{
var modelData = new GetNodeHealthStatusQueryModelData(request.Url);
var model = new IotaSDKModel<GetNodeHealthStatusQueryModelData>("getHealth", modelData);
var json = model.AsJson();

string? clientResponse = await _client.CallClientMethodAsync(request.ClientHandle, json);

IotaSDKException.CheckForException(clientResponse!);

return IotaSDKResponse<bool>.CreateInstance(clientResponse);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace IotaSDK.NET.Contexts.ClientContext.Queries.GetNodeHealthStatus
{
internal class GetNodeHealthStatusQueryModelData
{
public GetNodeHealthStatusQueryModelData(string url)
{
Url = url;
}

public string Url { get; }
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ To install,
</summary>
<ul>
<li>GetNftOutputIds</li>
<li>GetNode</li>
<li>GetNodeHealthStatus</li>
<li>GetOutput</li>
<li>GetOutputs</li>
</ul>
Expand Down

0 comments on commit 03e54c0

Please sign in to comment.