Skip to content

Commit

Permalink
Neo Node Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
lock9 committed Nov 23, 2023
1 parent 2e7e70e commit 0f619e0
Show file tree
Hide file tree
Showing 190 changed files with 33,306 additions and 0 deletions.
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}");
}
}
}
}
45 changes: 45 additions & 0 deletions src/Neo.CLI/CLI/MainService.Blockchain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 Neo.ConsoleService;
using Neo.SmartContract.Native;
using System;

namespace Neo.CLI
{
partial class MainService
{
/// <summary>
/// Process "export blocks" command
/// </summary>
/// <param name="start">Start</param>
/// <param name="count">Number of blocks</param>
/// <param name="path">Path</param>
[ConsoleCommand("export blocks", Category = "Blockchain Commands")]
private void OnExportBlocksStartCountCommand(uint start, uint count = uint.MaxValue, string path = null)
{
uint height = NativeContract.Ledger.CurrentIndex(NeoSystem.StoreView);
if (height < start)
{
ConsoleHelper.Error("invalid start height.");
return;
}

count = Math.Min(count, height - start + 1);

if (string.IsNullOrEmpty(path))
{
path = $"chain.{start}.acc";
}

WriteBlocks(start, count, path, true);
}
}
}
Loading

0 comments on commit 0f619e0

Please sign in to comment.