Skip to content

Commit

Permalink
Merge branch 'master' into add/plugins/rest-server
Browse files Browse the repository at this point in the history
  • Loading branch information
cschuchardt88 authored Dec 4, 2024
2 parents 2ef32eb + 79554f2 commit 6949fc3
Show file tree
Hide file tree
Showing 43 changed files with 575 additions and 443 deletions.
8 changes: 8 additions & 0 deletions src/Neo.Extensions/ByteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ public static int XxHash3_32(this byte[] value, long seed = DefaultXxHash3Seed)
/// </summary>
/// <param name="value">The byte array to convert.</param>
/// <returns>The converted hex <see cref="string"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToHexString(this byte[] value)
{
#if NET9_0_OR_GREATER
return Convert.ToHexStringLower(value);
#else
if (value is null)
throw new ArgumentNullException(nameof(value));

return string.Create(value.Length * 2, value, (span, bytes) =>
{
for (var i = 0; i < bytes.Length; i++)
Expand All @@ -74,12 +78,16 @@ public static string ToHexString(this byte[] value)
/// <param name="value">The byte array to convert.</param>
/// <param name="reverse">Indicates whether it should be converted in the reversed byte order.</param>
/// <returns>The converted hex <see cref="string"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/> is null.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToHexString(this byte[] value, bool reverse = false)
{
if (!reverse)
return ToHexString(value);

if (value is null)
throw new ArgumentNullException(nameof(value));

return string.Create(value.Length * 2, value, (span, bytes) =>
{
for (var i = 0; i < bytes.Length; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.GUI/GUI/ElectionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// modifications are permitted.

using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.Extensions;
using Neo.SmartContract.Native;
using Neo.VM;
using System;
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.GUI/GUI/VotingDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// modifications are permitted.

using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.Extensions;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
Expand Down
1 change: 1 addition & 0 deletions src/Neo/Extensions/Collections/ICollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.Extensions;
using Neo.IO;
using System.Collections.Generic;
using System.IO;
Expand Down
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;
}
}
}
Loading

0 comments on commit 6949fc3

Please sign in to comment.