Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neo-node Migration #2990

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions neo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.VM", "src\Neo.VM\Neo.VM
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.VM.Tests", "tests\Neo.VM.Tests\Neo.VM.Tests.csproj", "{005F84EB-EA2E-449F-930A-7B4173DDC7EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.ConsoleService", "src\Neo.ConsoleService\Neo.ConsoleService.csproj", "{9E886812-7243-48D8-BEAF-47AADC11C054}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.GUI", "src\Neo.GUI\Neo.GUI.csproj", "{02ABDE42-9880-43B4-B6F7-8D618602A277}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.CLI", "src\Neo.CLI\Neo.CLI.csproj", "{BDFBE455-4C1F-4FC4-B5FC-1387B93A8687}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.ConsoleService.Tests", "tests\Neo.ConsoleService.Tests\Neo.ConsoleService.Tests.csproj", "{B40F8584-5AFB-452C-AEFA-009C80CC23A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -62,6 +70,22 @@ Global
{005F84EB-EA2E-449F-930A-7B4173DDC7EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{005F84EB-EA2E-449F-930A-7B4173DDC7EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{005F84EB-EA2E-449F-930A-7B4173DDC7EC}.Release|Any CPU.Build.0 = Release|Any CPU
{9E886812-7243-48D8-BEAF-47AADC11C054}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E886812-7243-48D8-BEAF-47AADC11C054}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E886812-7243-48D8-BEAF-47AADC11C054}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E886812-7243-48D8-BEAF-47AADC11C054}.Release|Any CPU.Build.0 = Release|Any CPU
{02ABDE42-9880-43B4-B6F7-8D618602A277}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02ABDE42-9880-43B4-B6F7-8D618602A277}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02ABDE42-9880-43B4-B6F7-8D618602A277}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02ABDE42-9880-43B4-B6F7-8D618602A277}.Release|Any CPU.Build.0 = Release|Any CPU
{BDFBE455-4C1F-4FC4-B5FC-1387B93A8687}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDFBE455-4C1F-4FC4-B5FC-1387B93A8687}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDFBE455-4C1F-4FC4-B5FC-1387B93A8687}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDFBE455-4C1F-4FC4-B5FC-1387B93A8687}.Release|Any CPU.Build.0 = Release|Any CPU
{B40F8584-5AFB-452C-AEFA-009C80CC23A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B40F8584-5AFB-452C-AEFA-009C80CC23A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B40F8584-5AFB-452C-AEFA-009C80CC23A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B40F8584-5AFB-452C-AEFA-009C80CC23A9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -75,6 +99,10 @@ Global
{E83633BA-FCF0-4A1A-B5BC-42000E24D437} = {C25EB0B0-0CAC-4CC1-8F36-F9229EFB99EC}
{0603710E-E0BA-494C-AA0F-6FB0C8A8C754} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{005F84EB-EA2E-449F-930A-7B4173DDC7EC} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{9E886812-7243-48D8-BEAF-47AADC11C054} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{02ABDE42-9880-43B4-B6F7-8D618602A277} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{BDFBE455-4C1F-4FC4-B5FC-1387B93A8687} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{B40F8584-5AFB-452C-AEFA-009C80CC23A9} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCBA19D9-F868-4C6D-8061-A2B91E06E3EC}
Expand Down
145 changes: 145 additions & 0 deletions src/Neo.CLI/CLI/ConsolePercent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright (C) 2016-2023 The Neo Project.
//
// The neo-cli is free software distributed under the MIT software
// license, see the accompanying file LICENSE in the main directory of
// the project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System;

namespace Neo.CLI
{
public class ConsolePercent : IDisposable
{
#region Variables

private readonly long _maxValue;
private long _value;
private decimal _lastFactor;
private string _lastPercent;

private readonly int _x, _y;

private bool _inputRedirected;

#endregion

#region Properties

/// <summary>
/// Value
/// </summary>
public long Value
{
get => _value;
set
{
if (value == _value) return;

_value = Math.Min(value, _maxValue);
Invalidate();
}
}

/// <summary>
/// Maximum value
/// </summary>
public long MaxValue
{
get => _maxValue;
init
{
if (value == _maxValue) return;

_maxValue = value;

if (_value > _maxValue)
_value = _maxValue;

Invalidate();
}
}

/// <summary>
/// Percent
/// </summary>
public decimal Percent
{
get
{
if (_maxValue == 0) return 0;
return (_value * 100M) / _maxValue;
}
}

#endregion

/// <summary>
/// Constructor
/// </summary>
/// <param name="value">Value</param>
/// <param name="maxValue">Maximum value</param>
public ConsolePercent(long value = 0, long maxValue = 100)
{
_inputRedirected = Console.IsInputRedirected;
_lastFactor = -1;
_x = _inputRedirected ? 0 : Console.CursorLeft;
_y = _inputRedirected ? 0 : Console.CursorTop;

MaxValue = maxValue;
Value = value;
Invalidate();
}

/// <summary>
/// Invalidate
/// </summary>
public void Invalidate()
{
var factor = Math.Round((Percent / 100M), 1);
var percent = Percent.ToString("0.0").PadLeft(5, ' ');

if (_lastFactor == factor && _lastPercent == percent)
{
return;
}

_lastFactor = factor;
_lastPercent = percent;

var fill = string.Empty.PadLeft((int)(10 * factor), '■');
var clean = string.Empty.PadLeft(10 - fill.Length, _inputRedirected ? '□' : '■');

if (_inputRedirected)
{
Console.WriteLine("[" + fill + clean + "] (" + percent + "%)");
}
else
{
Console.SetCursorPosition(_x, _y);

var prevColor = Console.ForegroundColor;

Console.ForegroundColor = ConsoleColor.White;
Console.Write("[");
Console.ForegroundColor = Percent > 50 ? ConsoleColor.Green : ConsoleColor.DarkGreen;
Console.Write(fill);
Console.ForegroundColor = ConsoleColor.White;
Console.Write(clean + "] (" + percent + "%)");

Console.ForegroundColor = prevColor;
}
}

/// <summary>
/// Free console
/// </summary>
public void Dispose()
{
Console.WriteLine("");
}
}
}
41 changes: 41 additions & 0 deletions src/Neo.CLI/CLI/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2016-2023 The Neo Project.
//
// The neo-cli is free software distributed under the MIT software
// license, see the accompanying file LICENSE in the main directory of
// the project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System;
using Neo.SmartContract.Manifest;

namespace Neo.CLI
{
internal static class Helper
{
public static bool IsYes(this string input)
{
if (input == null) return false;

input = input.ToLowerInvariant();

return input == "yes" || input == "y";
}

public static string ToBase64String(this byte[] input) => System.Convert.ToBase64String(input);

public static void IsScriptValid(this ReadOnlyMemory<byte> script, ContractAbi abi)
{
try
{
SmartContract.Helper.Check(script.ToArray(), abi);
}
catch (Exception e)
{
throw new FormatException($"Bad Script or Manifest Format: {e.Message}");
}
}
}
}
Loading