diff --git a/NineChronicles.Headless.Tests/GraphQLTestUtils.cs b/NineChronicles.Headless.Tests/GraphQLTestUtils.cs index 7bf0cf4b2..636bd6987 100644 --- a/NineChronicles.Headless.Tests/GraphQLTestUtils.cs +++ b/NineChronicles.Headless.Tests/GraphQLTestUtils.cs @@ -4,6 +4,7 @@ using GraphQL; using GraphQL.Types; using Microsoft.Extensions.DependencyInjection; +using NCAction = Libplanet.Action.PolymorphicAction; namespace NineChronicles.Headless.Tests { @@ -23,6 +24,8 @@ public static Task ExecuteQueryAsync( services.AddSingleton(standaloneContext); } + services.AddLibplanetExplorer(); + var serviceProvider = services.BuildServiceProvider(); return ExecuteQueryAsync( serviceProvider, diff --git a/NineChronicles.Headless.Tests/GraphTypes/GraphQLTestBase.cs b/NineChronicles.Headless.Tests/GraphTypes/GraphQLTestBase.cs index 9cbfefd5b..be925801f 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/GraphQLTestBase.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/GraphQLTestBase.cs @@ -27,6 +27,7 @@ using Microsoft.Extensions.DependencyInjection; using Nekoyume.Model.State; using Nekoyume.TableData; +using NCAction = Libplanet.Action.PolymorphicAction; namespace NineChronicles.Headless.Tests.GraphTypes { @@ -96,6 +97,7 @@ public GraphQLTestBase(ITestOutputHelper output) services.AddSingleton(StandaloneContextFx); services.AddSingleton(configuration); services.AddGraphTypes(); + services.AddLibplanetExplorer(); services.AddSingleton(); ServiceProvider serviceProvider = services.BuildServiceProvider(); Schema = new StandaloneSchema(serviceProvider); diff --git a/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs b/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs index 5b3ecd5e6..24b8c8924 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs @@ -536,7 +536,7 @@ public async Task GetTx() timestamp updatedAddresses actions {{ - plainValue + inspection }} }} }}"; @@ -576,7 +576,7 @@ public async Task GetTx() var plainValue = tx["actions"] .As>() .First() - .As>()["plainValue"]; + .As>()["inspection"]; Assert.Equal(transaction.Actions.First().PlainValue.Inspection, plainValue); } diff --git a/NineChronicles.Headless/BlockChainContext.cs b/NineChronicles.Headless/BlockChainContext.cs new file mode 100644 index 000000000..5a3cedaf0 --- /dev/null +++ b/NineChronicles.Headless/BlockChainContext.cs @@ -0,0 +1,23 @@ +using Libplanet.Action; +using Libplanet.Blockchain; +using Libplanet.Explorer.Interfaces; +using Libplanet.Store; +using Nekoyume.Action; +using NCAction = Libplanet.Action.PolymorphicAction; + +namespace NineChronicles.Headless +{ + public class BlockChainContext : IBlockChainContext + { + private readonly StandaloneContext _standaloneContext; + + public BlockChainContext(StandaloneContext standaloneContext) + { + _standaloneContext = standaloneContext; + } + + public bool Preloaded => _standaloneContext.NodeStatus.PreloadEnded; + public BlockChain> BlockChain => _standaloneContext.BlockChain; + public IStore Store => _standaloneContext.Store; + } +} diff --git a/NineChronicles.Headless/GraphQLBuilderExtensions.cs b/NineChronicles.Headless/GraphQLBuilderExtensions.cs new file mode 100644 index 000000000..07dce444c --- /dev/null +++ b/NineChronicles.Headless/GraphQLBuilderExtensions.cs @@ -0,0 +1,16 @@ +using GraphQL.Server; +using Libplanet.Action; + +namespace NineChronicles.Headless +{ + public static class GraphQLBuilderExtensions + { + public static IGraphQLBuilder AddLibplanetExplorer(this IGraphQLBuilder builder) + where T : IAction, new() + { + builder.Services.AddLibplanetExplorer(); + + return builder; + } + } +} diff --git a/NineChronicles.Headless/GraphQLService.cs b/NineChronicles.Headless/GraphQLService.cs index 2d19c0f9e..832388a1f 100644 --- a/NineChronicles.Headless/GraphQLService.cs +++ b/NineChronicles.Headless/GraphQLService.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using GraphQL.Server; using Microsoft.AspNetCore.Builder; @@ -9,6 +10,7 @@ using NineChronicles.Headless.Middleware; using NineChronicles.Headless.Properties; using Serilog; +using NCAction = Libplanet.Action.PolymorphicAction; namespace NineChronicles.Headless { @@ -91,15 +93,16 @@ public void ConfigureServices(IServiceCollection services) options.EnableMetrics = true; options.UnhandledExceptionDelegate = context => { - Log.Error( - context.Exception, - context.ErrorMessage); + Console.Error.WriteLine(context.Exception.ToString()); + Console.Error.WriteLine(context.ErrorMessage); }; }) .AddSystemTextJson() .AddWebSockets() .AddDataLoader() .AddGraphTypes(typeof(StandaloneSchema)) + .AddLibplanetExplorer() + .AddUserContextBuilder() .AddGraphQLAuthorization( options => options.AddPolicy( LocalPolicyKey, diff --git a/NineChronicles.Headless/GraphQLServiceExtensions.cs b/NineChronicles.Headless/GraphQLServiceExtensions.cs index 7b67e35d0..326135118 100644 --- a/NineChronicles.Headless/GraphQLServiceExtensions.cs +++ b/NineChronicles.Headless/GraphQLServiceExtensions.cs @@ -2,8 +2,13 @@ using System.Linq; using System.Reflection; using GraphQL.Types; +using Libplanet.Action; +using Libplanet.Explorer.GraphTypes; +using Libplanet.Explorer.Interfaces; +using Libplanet.Explorer.Queries; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using NCAction = Libplanet.Action.PolymorphicAction; namespace NineChronicles.Headless { @@ -24,5 +29,37 @@ public static IServiceCollection AddGraphTypes(this IServiceCollection services) return services; } + + public static IServiceCollection AddLibplanetScalarTypes(this IServiceCollection services) + { + services.TryAddSingleton(); + services.TryAddSingleton(); + + return services; + } + + public static IServiceCollection AddBlockChainContext(this IServiceCollection services) + { + services.TryAddSingleton, BlockChainContext>(); + + return services; + } + + public static IServiceCollection AddLibplanetExplorer(this IServiceCollection services) + where T : IAction, new() + { + services.AddLibplanetScalarTypes(); + services.AddBlockChainContext(); + + services.TryAddSingleton>(); + services.TryAddSingleton>(); + services.TryAddSingleton>(); + services.TryAddSingleton>(); + services.TryAddSingleton>(); + services.TryAddSingleton>(); + services.TryAddSingleton>(); + + return services; + } } } diff --git a/NineChronicles.Headless/GraphTypes/ActionMutation.cs b/NineChronicles.Headless/GraphTypes/ActionMutation.cs index 8ac09644f..853887260 100644 --- a/NineChronicles.Headless/GraphTypes/ActionMutation.cs +++ b/NineChronicles.Headless/GraphTypes/ActionMutation.cs @@ -11,6 +11,7 @@ using Serilog; using System; using System.Collections.Generic; +using Libplanet.Explorer.GraphTypes; using Libplanet.Tx; using NineChroniclesActionType = Libplanet.Action.PolymorphicAction; diff --git a/NineChronicles.Headless/GraphTypes/ActionType.cs b/NineChronicles.Headless/GraphTypes/ActionType.cs deleted file mode 100644 index dc2fef868..000000000 --- a/NineChronicles.Headless/GraphTypes/ActionType.cs +++ /dev/null @@ -1,17 +0,0 @@ -using GraphQL.Types; -using Libplanet.Action; - -namespace NineChronicles.Headless.GraphTypes -{ - public class ActionType : ObjectGraphType where T : IAction, new() - { - public ActionType() - { - Field>( - nameof(IAction.PlainValue), - resolve: context => context.Source.PlainValue.Inspection - ); - Name = "Action"; - } - } -} diff --git a/NineChronicles.Headless/GraphTypes/AddressType.cs b/NineChronicles.Headless/GraphTypes/AddressType.cs deleted file mode 100644 index 523615285..000000000 --- a/NineChronicles.Headless/GraphTypes/AddressType.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using GraphQL.Language.AST; -using GraphQL.Types; -using Libplanet; - -namespace NineChronicles.Headless.GraphTypes -{ - // Copied from planetarium/libplanet-explorer:59a2d3045e99100fb33d79cc7d0ee6fdc09a1eb4 - // https://git.io/JfXZA - public class AddressType : StringGraphType - { - public AddressType() - { - Name = "Address"; - } - - public override object Serialize(object value) - { - if (value is Address addr) - { - return addr.ToString(); - } - - return value; - } - - public override object ParseValue(object value) - { - switch (value) - { - case null: - return null; - case string hex: - if (hex.Substring(0, 2).ToLower().Equals("0x")) - { - hex = hex.Substring(2); - } - - return new Address(hex); - default: - throw new ArgumentException( - $"Expected a hexadecimal string but {value}", nameof(value)); - } - } - - public override object ParseLiteral(IValue value) - { - if (value is StringValue) - { - return ParseValue(value.Value); - } - - return null; - } - } -} diff --git a/NineChronicles.Headless/GraphTypes/AppProtocolVersionType.cs b/NineChronicles.Headless/GraphTypes/AppProtocolVersionType.cs index 6967e75ef..1346ea8a1 100644 --- a/NineChronicles.Headless/GraphTypes/AppProtocolVersionType.cs +++ b/NineChronicles.Headless/GraphTypes/AppProtocolVersionType.cs @@ -1,6 +1,7 @@ using Bencodex; using Libplanet.Net; using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; namespace NineChronicles.Headless.GraphTypes { diff --git a/NineChronicles.Headless/GraphTypes/BlockHeaderType.cs b/NineChronicles.Headless/GraphTypes/BlockHeaderType.cs index 1d5b2a89c..bcb81c907 100644 --- a/NineChronicles.Headless/GraphTypes/BlockHeaderType.cs +++ b/NineChronicles.Headless/GraphTypes/BlockHeaderType.cs @@ -3,6 +3,7 @@ using Libplanet; using Libplanet.Action; using Libplanet.Blocks; +using Libplanet.Explorer.GraphTypes; namespace NineChronicles.Headless.GraphTypes { diff --git a/NineChronicles.Headless/GraphTypes/ByteStringType.cs b/NineChronicles.Headless/GraphTypes/ByteStringType.cs deleted file mode 100644 index 3cc32afe5..000000000 --- a/NineChronicles.Headless/GraphTypes/ByteStringType.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using GraphQL.Language.AST; -using GraphQL.Types; -using Libplanet; -using Serilog; - -namespace NineChronicles.Headless.GraphTypes -{ - // Copied from planetarium/libplanet-explorer:59a2d3045e99100fb33d79cc7d0ee6fdc09a1eb4 - // https://git.io/JfXOt - public class ByteStringType : ScalarGraphType - { - public ByteStringType() - { - Name = "ByteString"; - } - - public override object Serialize(object value) - { - // FIXME: ScalarGraphType에 동작 원리에 대한 이해가 필요합니다. - // https://graphql-dotnet.github.io/docs/getting-started/custom-scalars/ - return value switch - { - byte[] b => ByteUtil.Hex(b), - string s => s, - _ => null - }; - } - - public override object ParseValue(object value) - { - switch (value) - { - case null: - return null; - case string hex: - return ByteUtil.ParseHex(hex); - default: - throw new ArgumentException("Expected a hexadecimal string.", nameof(value)); - } - } - - public override object ParseLiteral(IValue value) - { - if (value is StringValue) - { - return ParseValue(value.Value); - } - - return null; - } - } -} diff --git a/NineChronicles.Headless/GraphTypes/KeyStoreMutation.cs b/NineChronicles.Headless/GraphTypes/KeyStoreMutation.cs index fcdcb4313..30f870f79 100644 --- a/NineChronicles.Headless/GraphTypes/KeyStoreMutation.cs +++ b/NineChronicles.Headless/GraphTypes/KeyStoreMutation.cs @@ -4,6 +4,7 @@ using GraphQL.Types; using Libplanet; using Libplanet.Crypto; +using Libplanet.Explorer.GraphTypes; using Libplanet.KeyStore; namespace NineChronicles.Headless.GraphTypes diff --git a/NineChronicles.Headless/GraphTypes/KeyStoreType.cs b/NineChronicles.Headless/GraphTypes/KeyStoreType.cs index 7b9d5366a..32eb762a5 100644 --- a/NineChronicles.Headless/GraphTypes/KeyStoreType.cs +++ b/NineChronicles.Headless/GraphTypes/KeyStoreType.cs @@ -4,6 +4,7 @@ using GraphQL.Types; using Libplanet; using Libplanet.Crypto; +using Libplanet.Explorer.GraphTypes; using Libplanet.KeyStore; using Org.BouncyCastle.Security; diff --git a/NineChronicles.Headless/GraphTypes/NodeStatus.cs b/NineChronicles.Headless/GraphTypes/NodeStatus.cs index 30d2ad65d..37facbcd9 100644 --- a/NineChronicles.Headless/GraphTypes/NodeStatus.cs +++ b/NineChronicles.Headless/GraphTypes/NodeStatus.cs @@ -8,6 +8,7 @@ using Libplanet.Action; using Libplanet.Blockchain; using Libplanet.Blocks; +using Libplanet.Explorer.GraphTypes; using Libplanet.Store; using Libplanet.Tx; using NCAction = Libplanet.Action.PolymorphicAction; diff --git a/NineChronicles.Headless/GraphTypes/PrivateKeyType.cs b/NineChronicles.Headless/GraphTypes/PrivateKeyType.cs index 9c1ac6ee3..e12ee6b1f 100644 --- a/NineChronicles.Headless/GraphTypes/PrivateKeyType.cs +++ b/NineChronicles.Headless/GraphTypes/PrivateKeyType.cs @@ -1,6 +1,7 @@ using GraphQL.Types; using Libplanet; using Libplanet.Crypto; +using Libplanet.Explorer.GraphTypes; namespace NineChronicles.Headless.GraphTypes { diff --git a/NineChronicles.Headless/GraphTypes/ProtectedPrivateKeyType.cs b/NineChronicles.Headless/GraphTypes/ProtectedPrivateKeyType.cs index 665291edc..0a737b040 100644 --- a/NineChronicles.Headless/GraphTypes/ProtectedPrivateKeyType.cs +++ b/NineChronicles.Headless/GraphTypes/ProtectedPrivateKeyType.cs @@ -1,4 +1,5 @@ using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Libplanet.KeyStore; namespace NineChronicles.Headless.GraphTypes diff --git a/NineChronicles.Headless/GraphTypes/PublicKeyType.cs b/NineChronicles.Headless/GraphTypes/PublicKeyType.cs index 425176b84..120a8d07f 100644 --- a/NineChronicles.Headless/GraphTypes/PublicKeyType.cs +++ b/NineChronicles.Headless/GraphTypes/PublicKeyType.cs @@ -2,6 +2,7 @@ using GraphQL.Types; using Libplanet; using Libplanet.Crypto; +using Libplanet.Explorer.GraphTypes; namespace NineChronicles.Headless.GraphTypes { diff --git a/NineChronicles.Headless/GraphTypes/StandaloneMutation.cs b/NineChronicles.Headless/GraphTypes/StandaloneMutation.cs index 78101aa4f..10a72339a 100644 --- a/NineChronicles.Headless/GraphTypes/StandaloneMutation.cs +++ b/NineChronicles.Headless/GraphTypes/StandaloneMutation.cs @@ -12,6 +12,7 @@ using Serilog; using System; using GraphQL.Server.Authorization.AspNetCore; +using Libplanet.Explorer.GraphTypes; using Microsoft.Extensions.Configuration; using NCAction = Libplanet.Action.PolymorphicAction; diff --git a/NineChronicles.Headless/GraphTypes/StandaloneQuery.cs b/NineChronicles.Headless/GraphTypes/StandaloneQuery.cs index 628572d30..8005e8c27 100644 --- a/NineChronicles.Headless/GraphTypes/StandaloneQuery.cs +++ b/NineChronicles.Headless/GraphTypes/StandaloneQuery.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.Security.Cryptography; using Bencodex; using Bencodex.Types; @@ -8,6 +9,9 @@ using Libplanet.Action; using Libplanet.Assets; using Libplanet.Blockchain; +using Libplanet.Explorer.GraphTypes; +using Libplanet.Explorer.Interfaces; +using Libplanet.Store; using Microsoft.Extensions.Configuration; using Libplanet.Tx; using Nekoyume.Action; @@ -88,6 +92,11 @@ public StandaloneQuery(StandaloneContext standaloneContext, IConfiguration confi } ); + Field>>( + name: "chainQuery", + resolve: context => new { } + ); + Field>( name: "validation", description: "The validation method provider for Libplanet types.", diff --git a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs index 1ce7a1a4e..eaaf173cf 100644 --- a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs +++ b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs @@ -12,6 +12,7 @@ using Lib9c.Renderer; using Libplanet; using Libplanet.Blockchain; +using Libplanet.Explorer.GraphTypes; using Libplanet.Net; using Libplanet.Headless; using Nekoyume.Action; diff --git a/NineChronicles.Headless/GraphTypes/StateQuery.cs b/NineChronicles.Headless/GraphTypes/StateQuery.cs index 11ffb67a1..f29bc2d04 100644 --- a/NineChronicles.Headless/GraphTypes/StateQuery.cs +++ b/NineChronicles.Headless/GraphTypes/StateQuery.cs @@ -3,6 +3,7 @@ using GraphQL.Types; using Libplanet; using Libplanet.Action; +using Libplanet.Explorer.GraphTypes; using Nekoyume; using Nekoyume.Model.State; using NineChronicles.Headless.GraphTypes.States; diff --git a/NineChronicles.Headless/GraphTypes/States/AgentStateType.cs b/NineChronicles.Headless/GraphTypes/States/AgentStateType.cs index a480f81ac..1df678664 100644 --- a/NineChronicles.Headless/GraphTypes/States/AgentStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/AgentStateType.cs @@ -5,6 +5,7 @@ using Libplanet.Action; using Libplanet.Assets; using Libplanet.Blockchain; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Action; using Nekoyume.Model.State; diff --git a/NineChronicles.Headless/GraphTypes/States/ArenaInfoType.cs b/NineChronicles.Headless/GraphTypes/States/ArenaInfoType.cs index 49678dde2..7fd9dcfb6 100644 --- a/NineChronicles.Headless/GraphTypes/States/ArenaInfoType.cs +++ b/NineChronicles.Headless/GraphTypes/States/ArenaInfoType.cs @@ -1,4 +1,5 @@ using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Model.State; namespace NineChronicles.Headless.GraphTypes.States diff --git a/NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs b/NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs index 32a3f7c67..9d7e2f41e 100644 --- a/NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs @@ -1,4 +1,5 @@ using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Model.State; using NineChronicles.Headless.GraphTypes.States.Models; using NineChronicles.Headless.GraphTypes.States.Models.World; diff --git a/NineChronicles.Headless/GraphTypes/States/Models/Item/MaterialType.cs b/NineChronicles.Headless/GraphTypes/States/Models/Item/MaterialType.cs index e3e958000..c197bb9eb 100644 --- a/NineChronicles.Headless/GraphTypes/States/Models/Item/MaterialType.cs +++ b/NineChronicles.Headless/GraphTypes/States/Models/Item/MaterialType.cs @@ -1,4 +1,5 @@ using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Model.Item; namespace NineChronicles.Headless.GraphTypes.States.Models.Item diff --git a/NineChronicles.Headless/GraphTypes/States/Models/Item/ShopItemType.cs b/NineChronicles.Headless/GraphTypes/States/Models/Item/ShopItemType.cs index 9273ccaf5..ca5f7fe35 100644 --- a/NineChronicles.Headless/GraphTypes/States/Models/Item/ShopItemType.cs +++ b/NineChronicles.Headless/GraphTypes/States/Models/Item/ShopItemType.cs @@ -1,4 +1,5 @@ using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Model.Item; namespace NineChronicles.Headless.GraphTypes.States.Models.Item diff --git a/NineChronicles.Headless/GraphTypes/States/RankingInfoType.cs b/NineChronicles.Headless/GraphTypes/States/RankingInfoType.cs index 8f46a3fc6..17a8269bf 100644 --- a/NineChronicles.Headless/GraphTypes/States/RankingInfoType.cs +++ b/NineChronicles.Headless/GraphTypes/States/RankingInfoType.cs @@ -1,4 +1,5 @@ using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Model.State; namespace NineChronicles.Headless.GraphTypes.States diff --git a/NineChronicles.Headless/GraphTypes/States/RankingMapStateType.cs b/NineChronicles.Headless/GraphTypes/States/RankingMapStateType.cs index d92b64398..219e6f139 100644 --- a/NineChronicles.Headless/GraphTypes/States/RankingMapStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/RankingMapStateType.cs @@ -1,4 +1,5 @@ using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Action; using Nekoyume.Model.State; diff --git a/NineChronicles.Headless/GraphTypes/States/ShopStateType.cs b/NineChronicles.Headless/GraphTypes/States/ShopStateType.cs index 83b84e459..74149bc19 100644 --- a/NineChronicles.Headless/GraphTypes/States/ShopStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/ShopStateType.cs @@ -2,6 +2,7 @@ using System.Linq; using GraphQL; using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Model.Item; using Nekoyume.Model.State; using NineChronicles.Headless.GraphTypes.States.Models.Item; diff --git a/NineChronicles.Headless/GraphTypes/States/WeeklyArenaStateType.cs b/NineChronicles.Headless/GraphTypes/States/WeeklyArenaStateType.cs index 81eb4325f..5c10ff290 100644 --- a/NineChronicles.Headless/GraphTypes/States/WeeklyArenaStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/WeeklyArenaStateType.cs @@ -1,4 +1,5 @@ using GraphQL.Types; +using Libplanet.Explorer.GraphTypes; using Nekoyume.Model.State; namespace NineChronicles.Headless.GraphTypes.States diff --git a/NineChronicles.Headless/GraphTypes/TransactionType.cs b/NineChronicles.Headless/GraphTypes/TransactionType.cs index 9d5df9589..e5ed5afbe 100644 --- a/NineChronicles.Headless/GraphTypes/TransactionType.cs +++ b/NineChronicles.Headless/GraphTypes/TransactionType.cs @@ -1,5 +1,6 @@ using GraphQL.Types; using Libplanet.Action; +using Libplanet.Explorer.GraphTypes; using Libplanet.Tx; namespace NineChronicles.Headless.GraphTypes diff --git a/NineChronicles.Headless/GraphTypes/ValidationQuery.cs b/NineChronicles.Headless/GraphTypes/ValidationQuery.cs index c3ff9be21..a951b3ff2 100644 --- a/NineChronicles.Headless/GraphTypes/ValidationQuery.cs +++ b/NineChronicles.Headless/GraphTypes/ValidationQuery.cs @@ -4,6 +4,7 @@ using GraphQL; using GraphQL.Types; using Libplanet.Crypto; +using Libplanet.Explorer.GraphTypes; using Serilog; namespace NineChronicles.Headless.GraphTypes diff --git a/NineChronicles.Headless/NineChronicles.Headless.csproj b/NineChronicles.Headless/NineChronicles.Headless.csproj index 5f5f05068..ee269c564 100644 --- a/NineChronicles.Headless/NineChronicles.Headless.csproj +++ b/NineChronicles.Headless/NineChronicles.Headless.csproj @@ -17,6 +17,7 @@ + diff --git a/NineChronicles.Headless/UserContextBuilder.cs b/NineChronicles.Headless/UserContextBuilder.cs new file mode 100644 index 000000000..3ade5a130 --- /dev/null +++ b/NineChronicles.Headless/UserContextBuilder.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using GraphQL.Server.Transports.AspNetCore; +using Libplanet.Explorer.Interfaces; +using Microsoft.AspNetCore.Http; +using NCAction = Libplanet.Action.PolymorphicAction; + +namespace NineChronicles.Headless +{ + public class UserContextBuilder : IUserContextBuilder + { + private readonly StandaloneContext _standaloneContext; + + public UserContextBuilder(StandaloneContext standaloneContext) + { + _standaloneContext = standaloneContext; + } + + public Task> BuildUserContext(HttpContext httpContext) + { + return new ValueTask>(new Dictionary + { + [nameof(IBlockChainContext.Store)] = _standaloneContext.Store, + }).AsTask(); + } + } +}