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 CLI NEW] Part 1 of https://github.com/neo-project/neo/pull/3103 #3369

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions SpellingExclusions.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
barc
scripthash
28 changes: 21 additions & 7 deletions neo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.IO", "src\Neo.IO\Neo.IO
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Extensions", "src\Neo.Extensions\Neo.Extensions.csproj", "{9C5213D6-3833-4570-8AE2-47E9F9017A8F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Hosting.App", "src\Neo.Hosting.App\Neo.Hosting.App.csproj", "{DF99D759-46D5-4CDB-89CB-EF56DC9728DA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Hosting.App.Tests", "tests\Neo.Hosting.App.Tests\Neo.Hosting.App.Tests.csproj", "{FB1FA9F6-B6B4-48B7-A522-1FAF55DFB228}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "plugins", "plugins", "{C2DC830A-327A-42A7-807D-295216D30DBB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Cryptography.MPTTrie.Tests", "tests\Neo.Cryptography.MPTTrie.Tests\Neo.Cryptography.MPTTrie.Tests.csproj", "{FAF5D8AC-B6B3-4CD4-879D-0E5F6211480F}"
Expand All @@ -50,8 +54,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.OracleService.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.RpcServer.Tests", "tests\Neo.Plugins.RpcServer.Tests\Neo.Plugins.RpcServer.Tests.csproj", "{2CBD2311-BA2E-4921-A000-FDDA59B74958}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.Storage.Tests", "tests\Neo.Plugins.Storage.Tests\Neo.Plugins.Storage.Tests.csproj", "{EF01E062-DBBC-47AF-AF3B-9EDEB00CFF7C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7F257712-D033-47FF-B439-9D4320D06599}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationLogs", "src\Plugins\ApplicationLogs\ApplicationLogs.csproj", "{22E2CE64-080B-4138-885F-7FA74A9159FB}"
Expand All @@ -78,6 +80,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TokensTracker", "src\Plugin
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcClient", "src\Plugins\RpcClient\RpcClient.csproj", "{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.Storage.Tests", "tests\Neo.Plugins.Storage.Tests\Neo.Plugins.Storage.Tests.csproj", "{9B6BC5EC-EC11-408C-BFBA-C7ABD732F5B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -148,6 +152,14 @@ Global
{9C5213D6-3833-4570-8AE2-47E9F9017A8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C5213D6-3833-4570-8AE2-47E9F9017A8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C5213D6-3833-4570-8AE2-47E9F9017A8F}.Release|Any CPU.Build.0 = Release|Any CPU
{DF99D759-46D5-4CDB-89CB-EF56DC9728DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF99D759-46D5-4CDB-89CB-EF56DC9728DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF99D759-46D5-4CDB-89CB-EF56DC9728DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF99D759-46D5-4CDB-89CB-EF56DC9728DA}.Release|Any CPU.Build.0 = Release|Any CPU
{FB1FA9F6-B6B4-48B7-A522-1FAF55DFB228}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB1FA9F6-B6B4-48B7-A522-1FAF55DFB228}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB1FA9F6-B6B4-48B7-A522-1FAF55DFB228}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB1FA9F6-B6B4-48B7-A522-1FAF55DFB228}.Release|Any CPU.Build.0 = Release|Any CPU
{FAF5D8AC-B6B3-4CD4-879D-0E5F6211480F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAF5D8AC-B6B3-4CD4-879D-0E5F6211480F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAF5D8AC-B6B3-4CD4-879D-0E5F6211480F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -164,10 +176,6 @@ Global
{2CBD2311-BA2E-4921-A000-FDDA59B74958}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CBD2311-BA2E-4921-A000-FDDA59B74958}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CBD2311-BA2E-4921-A000-FDDA59B74958}.Release|Any CPU.Build.0 = Release|Any CPU
{EF01E062-DBBC-47AF-AF3B-9EDEB00CFF7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF01E062-DBBC-47AF-AF3B-9EDEB00CFF7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF01E062-DBBC-47AF-AF3B-9EDEB00CFF7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF01E062-DBBC-47AF-AF3B-9EDEB00CFF7C}.Release|Any CPU.Build.0 = Release|Any CPU
{22E2CE64-080B-4138-885F-7FA74A9159FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22E2CE64-080B-4138-885F-7FA74A9159FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22E2CE64-080B-4138-885F-7FA74A9159FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -216,6 +224,10 @@ Global
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Release|Any CPU.Build.0 = Release|Any CPU
{9B6BC5EC-EC11-408C-BFBA-C7ABD732F5B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B6BC5EC-EC11-408C-BFBA-C7ABD732F5B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B6BC5EC-EC11-408C-BFBA-C7ABD732F5B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B6BC5EC-EC11-408C-BFBA-C7ABD732F5B8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -237,11 +249,12 @@ Global
{387CCF6C-9A26-43F6-A639-0A82E91E10D8} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{4CDAC1AA-45C6-4157-8D8E-199050433048} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{9C5213D6-3833-4570-8AE2-47E9F9017A8F} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{DF99D759-46D5-4CDB-89CB-EF56DC9728DA} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{FB1FA9F6-B6B4-48B7-A522-1FAF55DFB228} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{FAF5D8AC-B6B3-4CD4-879D-0E5F6211480F} = {7F257712-D033-47FF-B439-9D4320D06599}
{0E92F219-1225-4DD0-8C4A-98840985D59C} = {7F257712-D033-47FF-B439-9D4320D06599}
{5D9764FB-827D-4DDE-84E3-3C05FD8ABC89} = {7F257712-D033-47FF-B439-9D4320D06599}
{2CBD2311-BA2E-4921-A000-FDDA59B74958} = {7F257712-D033-47FF-B439-9D4320D06599}
{EF01E062-DBBC-47AF-AF3B-9EDEB00CFF7C} = {7F257712-D033-47FF-B439-9D4320D06599}
{7F257712-D033-47FF-B439-9D4320D06599} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{22E2CE64-080B-4138-885F-7FA74A9159FB} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{4C39E872-FC37-4BFD-AE4C-3E3F0546B726} = {C2DC830A-327A-42A7-807D-295216D30DBB}
Expand All @@ -255,6 +268,7 @@ Global
{FF76D8A4-356B-461A-8471-BC1B83E57BBC} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{5E4947F3-05D3-4806-B0F3-30DAC71B5986} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{9B6BC5EC-EC11-408C-BFBA-C7ABD732F5B8} = {7F257712-D033-47FF-B439-9D4320D06599}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCBA19D9-F868-4C6D-8061-A2B91E06E3EC}
Expand Down
25 changes: 25 additions & 0 deletions src/Neo.Extensions/AssemblyUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// AssemblyUtility.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository 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.Reflection;

namespace Neo.Extensions
{
public static class AssemblyUtility
{
public static int GetVersionNumber()
{
var version = Assembly.GetCallingAssembly().GetName().Version;
if (version is null) return 0;
return version.Major * 1000 + version.Minor * 100 + version.Build * 10 + version.Revision;
}
}
}
7 changes: 6 additions & 1 deletion src/Neo.Extensions/LogLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public enum LogLevel : byte
/// <summary>
/// The fatal log level.
/// </summary>
Fatal = Error + 1
Fatal = Error + 1,

/// <summary>
/// The trace log level.
/// </summary>
Trace = Fatal + 1,
}
}
44 changes: 44 additions & 0 deletions src/Neo.Hosting.App/Buffers/MemoryPoolBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// MemoryPoolBlock.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository 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 System.Buffers;
using System.Runtime.InteropServices;

namespace Neo.Hosting.App.Buffers
{
internal sealed class MemoryPoolBlock : IMemoryOwner<byte>
{
public PinnedBlockMemoryPool Pool { get; }

internal MemoryPoolBlock(
PinnedBlockMemoryPool pool,
int length)
{
Pool = pool;

var pinnedArray = GC.AllocateUninitializedArray<byte>(length, pinned: true);

Memory = MemoryMarshal.CreateFromPinnedArray(pinnedArray, 0, pinnedArray.Length);
}

#region IMemoryOwner

public Memory<byte> Memory { get; }

void IDisposable.Dispose()
{
Pool.Return(this);
}

#endregion
}
}
68 changes: 68 additions & 0 deletions src/Neo.Hosting.App/Buffers/PinnedBlockMemoryPool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// PinnedBlockMemoryPool.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository 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 System.Buffers;
using System.Collections.Concurrent;

namespace Neo.Hosting.App.Buffers
{
internal sealed class PinnedBlockMemoryPool : MemoryPool<byte>
{
private const int AnySize = -1;

private static readonly int s_blockSize = 4096;

public static int BlockSize => s_blockSize;

public override int MaxBufferSize { get; } = s_blockSize;

private readonly ConcurrentQueue<MemoryPoolBlock> _blocks = new();
private readonly object _disposedSync = new();

private bool _isDisposed;

public override IMemoryOwner<byte> Rent(int size = AnySize)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(size, s_blockSize);
ObjectDisposedException.ThrowIf(_isDisposed, this);

if (_blocks.TryDequeue(out var block))
return block;

return new MemoryPoolBlock(this, BlockSize);
}

internal void Return(MemoryPoolBlock block)
{
if (_isDisposed == false)
_blocks.Enqueue(block);
}

protected override void Dispose(bool disposing)
{
if (_isDisposed)
return;

lock (_disposedSync)
{
_isDisposed = true;

if (disposing)
{
while (_blocks.TryDequeue(out _))
{
}
}
}
}
}
}
136 changes: 136 additions & 0 deletions src/Neo.Hosting.App/Buffers/Struffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// Struffer.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository 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 System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace Neo.Hosting.App.Buffers
{
/// <summary>
/// Structure byte buffer
/// </summary>
internal sealed class Struffer : IEnumerable<byte>
{
private static readonly UTF8Encoding s_utf8NoBom = new(false, true);

private byte[] _data;

public int Position { get; set; }

public Struffer()
{
_data = [];
Position = 0;
}

public Struffer(byte[] buffer)
{
_data = buffer;
}

public Struffer(int capacity)
{
_data = GC.AllocateUninitializedArray<byte>(capacity);
Position = 0;
}

public static int SizeOf(string value) =>
s_utf8NoBom.GetByteCount(value) + sizeof(int);

public Struffer Write<T>(T value)
where T : unmanaged
{
var typeSize = Unsafe.SizeOf<T>();

if (Position + typeSize > _data.Length)
Array.Resize(ref _data, _data.Length + typeSize);

Unsafe.As<byte, T>(ref _data[Position]) = value;

Position += typeSize;
return this;
}

public Struffer Write<T>(T[] values)
where T : unmanaged
{
Write(values.Length);
foreach (var value in values)
Write(value);
return this;
}

public Struffer Write(string value)
{
var strByteCount = s_utf8NoBom.GetByteCount(value);
Write(strByteCount);

if (Position + strByteCount > _data.Length)
Array.Resize(ref _data, _data.Length + strByteCount);

Position += s_utf8NoBom.GetBytes(value, _data.AsSpan(Position));
return this;
}

public T Read<T>()
where T : unmanaged
{
var typeSize = Unsafe.SizeOf<T>();

if (Position + typeSize > _data.Length)
throw new IndexOutOfRangeException();

var value = Unsafe.As<byte, T>(ref _data[Position]);
Position += typeSize;

return value;
}

public T[] ReadArray<T>()
where T : unmanaged
{
var length = Read<int>();
var values = new T[length];
for (var i = 0; i < length; i++)
values[i] = Read<T>();
return values;
}

public string ReadString()
{
var strByteCount = Read<int>();

if (Position + strByteCount > _data.Length)
throw new IndexOutOfRangeException();

var value = s_utf8NoBom.GetString(_data, Position, strByteCount);
Position += strByteCount;

return value;
}

#region IEnumerable<byte>

public IEnumerator<byte> GetEnumerator()
{
foreach (var b in _data)
yield return b;
}

IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();

#endregion
}
}
Loading
Loading