-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b86b805
commit cfa2006
Showing
9 changed files
with
1,253 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31624.102 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonitorIotaNode", "MonitorIotaNode\MonitorIotaNode.csproj", "{02FFB943-5097-4062-9F4D-53D2AEB6BBDA}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{02FFB943-5097-4062-9F4D-53D2AEB6BBDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{02FFB943-5097-4062-9F4D-53D2AEB6BBDA}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{02FFB943-5097-4062-9F4D-53D2AEB6BBDA}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{02FFB943-5097-4062-9F4D-53D2AEB6BBDA}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {02EC43CF-FCA1-4B19-9B93-F32BD920E229} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageReference Include="RestSharp" Version="106.12.0" /> | ||
<PackageReference Include="Serilog" Version="2.10.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" /> | ||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="settings.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using RestSharp; | ||
|
||
namespace MonitorIotaNode | ||
{ | ||
public class NodeEndpoint | ||
{ | ||
public Uri Uri { get; private set; } | ||
|
||
private RestClient client; | ||
private RestRequest request; | ||
|
||
public NodeEndpoint(Uri uri) | ||
{ | ||
this.Uri = uri; | ||
client = new RestClient(Uri); | ||
request = new RestRequest("", DataFormat.None); | ||
} | ||
|
||
public NodeInfo RetrieveNodeInfo() | ||
{ | ||
IRestResponse response = client.Get(request); | ||
string json = response.Content; | ||
return JsonConvert.DeserializeObject<NodeInfo>(json); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
Uri otherUri = (Uri)obj; | ||
return Uri.Equals(otherUri); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Uri.GetHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MonitorIotaNode | ||
{ | ||
public class NodeInfo | ||
{ | ||
public string Version { get; set; } | ||
public int NetworkVersion { get; set; } | ||
public string IdentityIdShort { get; set; } | ||
public int SolidMessageCount { get; set; } | ||
public int TotalMessageCount { get; set; } | ||
public TangleTime TangleTime { get; set; } | ||
public Mana Mana { get; set; } | ||
} | ||
|
||
public class TangleTime | ||
{ | ||
public bool Synced { get; set; } | ||
public long Time { get; set; } | ||
|
||
[JsonIgnore] | ||
public DateTime DateTime => UnixTimeStampToDateTime(Time / 1_000_000_000); | ||
|
||
public override string ToString() | ||
{ | ||
return $"TangleTime is {DateTime} and is{(Synced ? " " : " NOT ")}synced"; | ||
} | ||
|
||
private static DateTime UnixTimeStampToDateTime(double unixTimeStamp) | ||
{ | ||
// Unix timestamp is seconds past epoch | ||
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); | ||
dateTime = dateTime.AddSeconds(unixTimeStamp).ToLocalTime(); | ||
return dateTime; | ||
} | ||
} | ||
|
||
public class Mana | ||
{ | ||
public decimal Access { get; set; } | ||
public decimal Consensus { get; set; } | ||
|
||
public static Mana operator +(Mana manaOne) => manaOne; | ||
|
||
public static Mana operator -(Mana manaOne) => new Mana(-manaOne.Access, -manaOne.Consensus); | ||
|
||
public static Mana operator +(Mana manaOne, Mana manaTwo) => new Mana(manaOne.Access + manaTwo.Access, manaOne.Consensus + manaTwo.Consensus); | ||
|
||
public static Mana operator -(Mana manaOne, Mana manaTwo) => manaOne + (-manaTwo); | ||
|
||
public static Mana operator /(Mana manaOne, Mana manaTwo) | ||
{ | ||
if (manaTwo.Access == 0 || manaTwo.Consensus == 0) | ||
{ | ||
throw new DivideByZeroException(); | ||
} | ||
return new Mana(manaOne.Access / manaTwo.Access, manaOne.Consensus / manaTwo.Consensus); | ||
} | ||
|
||
public static Mana operator *(Mana manaOne, Mana manaTwo) => new Mana(manaOne.Access * manaTwo.Access, manaOne.Consensus * manaTwo.Consensus); | ||
|
||
public static Mana operator *(Mana manaOne, int factor) => new Mana(manaOne.Access * factor, manaOne.Consensus * factor); | ||
|
||
public Mana(decimal access, decimal consensus) | ||
{ | ||
Access = access; | ||
Consensus = consensus; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"Access Mana: {Access:0} - Consensus Mana: {Consensus}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.