-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
Release/0.4.0
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Lib9c.StateService.Shared; | ||
|
||
public class RemoteEvaluationRequest | ||
{ | ||
public byte[] PreEvaluationBlock { get; set; } | ||
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / build-for-unity
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / nuget
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / build-and-test (Release)
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / release
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / release
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / build-for-unity
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / build-for-unity
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / build-and-test (Release)
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs GitHub Actions / build-and-test (Release)
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Lib9c.StateService.Shared; | ||
|
||
public class RemoteEvaluationResponse | ||
{ | ||
public byte[][] Evaluations { get; set; } | ||
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs GitHub Actions / build-for-unity
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs GitHub Actions / nuget
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs GitHub Actions / build-and-test (Release)
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs GitHub Actions / release
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs GitHub Actions / release
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs GitHub Actions / build-for-unity
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs GitHub Actions / build-for-unity
Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs GitHub Actions / build-and-test (Release)
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Bencodex; | ||
using Bencodex.Types; | ||
using Lib9c.StateService.Shared; | ||
using Libplanet.Action; | ||
using Libplanet.Action.State; | ||
using Libplanet.Extensions.ActionEvaluatorCommonComponents; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Nekoyume.Action; | ||
using Nekoyume.Action.Loader; | ||
|
||
namespace Lib9c.StateService.Controllers; | ||
|
||
[ApiController] | ||
[Route("/evaluation")] | ||
public class RemoteEvaluationController : ControllerBase | ||
{ | ||
private readonly IBlockChainStates _blockChainStates; | ||
private readonly ILogger<RemoteEvaluationController> _logger; | ||
private readonly Codec _codec; | ||
|
||
public RemoteEvaluationController( | ||
IBlockChainStates blockChainStates, | ||
ILogger<RemoteEvaluationController> logger, | ||
Codec codec) | ||
{ | ||
_blockChainStates = blockChainStates; | ||
_logger = logger; | ||
_codec = codec; | ||
} | ||
|
||
[HttpPost] | ||
public ActionResult<RemoteEvaluationResponse> GetEvaluation([FromBody] RemoteEvaluationRequest request) | ||
{ | ||
var decoded = _codec.Decode(request.PreEvaluationBlock); | ||
if (decoded is not Dictionary dictionary) | ||
{ | ||
return StatusCode(StatusCodes.Status400BadRequest); | ||
} | ||
|
||
var preEvaluationBlock = PreEvaluationBlockMarshaller.Unmarshal(dictionary); | ||
var actionEvaluator = | ||
new ActionEvaluator( | ||
context => new RewardGold(), | ||
_blockChainStates, | ||
new NCActionLoader()); | ||
return Ok(new RemoteEvaluationResponse | ||
{ | ||
Evaluations = actionEvaluator.Evaluate(preEvaluationBlock).Select(ActionEvaluationMarshaller.Serialize) | ||
.ToArray(), | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\.Libplanet.Extensions.RemoteBlockChainStates\Libplanet.Extensions.RemoteBlockChainStates.csproj" /> | ||
<ProjectReference Include="..\.Libplanet.Extensions.ActionEvaluatorCommonComponents\Libplanet.Extensions.ActionEvaluatorCommonComponents.csproj" /> | ||
<ProjectReference Include="..\.Lib9c.StateService.Shared\Lib9c.StateService.Shared.csproj" /> | ||
<ProjectReference Include="..\Lib9c\Lib9c.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Bencodex; | ||
using Libplanet.Action.State; | ||
using Libplanet.Extensions.RemoteBlockChainStates; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Configuration.AddEnvironmentVariables(); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
builder.Services.AddSingleton<Codec>(); | ||
|
||
builder.Services.AddSingleton<IBlockChainStates, RemoteBlockChainStates>(_ => | ||
{ | ||
const string DefaultEndpoint = "http://localhost:31280/graphql/explorer"; | ||
var endpoint = builder.Configuration.GetValue<string>("RemoteBlockChainStatesEndpoint") ?? DefaultEndpoint; | ||
return new RemoteBlockChainStates(new Uri(endpoint)); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:25712", | ||
"sslPort": 44330 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5157", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7140;http://localhost:5157", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"type": "object", | ||
"description": "appsettings.json to configure application.", | ||
"properties": { | ||
"RemoteBlockChainStatesEndpoint": { | ||
"type": "string", | ||
"description": "The headless' Libplanet.Explorer GraphQL endpoint. (e.g., http://localhost/graphql/explorer)" | ||
} | ||
}, | ||
"required": ["RemoteBlockChainStatesEndpoint"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |