Skip to content

Commit

Permalink
Merge pull request #46 from xeliuqa/develop
Browse files Browse the repository at this point in the history
4.06
  • Loading branch information
xeliuqa authored May 26, 2024
2 parents c9a0af5 + 6fec8bf commit bc995e8
Showing 1 changed file with 64 additions and 51 deletions.
115 changes: 64 additions & 51 deletions sm-monitor.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Requires -Version 7.0
<# -----------------------------------------------------------------------------------------------
<#PSScriptInfo
.VERSION 4.05
.VERSION 4.06
.GUID 98d4b6b6-00e1-4632-a836-33767fe196cd
.AUTHOR
.PROJECTURI https://github.com/xeliuqa/SM-Monitor
Expand All @@ -15,7 +15,7 @@ With Thanks To: == S A K K I == Stizerg == PlainLazy == Shanyaa == Miguell
Get grpcurl here: https://github.com/fullstorydev/grpcurl/releases
-------------------------------------------------------------------------------------------- #>
$version = "4.05"
$version = "4.06"
$host.ui.RawUI.WindowTitle = $MyInvocation.MyCommand.Name

function main {
Expand All @@ -30,6 +30,12 @@ function main {
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
}
if (!(Test-Path $grpcurl)) {
Write-Host "Error: grpcurl not found." -ForegroundColor Red
Write-Host "Press any key to continue ..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
}
# Import NodeList
$nodeListFile = ".\sm-nodeList.txt"
if (Test-Path $nodeListFile) {
Expand Down Expand Up @@ -400,14 +406,16 @@ function main {

$duplicateKeys = @{}
foreach ($node in $syncNodes.Values) {
if ($node.publicKey -ne $null) {
if ($duplicateKeys.ContainsKey($node.publicKey)) {
$duplicateKeys[$node.publicKey]++
} else {
$duplicateKeys[$node.publicKey] = 1
}
}
}
foreach ($node in $syncNodes.Values) {
if ($duplicateKeys[$node.publicKey] -gt 1) {
if (($node.publicKey -ne $null) -and ($duplicateKeys[$node.publicKey] -gt 1)) {
$node.shortKey = "!" + $node.shortKey
$node.fullkey = "!" + $node.fullkey
}
Expand Down Expand Up @@ -439,60 +447,67 @@ function main {

$object += $o
}

if ($rewardsTrackApp -and ($fileFormat -ne 0)) {
$files = Get-ChildItem -Path .\ -Filter "RewardsTrackApp_*.json"
foreach ($file in $files) {
Remove-Item $file.FullName
}
$timestamp = Get-Date -Format "HHmm"
if ($fileFormat -eq 1) {
$data = (Get-Content RewardsTrackApp.tmp -Raw) -replace '(?m)}\s+{', ',' | ConvertFrom-Json
$data | ConvertTo-Json -Depth 99 | Set-Content "RewardsTrackApp_$timestamp.json"
Remove-Item ".\RewardsTrackApp.tmp"
}
elseif ($fileFormat -eq 2) {
$rewardsTrackApp | ConvertTo-Json -Depth 99 | Set-Content "RewardsTrackApp_$timestamp.json"
}
elseif (($fileFormat -eq 3)) {
$rewardsTrackApp | ConvertTo-Json -Depth 99 | Set-Content "SM-Layers.json"

if (($stage -ne 4) -and ($stage -ne 2)) {
if ($rewardsTrackApp -and ($fileFormat -ne 0)) {
$files = Get-ChildItem -Path .\ -Filter "RewardsTrackApp_*.json"
foreach ($file in $files) {
Remove-Item $file.FullName
}
$timestamp = Get-Date -Format "HHmm"
if ($fileFormat -eq 1) {
$data = (Get-Content RewardsTrackApp.tmp -Raw) -replace '(?m)}\s+{', ',' | ConvertFrom-Json
$data | ConvertTo-Json -Depth 99 | Set-Content "RewardsTrackApp_$timestamp.json"
Remove-Item ".\RewardsTrackApp.tmp"
}
elseif ($fileFormat -eq 2) {
$rewardsTrackApp | ConvertTo-Json -Depth 99 | Set-Content "RewardsTrackApp_$timestamp.json"
}
elseif (($fileFormat -eq 3)) {
$rewardsTrackApp | ConvertTo-Json -Depth 99 | Set-Content "SM-Layers.json"
}
}
}

if (($stage -ne 4) -and ($stage -ne 1)) {
# Find all private nodes, then select the first in the list. Once we have this, we know that we have a good Online Local Private Node
# Find all online nodes, then select the one that works.
$filterObjects = $object | Where-Object { $_.Synced -match "True" } # -and $_.Host -match "localhost" -and $_.status -match "True"
$coinbase = $null
$balance = $null
if ($filterObjects) {
$privateOnlineNodes = $filterObjects[0]
$onlineNode = $filterObjects[0]
if (($checkIfBanned -eq "True") -and !$malfeasanceStream) {
$malfeasanceStream = (Invoke-Expression ("$($grpcurl) --plaintext -max-time 5 $($privateOnlineNodes.Host):$($privateOnlineNodes.Port) spacemesh.v1.MeshService.MalfeasanceStream")) 2>$null
}
}
else {
$privateOnlineNodes = $null
}
}

# If private nodes are found, determine the PS version and execute corresponding grpcurl if statement. Else skip.
if (($showWalletBalance -eq "True") -and $privateOnlineNodes.name.count -gt 0) {
$coinbase = (Invoke-Expression "$grpcurl --plaintext -max-time 10 $($privateOnlineNodes.Host):$($privateOnlineNodes.Port2) spacemesh.v1.SmesherService.Coinbase" | ConvertFrom-Json).accountId.address
$jsonPayload = "{ `"filter`": { `"account_id`": { `"address`": `"$coinbase`" }, `"account_data_flags`": 4 } }"
$balance = (Invoke-Expression "$grpcurl -plaintext -d '$jsonPayload' -max-time 10 $($privateOnlineNodes.Host):$($privateOnlineNodes.Port) spacemesh.v1.GlobalStateService.AccountDataQuery" | ConvertFrom-Json).accountItem.accountWrapper.stateCurrent.balance.value
$balanceSMH = [string]([math]::Round($balance / 1000000000, 3)) + " SMH"
$coinbase = "($coinbase)"
if ($fakeCoins -ne 0) { [string]$balanceSMH = "$($fakeCoins) SMH" }
if ($coinbaseAddressVisibility -eq "partial") {
$coinbase = '(' + $($coinbase).Substring($($coinbase).IndexOf(")") - 4, 4) + ')'
}
elseif ($coinbaseAddressVisibility -eq "hidden") {
$coinbase = "(----)"
$malfeasanceStream = (Invoke-Expression ("$($grpcurl) --plaintext -max-time 5 $($onlineNode.Host):$($onlineNode.Port) spacemesh.v1.MeshService.MalfeasanceStream")) 2>$null
}
if ($showWalletBalance -eq "True") {
foreach ($node in $filterObjects) {
$onlineNode = $node
$coinbase = (Invoke-Expression "$grpcurl --plaintext -max-time 5 $($onlineNode.Host):$($onlineNode.Port2) spacemesh.v1.SmesherService.Coinbase" | ConvertFrom-Json).accountId.address 2>$null
if ($coinbase) {
break
}
}

if ($coinbase) {
$jsonPayload = "{ `"filter`": { `"account_id`": { `"address`": `"$coinbase`" }, `"account_data_flags`": 4 } }"
$balance = (Invoke-Expression "$grpcurl -plaintext -d '$jsonPayload' -max-time 5 $($onlineNode.Host):$($onlineNode.Port) spacemesh.v1.GlobalStateService.AccountDataQuery" | ConvertFrom-Json).accountItem.accountWrapper.stateCurrent.balance.value 2>$null
$balanceSMH = [string]([math]::Round($balance / 1000000000, 3)) + " SMH"
$coinbase = "($coinbase)"
if ($fakeCoins -ne 0) { [string]$balanceSMH = "$($fakeCoins) SMH" }
if ($coinbaseAddressVisibility -eq "partial") {
$coinbase = '(' + $($coinbase).Substring($($coinbase).IndexOf(")") - 4, 4) + ')'
}
elseif ($coinbaseAddressVisibility -eq "hidden") {
$coinbase = "(----)"
}
} else {
$coinbase = ""
$balanceSMH = "Unable to retrieve the balance at the moment"
}
}
}
}
else {
$coinbase = ""
$balanceSMH = "Unable to retrieve the balance at the moment"
}


$columnRules = applyColumnRules

Clear-Host
Expand Down Expand Up @@ -968,8 +983,6 @@ function printSMMonitorLogo {

$CursorPosition = [System.Management.Automation.Host.Coordinates]::new(0, $lines.Length + $verticalOffset + 1)
$host.UI.RawUI.CursorPosition = $CursorPosition
# Start-Sleep $logoDelay
# Clear-Host
}

function applyColumnRules {
Expand Down

0 comments on commit bc995e8

Please sign in to comment.