Skip to content

Commit

Permalink
Merge pull request #16 from GalaxyPay/dev
Browse files Browse the repository at this point in the history
chore: release v1.3.0
  • Loading branch information
acfunk authored Nov 8, 2024
2 parents 26f3166 + 9296351 commit 764f5d8
Show file tree
Hide file tree
Showing 26 changed files with 475 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ jobs:
uses: ncipollo/release-action@v1
with:
allowUpdates: true
tag: v1.2.2
tag: v1.3.0
artifacts: "Output\\AvmWinNode_Setup.exe"
2 changes: 1 addition & 1 deletion AvmWinNode.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "AvmWinNode"
#define MyAppVersion "1.2.2"
#define MyAppVersion "1.3.0"
#define MyAppPublisher "Galaxy Pay, LLC"
#define MyAppPublisherURL "https://galaxy-pay.com"
#define MyPublishPath "publish"
Expand Down
1 change: 1 addition & 0 deletions AvmWinNode/AvmWinNode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Octokit" Version="13.0.1" />
</ItemGroup>

Expand Down
55 changes: 43 additions & 12 deletions AvmWinNode/Controllers/AlgorandController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AvmWinNode.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using static System.Environment;

namespace AvmWinNode.Controllers
Expand All @@ -18,18 +19,32 @@ public async Task<ActionResult<NodeStatus>> GetAlgorand()
{
try
{
string net = ":0";
try { net = System.IO.File.ReadAllText(_dataPath + @"algorand\algod.net").Replace("\n", ""); } catch { }
int port = int.Parse(net[(net.LastIndexOf(":") + 1)..]);
int port = 0;
string token = string.Empty;
try { token = System.IO.File.ReadAllText(_dataPath + @"algorand\algod.admin.token"); } catch { }
bool p2p = false;
string? configText = null;
try { configText = System.IO.File.ReadAllText(_dataPath + @"algorand\config.json"); } catch { }
if (configText != null)
{
JObject config = JObject.Parse(configText);
var endpointAddressToken = config.GetValue("EndpointAddress");
string endpointAddress = endpointAddressToken?.Value<string>() ?? ":0";
port = int.Parse(endpointAddress[(endpointAddress.IndexOf(":") + 1)..]);
var enableP2PToken = config.GetValue("EnableP2P");
var enableP2PHybridModeToken = config.GetValue("EnableP2PHybridMode");
bool enableP2P = enableP2PToken != null && enableP2PToken.Value<bool>();
bool enableP2PHybridMode = enableP2PHybridModeToken != null && enableP2PHybridModeToken.Value<bool>();
if (enableP2P || enableP2PHybridMode) p2p = true;
}
string sc = await Utils.ExecCmd(@"sc query ""Algorand Node""");
string serviceStatus = Utils.ParseServiceStatus(sc);
NodeStatus nodeStatus = new()
{
ServiceStatus = serviceStatus,
Port = port,
Token = token,
ServiceStatus = serviceStatus
P2p = p2p,
};
return nodeStatus;
}
Expand Down Expand Up @@ -83,14 +98,7 @@ public async Task<ActionResult<string>> CatchupAlgorandNode(Catchup model)
{
try
{
var round = model.Catchpoint.Split('#')[0];
var data = model.Catchpoint.Split('#')[1];
if (string.IsNullOrEmpty(model.Catchpoint)
|| model.Catchpoint.Any(Char.IsWhiteSpace)
|| !int.TryParse(round, out _)
|| data.Length != 52)
return BadRequest();
string cmd = string.Format(_dataPath + "goal node catchup {0} -d " + _dataPath + "algorand", model.Catchpoint);
string cmd = $"{_dataPath}goal node catchup {model.Round}#{model.Label} -d {_dataPath}algorand";
return await Utils.ExecCmd(cmd);
}
catch (Exception ex)
Expand Down Expand Up @@ -140,5 +148,28 @@ public async Task<ActionResult<string>> DeleteAlgorandService()
return BadRequest(ex.Message);
}
}

// GET: algorand/config
[HttpGet("config")]
public async Task<ActionResult<string>> GetConfig()
{
if (!Directory.Exists($"{_dataPath}algorand"))
{
await Utils.ExecCmd($@"tar -xf ""{AppContext.BaseDirectory}Templates\algorand.zip"" -C {_dataPath}");
}
string config = System.IO.File.ReadAllText($@"{_dataPath}algorand\config.json");
return config;
}

// PUT: algorand/config
[HttpPut("config")]
public ActionResult SetConfig(Config model)
{
using (StreamWriter writer = new($@"{_dataPath}algorand\config.json", false))
{
writer.Write(model.Json);
}
return Ok();
}
}
}
56 changes: 43 additions & 13 deletions AvmWinNode/Controllers/FnetController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AvmWinNode.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using static System.Environment;

namespace AvmWinNode.Controllers
Expand All @@ -18,14 +19,26 @@ public async Task<ActionResult<NodeStatus>> GetFnet()
{
try
{
string net = ":0";
try { net = System.IO.File.ReadAllText(_dataPath + @"fnet\algod.net").Replace("\n", ""); } catch { }
int port = int.Parse(net[(net.LastIndexOf(":") + 1)..]);
int port = 0;
string token = string.Empty;
try { token = System.IO.File.ReadAllText(_dataPath + @"fnet\algod.admin.token"); } catch { }
string fnetQuery = await Utils.ExecCmd(@"sc query ""Fnet Node""");
string nodeServiceStatus = Utils.ParseServiceStatus(fnetQuery);

bool p2p = false;
string? configText = null;
try { configText = System.IO.File.ReadAllText(_dataPath + @"fnet\config.json"); } catch { }
if (configText != null)
{
JObject config = JObject.Parse(configText);
var endpointAddressToken = config.GetValue("EndpointAddress");
string endpointAddress = endpointAddressToken?.Value<string>() ?? ":0";
port = int.Parse(endpointAddress[(endpointAddress.IndexOf(":") + 1)..]);
var enableP2PToken = config.GetValue("EnableP2P");
var enableP2PHybridModeToken = config.GetValue("EnableP2PHybridMode");
bool enableP2P = enableP2PToken != null && enableP2PToken.Value<bool>();
bool enableP2PHybridMode = enableP2PHybridModeToken != null && enableP2PHybridModeToken.Value<bool>();
if (enableP2P || enableP2PHybridMode) p2p = true;
}
// Reti Status
string retiQuery = await Utils.ExecCmd(@"sc query ""Reti Validator""");
string retiServiceStatus = Utils.ParseServiceStatus(retiQuery);
Expand Down Expand Up @@ -64,7 +77,8 @@ public async Task<ActionResult<NodeStatus>> GetFnet()
ServiceStatus = nodeServiceStatus,
Port = port,
Token = token,
RetiStatus = retiStatus
P2p = p2p,
RetiStatus = retiStatus,
};

return nodeStatus;
Expand Down Expand Up @@ -119,14 +133,7 @@ public async Task<ActionResult<string>> CatchupFnetNode(Catchup model)
{
try
{
var round = model.Catchpoint.Split('#')[0];
var data = model.Catchpoint.Split('#')[1];
if (string.IsNullOrEmpty(model.Catchpoint)
|| model.Catchpoint.Any(Char.IsWhiteSpace)
|| !int.TryParse(round, out _)
|| data.Length != 52)
return BadRequest();
string cmd = string.Format(_dataPath + "goal node catchup {0} -d " + _dataPath + "fnet", model.Catchpoint);
string cmd = $"{_dataPath}goal node catchup {model.Round}#{model.Label} -d {_dataPath}fnet";
return await Utils.ExecCmd(cmd);
}
catch (Exception ex)
Expand Down Expand Up @@ -176,5 +183,28 @@ public async Task<ActionResult<string>> DeleteFnetService()
return BadRequest(ex.Message);
}
}

// GET: fnet/config
[HttpGet("config")]
public async Task<ActionResult<string>> GetConfig()
{
if (!Directory.Exists($"{_dataPath}fnet"))
{
await Utils.ExecCmd($@"tar -xf ""{AppContext.BaseDirectory}Templates\fnet.zip"" -C {_dataPath}");
}
string config = System.IO.File.ReadAllText($@"{_dataPath}fnet\config.json");
return config;
}

// PUT: fnet/config
[HttpPut("config")]
public ActionResult SetConfig(Config model)
{
using (StreamWriter writer = new($@"{_dataPath}fnet\config.json", false))
{
writer.Write(model.Json);
}
return Ok();
}
}
}
24 changes: 18 additions & 6 deletions AvmWinNode/Controllers/GoalController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AvmWinNode.Models;
using Microsoft.AspNetCore.Mvc;
using static System.Environment;

Expand All @@ -10,15 +11,14 @@ public class GoalController(ILogger<GoalController> logger) : ControllerBase

private readonly ILogger<GoalController> _logger = logger;
private readonly string _dataPath = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), @"AvmWinNode\");
private readonly string _releasePath = "https://github.com/GalaxyPay/algowin/releases/latest/download/";

// GET: goal/version
[HttpGet("version")]
public async Task<ActionResult<string>> GoalVersion()
{
try
{
return await Utils.ExecCmd(_dataPath + "goal --version");
return await Utils.ExecCmd($"{_dataPath}goal --version");
}
catch (Exception ex)
{
Expand All @@ -28,13 +28,25 @@ public async Task<ActionResult<string>> GoalVersion()

// POST: goal/update
[HttpPost("update")]
public async Task<ActionResult<string>> GoalUpdate()
public async Task<ActionResult<string>> GoalUpdate(Release model)
{
try
{
await Utils.ExecCmd("curl -sL -o " + _dataPath + "algod.exe " + _releasePath + "algod.exe");
await Utils.ExecCmd("curl -sL -o " + _dataPath + "goal.exe " + _releasePath + "goal.exe");
await Utils.ExecCmd("curl -sL -o " + _dataPath + "kmd.exe " + _releasePath + "kmd.exe");
string releasePath = "https://github.com/GalaxyPay/algowin/releases/";

if (model.Name == "latest")
{
releasePath += "latest/download/";
}
else
{
releasePath += $"download/{model.Name}/";
}

await Utils.ExecCmd($"curl -sL -o {_dataPath}algod.exe {releasePath}algod.exe");
await Utils.ExecCmd($"curl -sL -o {_dataPath}goal.exe {releasePath}goal.exe");
await Utils.ExecCmd($"curl -sL -o {_dataPath}kmd.exe {releasePath}kmd.exe");

return Ok();
}
catch (Exception ex)
Expand Down
55 changes: 43 additions & 12 deletions AvmWinNode/Controllers/VoiController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AvmWinNode.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using static System.Environment;

namespace AvmWinNode.Controllers
Expand All @@ -18,18 +19,32 @@ public async Task<ActionResult<NodeStatus>> GetVoi()
{
try
{
string net = ":0";
try { net = System.IO.File.ReadAllText(_dataPath + @"voi\algod.net").Replace("\n", ""); } catch { }
int port = int.Parse(net[(net.LastIndexOf(":") + 1)..]);
int port = 0;
string token = string.Empty;
try { token = System.IO.File.ReadAllText(_dataPath + @"voi\algod.admin.token"); } catch { }
string sc = await Utils.ExecCmd(@"sc query ""Voi Node""");
string serviceStatus = Utils.ParseServiceStatus(sc);
bool p2p = false;
string? configText = null;
try { configText = System.IO.File.ReadAllText(_dataPath + @"voi\config.json"); } catch { }
if (configText != null)
{
JObject config = JObject.Parse(configText);
var endpointAddressToken = config.GetValue("EndpointAddress");
string endpointAddress = endpointAddressToken?.Value<string>() ?? ":0";
port = int.Parse(endpointAddress[(endpointAddress.IndexOf(":") + 1)..]);
var enableP2PToken = config.GetValue("EnableP2P");
var enableP2PHybridModeToken = config.GetValue("EnableP2PHybridMode");
bool enableP2P = enableP2PToken != null && enableP2PToken.Value<bool>();
bool enableP2PHybridMode = enableP2PHybridModeToken != null && enableP2PHybridModeToken.Value<bool>();
if (enableP2P || enableP2PHybridMode) p2p = true;
}
NodeStatus nodeStatus = new()
{
ServiceStatus = serviceStatus,
Port = port,
Token = token,
ServiceStatus = serviceStatus
P2p = p2p,
};
return nodeStatus;
}
Expand Down Expand Up @@ -83,14 +98,7 @@ public async Task<ActionResult<string>> CatchupVoiNode(Catchup model)
{
try
{
var round = model.Catchpoint.Split('#')[0];
var data = model.Catchpoint.Split('#')[1];
if (string.IsNullOrEmpty(model.Catchpoint)
|| model.Catchpoint.Any(Char.IsWhiteSpace)
|| !int.TryParse(round, out _)
|| data.Length != 52)
return BadRequest();
string cmd = string.Format(_dataPath + "goal node catchup {0} -d " + _dataPath + "voi", model.Catchpoint);
string cmd = $"{_dataPath}goal node catchup {model.Round}#{model.Label} -d {_dataPath}voi";
return await Utils.ExecCmd(cmd);
}
catch (Exception ex)
Expand Down Expand Up @@ -140,5 +148,28 @@ public async Task<ActionResult<string>> DeleteVoiService()
return BadRequest(ex.Message);
}
}

// GET: voi/config
[HttpGet("config")]
public async Task<ActionResult<string>> GetConfig()
{
if (!Directory.Exists($"{_dataPath}voi"))
{
await Utils.ExecCmd($@"tar -xf ""{AppContext.BaseDirectory}Templates\voi.zip"" -C {_dataPath}");
}
string config = System.IO.File.ReadAllText($@"{_dataPath}voi\config.json");
return config;
}

// PUT: voi/config
[HttpPut("config")]
public ActionResult SetConfig(Config model)
{
using (StreamWriter writer = new($@"{_dataPath}voi\config.json", false))
{
writer.Write(model.Json);
}
return Ok();
}
}
}
9 changes: 7 additions & 2 deletions AvmWinNode/Models/Catchup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace AvmWinNode.Models
using System.ComponentModel.DataAnnotations;

namespace AvmWinNode.Models
{
public class Catchup
{
public required string Catchpoint { get; set; }
public required uint Round { get; set; }

[RegularExpression("^[A-Z0-9]{52}$", ErrorMessage = "Invalid Label")]
public required string Label { get; set; }
}
}
7 changes: 7 additions & 0 deletions AvmWinNode/Models/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AvmWinNode.Models
{
public class Config
{
public required string Json { get; set; }
}
}
1 change: 1 addition & 0 deletions AvmWinNode/Models/NodeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class NodeStatus
public required string ServiceStatus { get; set; }
public required int Port { get; set; }
public required string Token { get; set; }
public required bool P2p { get; set; }
public RetiStatus? RetiStatus { get; set; }
}

Expand Down
12 changes: 12 additions & 0 deletions AvmWinNode/Models/Release.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;

namespace AvmWinNode.Models
{
public class Release
{
[MaxLength(20)]
[RegularExpression("^[a-z0-9\\.\\-]+$", ErrorMessage = "Invalid Name")]
public required string Name { get; set; }
}

}
Binary file modified AvmWinNode/Templates/algorand.zip
Binary file not shown.
Binary file modified AvmWinNode/Templates/fnet.zip
Binary file not shown.
Binary file modified AvmWinNode/Templates/voi.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion webui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "avm-win-node-webui",
"version": "1.2.2",
"version": "1.3.0",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
Expand Down
Loading

0 comments on commit 764f5d8

Please sign in to comment.