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

[Move] Part-8 Classes into Different Library - Neo.Extensions #3447

Merged
merged 38 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bf93412
Part-1 `Neo.IO` - move
cschuchardt88 Jul 2, 2024
4d08154
Part-2
cschuchardt88 Jul 2, 2024
597c9ca
Merge branch 'master' into rebuild/the-split-2
cschuchardt88 Jul 5, 2024
9881579
Added `BigInteger` to `Neo.Extensions`
cschuchardt88 Jul 5, 2024
8779151
Found more `BigInteger`
cschuchardt88 Jul 5, 2024
ed34707
Added `ByteArray` to `Neo.Extensions`
cschuchardt88 Jul 5, 2024
5b12304
Added `DateTime` Extensions to `Neo.Extensions`
cschuchardt88 Jul 7, 2024
0f6627a
Added `HashSetExtensions`, `HashSetExtensions2`, `IpAddressExtensions…
cschuchardt88 Jul 7, 2024
95f8a2d
Merge branch 'master' into rebuild/the-split-4
cschuchardt88 Jul 7, 2024
721ce58
Added `ICollection`, `Memory`, `String`, `Unsafe` extensions
cschuchardt88 Jul 7, 2024
129a32f
Adding `using`
cschuchardt88 Jul 7, 2024
397cc1f
dotnet format
cschuchardt88 Jul 7, 2024
a127386
Added more Extensions
cschuchardt88 Jul 7, 2024
9a84436
Move some methods
cschuchardt88 Jul 7, 2024
dbbf5b3
Merge branch 'master' into rebuild/the-split-2
shargon Jul 8, 2024
b64435b
Added Tests
cschuchardt88 Jul 9, 2024
583e610
Merge branch 'rebuild/the-split-2' of https://github.com/cschuchardt8…
cschuchardt88 Jul 9, 2024
6a50385
Merge branch 'rebuild/the-split-2' into rebuild/the-split-3
cschuchardt88 Jul 9, 2024
f381b89
Merge branch 'rebuild/the-split-3' into rebuild/the-split-4
cschuchardt88 Jul 9, 2024
6261f70
Merge branch 'rebuild/the-split-4' into rebuild/the-split-5
cschuchardt88 Jul 9, 2024
4a0fb7a
Merge branch 'rebuild/the-split-5' into rebuild/the-split-6
cschuchardt88 Jul 9, 2024
58f7fee
Added `tests` from `Part-2`
cschuchardt88 Jul 9, 2024
7f74300
Merge branch 'rebuild/the-split-3' into rebuild/the-split-4
cschuchardt88 Jul 9, 2024
c790166
Merge branch 'rebuild/the-split-4' into rebuild/the-split-5
cschuchardt88 Jul 9, 2024
26d0515
Merge branch 'rebuild/the-split-5' into rebuild/the-split-6
cschuchardt88 Jul 9, 2024
e644bd3
Added `tests` for `PART-4`
cschuchardt88 Jul 9, 2024
79a3578
Merge branch 'rebuild/the-split-4' into rebuild/the-split-5
cschuchardt88 Jul 9, 2024
00ce5ae
Merge branch 'rebuild/the-split-5' into rebuild/the-split-6
cschuchardt88 Jul 9, 2024
6fa0fda
Added `tests` for `PART-5`
cschuchardt88 Jul 9, 2024
708ce84
Merge branch 'rebuild/the-split-5' into rebuild/the-split-6
cschuchardt88 Jul 9, 2024
bb9992e
Merge Master
cschuchardt88 Aug 3, 2024
ff3c158
Added the `Part` 7
cschuchardt88 Aug 3, 2024
b9a6cb4
`PART-8`
cschuchardt88 Aug 4, 2024
0d9493a
Merge `Master` into `the-split-8`
cschuchardt88 Nov 29, 2024
2c36ac0
Merge `master` into `the-split-8`
cschuchardt88 Nov 29, 2024
6879e38
Fixed some stuff
cschuchardt88 Nov 29, 2024
02838b2
Merge branch 'master' into rebuild/the-split-8
shargon Dec 1, 2024
c08fd87
Merge branch 'master' into rebuild/the-split-8
shargon Dec 2, 2024
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
32 changes: 32 additions & 0 deletions src/Neo/Extensions/UInt160Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// UInt160Extensions.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 Neo.VM;

namespace Neo.Extensions
{
public static class UInt160Extensions
{
/// <summary>
/// Generates the script for calling a contract dynamically.
/// </summary>
/// <param name="scriptHash">The hash of the contract to be called.</param>
/// <param name="method">The method to be called in the contract.</param>
/// <param name="args">The arguments for calling the contract.</param>
/// <returns>The generated script.</returns>
public static byte[] MakeScript(this UInt160 scriptHash, string method, params object[] args)
{
using ScriptBuilder sb = new();
sb.EmitDynamicCall(scriptHash, method, args);
return sb.ToArray();
}
}
}
37 changes: 37 additions & 0 deletions src/Neo/Extensions/VM/EvaluationStackExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// EvaluationStackExtensions.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 Neo.Json;
using Neo.VM;
using System;

namespace Neo.Extensions
{
public static class EvaluationStackExtensions
{
/// <summary>
/// Converts the <see cref="EvaluationStack"/> to a JSON object.
/// </summary>
/// <param name="stack">The <see cref="EvaluationStack"/> to convert.</param>
/// <param name="maxSize">The maximum size in bytes of the result.</param>
/// <returns>The <see cref="EvaluationStack"/> represented by a JSON object.</returns>
public static JArray ToJson(this EvaluationStack stack, int maxSize = int.MaxValue)
{
if (maxSize <= 0) throw new ArgumentOutOfRangeException(nameof(maxSize));
maxSize -= 2/*[]*/+ Math.Max(0, (stack.Count - 1))/*,*/;
JArray result = [];
foreach (var item in stack)
result.Add(item.ToJson(null, ref maxSize));
if (maxSize < 0) throw new InvalidOperationException("Max size reached.");
return result;
}
}
}
33 changes: 1 addition & 32 deletions src/Neo/VM/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ namespace Neo.VM
/// </summary>
public static class Helper
{
/// <summary>
/// Generates the script for calling a contract dynamically.
/// </summary>
/// <param name="scriptHash">The hash of the contract to be called.</param>
/// <param name="method">The method to be called in the contract.</param>
/// <param name="args">The arguments for calling the contract.</param>
/// <returns>The generated script.</returns>
public static byte[] MakeScript(this UInt160 scriptHash, string method, params object[] args)
{
using ScriptBuilder sb = new();
sb.EmitDynamicCall(scriptHash, method, args);
return sb.ToArray();
}

/// <summary>
/// Converts the <see cref="StackItem"/> to a JSON object.
/// </summary>
Expand All @@ -54,24 +40,7 @@ public static JObject ToJson(this StackItem item, int maxSize = int.MaxValue)
return ToJson(item, null, ref maxSize);
}

/// <summary>
/// Converts the <see cref="EvaluationStack"/> to a JSON object.
/// </summary>
/// <param name="stack">The <see cref="EvaluationStack"/> to convert.</param>
/// <param name="maxSize">The maximum size in bytes of the result.</param>
/// <returns>The <see cref="EvaluationStack"/> represented by a JSON object.</returns>
public static JArray ToJson(this EvaluationStack stack, int maxSize = int.MaxValue)
{
if (maxSize <= 0) throw new ArgumentOutOfRangeException(nameof(maxSize));
maxSize -= 2/*[]*/+ Math.Max(0, (stack.Count - 1))/*,*/;
JArray result = new();
foreach (var item in stack)
result.Add(ToJson(item, null, ref maxSize));
if (maxSize < 0) throw new InvalidOperationException("Max size reached.");
return result;
}

private static JObject ToJson(StackItem item, HashSet<StackItem> context, ref int maxSize)
public static JObject ToJson(this StackItem item, HashSet<StackItem> context, ref int maxSize)
{
JObject json = new()
{
Expand Down
1 change: 1 addition & 0 deletions src/Plugins/RpcClient/Nep17API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// modifications are permitted.

using Neo.Cryptography.ECC;
using Neo.Extensions;
using Neo.Network.P2P.Payloads;
using Neo.Network.RPC.Models;
using Neo.SmartContract;
Expand Down
1 change: 1 addition & 0 deletions tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Neo.Extensions;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
Expand Down
1 change: 1 addition & 0 deletions tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Moq;
using Neo.Cryptography;
using Neo.Cryptography.ECC;
using Neo.Extensions;
using Neo.IO;
using Neo.Json;
using Neo.Network.P2P;
Expand Down
Loading