Skip to content
Draft
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
1 change: 0 additions & 1 deletion Docs/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"src/Libplanet.Action/Libplanet.Action.csproj",
"src/Libplanet.Common/Libplanet.Common.csproj",
"src/Libplanet.Crypto/Libplanet.Crypto.csproj",
"src/Libplanet.Crypto.Secp256k1/Libplanet.Crypto.Secp256k1.csproj",
"tools/Libplanet.Explorer.Cocona/Libplanet.Explorer.Cocona.csproj",
"tools/Libplanet.Extensions.Cocona/Libplanet.Extensions.Cocona.csproj",
"test/Libplanet.Mocks/Libplanet.Mocks.csproj",
Expand Down
42 changes: 0 additions & 42 deletions Libplanet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Net", "src\Libpla
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Net.Tests", "test\Libplanet.Net.Tests\Libplanet.Net.Tests.csproj", "{6D7A63C9-16AB-4B7E-B9C0-0956E1E02610}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Crypto.Secp256k1", "src\Libplanet.Crypto.Secp256k1\Libplanet.Crypto.Secp256k1.csproj", "{9F88C871-CB37-4A88-BACF-540AC253C202}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Crypto.Secp256k1.Tests", "test\Libplanet.Crypto.Secp256k1.Tests\Libplanet.Crypto.Secp256k1.Tests.csproj", "{B1A38DDE-5534-4625-A3F2-A585BA7A1198}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Explorer.Cocona", "tools\Libplanet.Explorer.Cocona\Libplanet.Explorer.Cocona.csproj", "{8698E0C2-1A82-43E6-8A26-3D9A825CF574}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Explorer.Cocona.Tests", "test\Libplanet.Explorer.Cocona.Tests\Libplanet.Explorer.Cocona.Tests.csproj", "{F782BC86-9CE6-4F69-8F77-710A399CB54F}"
Expand Down Expand Up @@ -391,42 +387,6 @@ Global
{6D7A63C9-16AB-4B7E-B9C0-0956E1E02610}.Release|x64.Build.0 = Release|Any CPU
{6D7A63C9-16AB-4B7E-B9C0-0956E1E02610}.Release|x86.ActiveCfg = Release|Any CPU
{6D7A63C9-16AB-4B7E-B9C0-0956E1E02610}.Release|x86.Build.0 = Release|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Debug|x64.ActiveCfg = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Debug|x64.Build.0 = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Debug|x86.ActiveCfg = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Debug|x86.Build.0 = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.ReleaseMono|Any CPU.ActiveCfg = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.ReleaseMono|Any CPU.Build.0 = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.ReleaseMono|x64.ActiveCfg = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.ReleaseMono|x64.Build.0 = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.ReleaseMono|x86.ActiveCfg = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.ReleaseMono|x86.Build.0 = Debug|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Release|Any CPU.Build.0 = Release|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Release|x64.ActiveCfg = Release|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Release|x64.Build.0 = Release|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Release|x86.ActiveCfg = Release|Any CPU
{9F88C871-CB37-4A88-BACF-540AC253C202}.Release|x86.Build.0 = Release|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Debug|x64.ActiveCfg = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Debug|x64.Build.0 = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Debug|x86.ActiveCfg = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Debug|x86.Build.0 = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.ReleaseMono|Any CPU.ActiveCfg = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.ReleaseMono|Any CPU.Build.0 = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.ReleaseMono|x64.ActiveCfg = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.ReleaseMono|x64.Build.0 = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.ReleaseMono|x86.ActiveCfg = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.ReleaseMono|x86.Build.0 = Debug|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Release|Any CPU.Build.0 = Release|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Release|x64.ActiveCfg = Release|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Release|x64.Build.0 = Release|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Release|x86.ActiveCfg = Release|Any CPU
{B1A38DDE-5534-4625-A3F2-A585BA7A1198}.Release|x86.Build.0 = Release|Any CPU
{8698E0C2-1A82-43E6-8A26-3D9A825CF574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8698E0C2-1A82-43E6-8A26-3D9A825CF574}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8698E0C2-1A82-43E6-8A26-3D9A825CF574}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -719,8 +679,6 @@ Global
{A43E44E5-F9C1-44BD-A593-419EC113117B} = {B9C00FAF-36CF-463A-83FA-43E6B974AE2E}
{2E17A091-DC29-41FB-ABC8-767BD75FFB07} = {AC908E33-B856-4E23-9F81-B7F7C97A07F9}
{6D7A63C9-16AB-4B7E-B9C0-0956E1E02610} = {B9C00FAF-36CF-463A-83FA-43E6B974AE2E}
{9F88C871-CB37-4A88-BACF-540AC253C202} = {AC908E33-B856-4E23-9F81-B7F7C97A07F9}
{B1A38DDE-5534-4625-A3F2-A585BA7A1198} = {B9C00FAF-36CF-463A-83FA-43E6B974AE2E}
{8698E0C2-1A82-43E6-8A26-3D9A825CF574} = {88E7FAF4-CEEC-48B6-9114-71CFE3FC0F50}
{F782BC86-9CE6-4F69-8F77-710A399CB54F} = {B9C00FAF-36CF-463A-83FA-43E6B974AE2E}
{763BAD3E-3244-4E8F-8182-2BF35774262A} = {AC908E33-B856-4E23-9F81-B7F7C97A07F9}
Expand Down
4 changes: 0 additions & 4 deletions changes/v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,10 @@ below.

The default SDK version for the project has been bumped up to .NET 6.0.
The list of supported SDKs is as follows
- netstandard2.0
- netstandard2.1
- netcoreapp3.1
- net6.0"

> Support for `netstandard2.0` is coming to an end soon, please note that
projects using `netstandard2.0` will be deprecated.

The `VersionPrefix` property has been moved from the
*src/Libplanet/Libplanet.csproj* file to the `Directory.Build.props` file.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

<ItemGroup>
<ProjectReference Include="..\..\..\tools\Libplanet.Explorer.Executable\Libplanet.Explorer.Executable.csproj" />
<ProjectReference Include="..\..\..\src\Libplanet.Crypto.Secp256k1\Libplanet.Crypto.Secp256k1.csproj" />
<ProjectReference Include="..\Libplanet.Node.Extensions\Libplanet.Node.Extensions.csproj" />
<ProjectReference Include="..\Libplanet.Node\Libplanet.Node.csproj" />
</ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions sdk/node/Libplanet.Node/Actions/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@ internal static class PluginLoader
{
public static IActionLoader LoadActionLoader(string modulePath, string typeName)
{
if (Type.GetType(typeName) is { } type)
{
if (Activator.CreateInstance(type) is not IActionLoader obj)
{
throw new InvalidOperationException();
}

return obj;
}

var assembly = LoadAssembly(modulePath);
return Create<IActionLoader>(assembly, typeName);
}

public static IPolicyActionsRegistry LoadPolicyActionRegistry(
string relativePath, string typeName)
{
if (Type.GetType(typeName) is { } type)
{
if (Activator.CreateInstance(type) is not IPolicyActionsRegistry obj)
{
throw new InvalidOperationException();
}

return obj;
}

var assembly = LoadAssembly(relativePath);
return Create<IPolicyActionsRegistry>(assembly, typeName);
}
Expand Down
6 changes: 4 additions & 2 deletions sdk/node/Libplanet.Node/Services/ActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ private static IActionLoader GetActionLoader(ActionOptions options)
{
if (options.ActionLoaderType != string.Empty)
{
var modulePath = options.ModulePath;
var modulePath = options.ModulePath != string.Empty
? Path.GetFullPath(options.ModulePath) : string.Empty;
var actionLoaderType = options.ActionLoaderType;
return PluginLoader.LoadActionLoader(modulePath, actionLoaderType);
}
Expand All @@ -30,7 +31,8 @@ private static IPolicyActionsRegistry GetPolicyActionsRegistry(ActionOptions opt
{
if (options.PolicyActionRegistryType != string.Empty)
{
var modulePath = options.ModulePath;
var modulePath = options.ModulePath != string.Empty
? Path.GetFullPath(options.ModulePath) : string.Empty;
var policyActionRegistryType = options.PolicyActionRegistryType;
return PluginLoader.LoadPolicyActionRegistry(modulePath, policyActionRegistryType);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<TargetFrameworks Condition="'$(_IsPacking)'=='true'">$(TargetFrameworks);netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(_IsPacking)'=='true'">$(TargetFrameworks);netstandard2.1</TargetFrameworks>
<LangVersion>9</LangVersion>
<IsPackable>true</IsPackable>
<IsTestProject>false</IsTestProject>
Expand Down
25 changes: 25 additions & 0 deletions src/Libplanet.Common/ByteUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using Bencodex.Json;
using Bencodex.Types;

namespace Libplanet.Common
{
Expand All @@ -23,6 +28,16 @@ public static class ByteUtil
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
};

private static readonly BencodexJsonConverter BencodexJsonConverter = new ();
private static readonly JsonSerializerOptions SerializerOptions = new ()
{
WriteIndented = true,
Converters =
{
BencodexJsonConverter,
},
};

/// <summary>
/// Converts a hexadecimal string to a mutable <see cref="byte"/> array.
/// </summary>
Expand Down Expand Up @@ -232,5 +247,15 @@ public static bool Satisfies(IReadOnlyList<byte> hashDigest, long difficulty)
var result = new BigInteger(digestArray);
return result < target;
}

public static byte[] CreateMessage(IValue value)
{
using var ms = new MemoryStream();
using var writer = new Utf8JsonWriter(ms, new JsonWriterOptions { Indented = true });
BencodexJsonConverter.Write(writer, value, SerializerOptions);
ms.Position = 0;
using var sr = new StreamReader(ms);
return Encoding.UTF8.GetBytes(sr.ReadToEnd());
}
}
}
2 changes: 1 addition & 1 deletion src/Libplanet.Common/FixedSizedQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public FixedSizedQueue(int size)
while (Count > Size)
{
// Ensure we don't exceed the maximum size.
TryDequeue(out T _);
TryDequeue(out T? _);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Libplanet.Common/Libplanet.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PackageReference Include="System.Collections.Immutable" Version="1.*" />
<PackageReference Include="System.Text.Json" Version="6.0.*" />
<PackageReference Include="Bencodex" Version="0.16.0" />
<PackageReference Include="Bencodex.Json" Version="0.16.0" />
</ItemGroup>

<ItemGroup Condition="'$(SkipSonar)' != 'true'">
Expand Down
21 changes: 0 additions & 21 deletions src/Libplanet.Crypto.Secp256k1/Libplanet.Crypto.Secp256k1.csproj

This file was deleted.

69 changes: 0 additions & 69 deletions src/Libplanet.Crypto.Secp256k1/Secp256k1CryptoBackend.cs

This file was deleted.

39 changes: 17 additions & 22 deletions src/Libplanet.Crypto/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Bencodex;
using Bencodex.Types;
using Libplanet.Common;
using Org.BouncyCastle.Crypto.Digests;

namespace Libplanet.Crypto
{
Expand Down Expand Up @@ -259,35 +257,32 @@ public int CompareTo(object? obj) => obj is Address other

private static string ToChecksumAddress(string hex)
{
byte[] bytes = Encoding.ASCII.GetBytes(hex);
byte[] hash = CalculateHash(bytes);
string hashHex = ByteUtil.Hex(hash);
string address = string.Empty;

for (var i = 0; i < hex.Length; i++)
var value = new Nethereum.Util.AddressUtil().ConvertToChecksumAddress(hex);
if (value.StartsWith("0x"))
{
char c = hex[i];
address += (hashHex[i] >= '8') ? char.ToUpper(c, CultureInfo.InvariantCulture) : c;
return value.Substring(2);
}

return address;
return value;
}

private static byte[] CalculateHash(byte[] value)
private static ImmutableArray<byte> DeriveAddress(PublicKey key)
{
var digest = new KeccakDigest(256);
var output = new byte[digest.GetDigestSize()];
digest.BlockUpdate(value, 0, value.Length);
digest.DoFinal(output, 0);
return output;
var initaddr = new Nethereum.Util.Sha3Keccack().CalculateHash(
GetPubKeyNoPrefix(key, false));
var addr = new byte[initaddr.Length - 12];
Array.Copy(initaddr, 12, addr, 0, initaddr.Length - 12);
var address = ToChecksumAddress(
Nethereum.Hex.HexConvertors.Extensions.HexByteConvertorExtensions.ToHex(addr));
return ByteUtil.ParseHexToImmutable(address);
}

private static ImmutableArray<byte> DeriveAddress(PublicKey key)
private static byte[] GetPubKeyNoPrefix(PublicKey publicKey, bool compressed = false)
{
byte[] hashPayload = key.Format(false).Skip(1).ToArray();
var output = CalculateHash(hashPayload);

return output.Skip(output.Length - Size).ToImmutableArray();
var pubKey = publicKey.Format(compressed);
var arr = new byte[pubKey.Length - 1];
Array.Copy(pubKey, 1, arr, 0, arr.Length);
return arr;
}

private static ImmutableArray<byte> DeriveAddress(string hex)
Expand Down
Loading
Loading