Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
riemannulus committed Aug 26, 2024
1 parent a0dcd80 commit 64acafb
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .Libplanet
Submodule .Libplanet updated 111 files
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
52 changes: 52 additions & 0 deletions Lib9c.NCActionLoader/Lib9c.NCActionLoader.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Lib9c.Policy\Lib9c.Policy.csproj" />
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\.Libplanet\src\Libplanet.Action\Libplanet.Action.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>

<ProjectReference Include="..\.Libplanet\src\Libplanet\Libplanet.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>

<ProjectReference Include="..\.Libplanet\src\Libplanet.Types\Libplanet.Types.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>

<ProjectReference Include="..\.Libplanet\src\Libplanet.Common\Libplanet.Common.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>

<ProjectReference Include="..\.Libplanet\src\Libplanet.Crypto\Libplanet.Crypto.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>

<ProjectReference Include="..\.Libplanet\src\Libplanet.Store\Libplanet.Store.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>

<PackageReference Include="Bencodex" Version="0.16.0">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions Lib9c.NCActionLoader/NineChroniclesActionLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Bencodex.Types;
using Libplanet.Action;
using Libplanet.Action.Loader;

namespace Lib9c.NCActionLoader;

public class NineChroniclesActionLoader : IActionLoader
{
private readonly IActionLoader _actionLoader = new Nekoyume.Action.Loader.NCActionLoader();

public NineChroniclesActionLoader()
{
}

public IAction LoadAction(long index, IValue value) =>
_actionLoader.LoadAction(index, value);
}
32 changes: 32 additions & 0 deletions Lib9c.NCActionLoader/NineChroniclesPolicyActionRegistry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Immutable;
using Libplanet.Action;
using Nekoyume.Action;

namespace Lib9c.NCActionLoader;

public class NineChroniclesPolicyActionRegistry : IPolicyActionsRegistry
{
private IPolicyActionsRegistry _policyActionsRegistry;

public NineChroniclesPolicyActionRegistry()
{
_policyActionsRegistry = new PolicyActionsRegistry(
beginBlockActions: ImmutableArray<IAction>.Empty,
endBlockActions: new IAction[] { new RewardGold() }.ToImmutableArray(),
beginTxActions: ImmutableArray<IAction>.Empty,
endTxActions: ImmutableArray<IAction>.Empty);
}

public ImmutableArray<IAction> BeginBlockActions =>
_policyActionsRegistry.BeginBlockActions;

public ImmutableArray<IAction> EndBlockActions =>
_policyActionsRegistry.EndBlockActions;

public ImmutableArray<IAction> BeginTxActions =>
_policyActionsRegistry.BeginTxActions;

public ImmutableArray<IAction> EndTxActions =>
_policyActionsRegistry.EndTxActions;

}
18 changes: 18 additions & 0 deletions Lib9c.sln
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.Plugin.Shared", ".Lib
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Mocks", ".Libplanet\test\Libplanet.Mocks\Libplanet.Mocks.csproj", "{8BC561CB-91EF-4290-893F-025E9E6A0CF7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Node", ".Libplanet\sdk\node\Libplanet.Node\Libplanet.Node.csproj", "{9F167168-49C8-4FE1-8A72-0E6924E5181F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Node.Extensions", ".Libplanet\sdk\node\Libplanet.Node.Extensions\Libplanet.Node.Extensions.csproj", "{E4A2B680-F4CE-4D25-8F0F-77447DAFA9AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib9c.NCActionLoader", "Lib9c.NCActionLoader\Lib9c.NCActionLoader.csproj", "{3B637F4F-7EF5-449C-8907-FE2F5863B5C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -196,6 +202,18 @@ Global
{8BC561CB-91EF-4290-893F-025E9E6A0CF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BC561CB-91EF-4290-893F-025E9E6A0CF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BC561CB-91EF-4290-893F-025E9E6A0CF7}.Release|Any CPU.Build.0 = Release|Any CPU
{9F167168-49C8-4FE1-8A72-0E6924E5181F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F167168-49C8-4FE1-8A72-0E6924E5181F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F167168-49C8-4FE1-8A72-0E6924E5181F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F167168-49C8-4FE1-8A72-0E6924E5181F}.Release|Any CPU.Build.0 = Release|Any CPU
{E4A2B680-F4CE-4D25-8F0F-77447DAFA9AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4A2B680-F4CE-4D25-8F0F-77447DAFA9AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4A2B680-F4CE-4D25-8F0F-77447DAFA9AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4A2B680-F4CE-4D25-8F0F-77447DAFA9AA}.Release|Any CPU.Build.0 = Release|Any CPU
{3B637F4F-7EF5-449C-8907-FE2F5863B5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B637F4F-7EF5-449C-8907-FE2F5863B5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B637F4F-7EF5-449C-8907-FE2F5863B5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B637F4F-7EF5-449C-8907-FE2F5863B5C5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions Lib9c/Lib9c.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<PackageReference Include="DecimalMath.DecimalEx" Version="1.0.2" />
<PackageReference Include="Jitbit.FastCache" Version="1.0.11" />
<PackageReference Include="OptimizedPriorityQueue" Version="4.2.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.38.0.46746">
Expand Down
14 changes: 7 additions & 7 deletions Lib9c/Module/LegacyModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Security.Cryptography;
using System.Text;
using Bencodex.Types;
using Jitbit.Utils;
using Lib9c;
using Libplanet.Action;
using Libplanet.Action.State;
Expand All @@ -29,9 +30,8 @@ namespace Nekoyume.Module
{
public static class LegacyModule
{
private const int SheetsCacheSize = 100;
private static readonly LruCache<string, ISheet> SheetsCache =
new LruCache<string, ISheet>(SheetsCacheSize);
private static readonly FastCache<string, ISheet> FastSheetsCache =
new FastCache<string, ISheet>();

public static IValue GetLegacyState(this IWorldState worldState, Address address) =>
worldState.GetAccountState(ReservedAddresses.LegacyAccount).GetState(address);
Expand Down Expand Up @@ -401,14 +401,14 @@ public static T GetSheet<T>(
}

var cacheKey = sheetAddr.ToHex() + ByteUtil.Hex(hash);
if (SheetsCache.TryGetValue(cacheKey, out var cached))
if (FastSheetsCache.TryGet(cacheKey, out var cached))
{
return (T)cached;
}

var sheet = new T();
sheet.Set(csv);
SheetsCache.AddOrUpdate(cacheKey, sheet);
FastSheetsCache.AddOrUpdate(cacheKey, sheet, TimeSpan.FromMinutes(1));
return sheet;
}
catch (Exception e)
Expand Down Expand Up @@ -632,7 +632,7 @@ public static bool TryGetSheet<T>(this IWorldState worldState, Address address,
}

var cacheKey = address.ToHex() + ByteUtil.Hex(hash);
if (SheetsCache.TryGetValue(cacheKey, out var cached))
if (FastSheetsCache.TryGet(cacheKey, out var cached))
{
result[sheetType] = (address, cached);
continue;
Expand All @@ -645,7 +645,7 @@ public static bool TryGetSheet<T>(this IWorldState worldState, Address address,
}

sheet.Set(csv);
SheetsCache.AddOrUpdate(cacheKey, sheet);
FastSheetsCache.AddOrUpdate(cacheKey, sheet, TimeSpan.FromMinutes(1));
result[sheetType] = (address, sheet);
}

Expand Down

0 comments on commit 64acafb

Please sign in to comment.