-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Showing
190 changed files
with
33,306 additions
and
0 deletions.
There are no files selected for viewing
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
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,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(""); | ||
} | ||
} | ||
} |
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,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}"); | ||
} | ||
} | ||
} | ||
} |
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,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); | ||
} | ||
} | ||
} |
Oops, something went wrong.