From a6a94e8b02449f6d641b249a91a924cce912da39 Mon Sep 17 00:00:00 2001 From: s2quake Date: Fri, 31 Jan 2025 14:06:00 +0900 Subject: [PATCH] refactor: Namespace and seed --- libplanet-console.sln | 16 ++--- .../LibplanetConsole.Client.Bank/Bank.cs | 3 +- .../Commands/BankCommand.cs | 2 + .../CurrencyCollection.cs | 2 + .../ServiceCollectionExtensions.cs | 1 + .../Services/BankServiceGrpcV1.cs | 3 +- .../Application.cs | 2 +- .../ConsoleConfigureOptions.cs | 4 +- .../ConsoleHostedService.cs | 4 +- .../EntryCommands/RunCommand.cs | 2 +- .../EntryCommands/StartCommand.cs | 2 +- .../SystemTerminal.cs | 1 + .../SystemTerminalHostedService.cs | 9 +-- .../Tracers/BlockChainEventTracer.cs | 1 + .../Tracers/ClientEventTracer.cs | 4 +- .../AddressCollection.cs | 2 + src/client/LibplanetConsole.Client/Client.cs | 4 +- .../ClientBlockChain.cs | 5 +- .../ServiceCollectionExtensions.cs | 2 + .../Services/BlockChainGrpcServiceV1.cs | 3 +- .../Services/ClientGrpcServiceV1.cs | 2 +- .../ClientBank.cs | 3 +- .../Commands/BankCommand.cs | 2 + .../Commands/ClientBankCommand.cs | 2 + .../Commands/NodeBankCommand.cs | 2 + .../CurrencyCollection.cs | 2 + .../LibplanetConsole.Console.Bank/NodeBank.cs | 3 +- .../ServiceCollectionExtensions.cs | 1 + .../INodeEvidence.cs | 1 + .../NodeEvidence.cs | 3 +- .../Application.cs | 3 + .../EntryCommands/InitializeCommand.cs | 1 + ...LibplanetConsole.Console.Executable.csproj | 1 + .../NodeGenesisProcess.cs | 1 + .../Repository.cs | 1 + .../SystemTerminal.cs | 1 + .../ISeedService.cs | 6 +- .../LibplanetConsole.Console.Seed.csproj} | 13 ++-- .../NodeEndpointRouteBuilderExtensions.cs | 15 +++++ .../LibplanetConsole.Console.Seed}/Peer.cs | 5 +- .../PeerCollection.cs | 5 +- .../Protos/SeedGrpcService.proto | 2 +- .../SeedHostedService.cs | 26 +++++++ .../SeedNode.cs | 5 +- .../SeedOptions.cs | 4 +- .../SeedService.cs | 15 +++-- .../ServiceCollectionExtensions.cs | 14 ++++ .../Services/SeedGrpcServiceV1.cs | 7 +- .../AddressCollection.cs | 2 + .../ApplicationInfoProvider.cs | 2 +- .../ApplicationOptions.cs | 12 ++-- .../LibplanetConsole.Console/Client.cs | 4 +- .../ClientBlockChain.cs | 5 +- .../ClientCollection.cs | 1 + .../Commands/ClientCommand.cs | 1 + .../Commands/ClientCommandAsyncBase.cs | 1 + .../Commands/ClientCommandBase.cs | 1 + .../Commands/ClientCommandMethodBase.cs | 1 + .../Commands/NodeCommand.cs | 1 + .../Commands/NodeCommandAsyncBase.cs | 1 + .../Commands/NodeCommandBase.cs | 1 + .../Commands/NodeCommandMethodBase.cs | 1 + .../ConsoleBlockChain.cs | 1 + .../LibplanetConsole.Console/ConsoleHost.cs | 2 +- .../ConsoleHostedService.cs | 3 - .../Extensions/INodeCollectionExtensions.cs | 2 + .../IApplicationOptions.cs | 4 +- .../LibplanetConsole.Console/IClient.cs | 1 + src/console/LibplanetConsole.Console/INode.cs | 1 + .../LibplanetConsole.Console.csproj | 1 - src/console/LibplanetConsole.Console/Node.cs | 7 +- .../NodeBlockChain.cs | 5 +- .../NodeCollection.cs | 1 + .../NodeEndpointRouteBuilderExtensions.cs | 1 - .../ServiceCollectionExtensions.cs | 5 +- .../Services/ConsoleGrpcServiceV1.cs | 5 +- src/node/LibplanetConsole.Node.Bank/Bank.cs | 1 + .../Commands/BankCommand.cs | 2 + .../CurrencyCollection.cs | 2 + .../ICurrencyProvider.cs | 2 + .../ServiceCollectionExtensions.cs | 1 + .../Services/BankServiceGrpcV1.cs | 3 +- .../Evidence.cs | 12 ++-- .../IEvidence.cs | 1 + .../Services/EvidenceServiceGrpcV1.cs | 3 +- .../AddressProvider.cs | 2 + .../Application.cs | 2 +- .../ConsoleConfigureOptions.cs | 4 +- .../ConsoleHostedService.cs | 4 +- .../CurrencyProvider.cs | 1 + .../EntryCommands/RunCommand.cs | 2 +- .../EntryCommands/StartCommand.cs | 2 +- .../SystemTerminal.cs | 1 + .../SystemTerminalHostedService.cs | 9 +-- .../Tracers/BlockChainEventTracer.cs | 1 + .../Tracers/NodeEventTracer.cs | 4 +- .../BlockChainContext.cs | 7 +- .../AddressCollection.cs | 2 + .../ApplicationOptions.cs | 1 - .../BlockChainUtility.cs | 7 +- .../Commands/NonceCommand.cs | 1 + .../LibplanetConsole.Node/IAddressProvider.cs | 2 + .../IApplicationOptions.cs | 2 - .../LibplanetConsole.Node.csproj | 9 ++- .../LibplanetConsole.Node/Node.BlockChain.cs | 1 + src/node/LibplanetConsole.Node/Node.cs | 22 +++--- .../ServiceCollectionExtensions.cs | 2 + .../Services/BlockChainGrpcServiceV1.cs | 3 +- .../Services/NodeGrpcServiceV1.cs | 2 +- .../CurrencyCollectionBase.cs | 10 +-- .../LibplanetConsole.Bank/CurrencyInfo.cs | 12 +--- .../ICurrencyCollection.cs | 10 +-- .../Protos/BankGrpcService.proto | 2 +- .../AddressCollectionBase.cs | 10 +-- .../AddressInfo.cs | 12 +--- .../BlockEventArgs.cs | 10 +-- .../BlockInfo.Node.cs | 2 +- .../LibplanetConsole.BlockChain/BlockInfo.cs | 12 +--- .../Commands/AddressCommand.cs | 10 +-- .../Converters/AddressTypeConverter.cs | 10 +-- .../IAddressCollection.cs | 10 +-- .../IBlockChain.cs | 10 +-- .../Protos/BlockChainGrpcService.proto | 2 +- .../Services/BlockChainService.cs | 12 ++-- .../ClientEventArgs.cs | 6 -- .../LibplanetConsole.Client/ClientInfo.cs | 8 +-- .../Protos/ClientGrpcService.proto | 2 +- .../Services/ClientService.cs | 6 +- .../Protos/ConsoleGrpcService.proto | 2 +- .../Services/ConsoleChannel.cs | 6 +- .../Services/ConsoleService.cs | 8 +-- .../LibplanetConsole.Evidence/EvidenceInfo.cs | 8 +-- .../Protos/EvidenceGrpcService.proto | 2 +- .../LibplanetConsole.Node/BlockUtility.cs | 8 --- .../LibplanetConsole.Node/GenesisOptions.cs | 8 --- .../LibplanetConsole.Node/NodeEventArgs.cs | 8 --- src/shared/LibplanetConsole.Node/NodeInfo.cs | 11 +-- .../Protos/NodeGrpcService.proto | 2 +- .../Services/NodeChannel.cs | 8 +-- .../Services/NodeService.cs | 12 ++-- .../LibplanetConsole.Seed/BoundPeerUtility.cs | 3 +- .../Converters/BoundPeerJsonConverter.cs | 0 .../Protos/SeedGrpcService.proto | 22 ++++++ .../LibplanetConsole.Seed/SeedInfo.cs | 2 +- .../Services/SeedChannel.cs | 67 +++++++++++++++++++ .../Services/SeedService.cs | 11 +++ 146 files changed, 420 insertions(+), 335 deletions(-) rename src/{common/LibplanetConsole.Seed => console/LibplanetConsole.Console.Seed}/ISeedService.cs (64%) rename src/{common/LibplanetConsole.Seed/LibplanetConsole.Seed.csproj => console/LibplanetConsole.Console.Seed/LibplanetConsole.Console.Seed.csproj} (66%) create mode 100644 src/console/LibplanetConsole.Console.Seed/NodeEndpointRouteBuilderExtensions.cs rename src/{common/LibplanetConsole.Seed => console/LibplanetConsole.Console.Seed}/Peer.cs (94%) rename src/{common/LibplanetConsole.Seed => console/LibplanetConsole.Console.Seed}/PeerCollection.cs (95%) rename src/{common/LibplanetConsole.Seed => console/LibplanetConsole.Console.Seed}/Protos/SeedGrpcService.proto (86%) create mode 100644 src/console/LibplanetConsole.Console.Seed/SeedHostedService.cs rename src/{common/LibplanetConsole.Seed => console/LibplanetConsole.Console.Seed}/SeedNode.cs (97%) rename src/{common/LibplanetConsole.Seed => console/LibplanetConsole.Console.Seed}/SeedOptions.cs (82%) rename src/console/{LibplanetConsole.Console => LibplanetConsole.Console.Seed}/SeedService.cs (78%) create mode 100644 src/console/LibplanetConsole.Console.Seed/ServiceCollectionExtensions.cs rename src/console/{LibplanetConsole.Console => LibplanetConsole.Console.Seed}/Services/SeedGrpcServiceV1.cs (71%) rename src/{common => shared}/LibplanetConsole.Seed/BoundPeerUtility.cs (94%) rename src/{common => shared}/LibplanetConsole.Seed/Converters/BoundPeerJsonConverter.cs (100%) create mode 100644 src/shared/LibplanetConsole.Seed/Protos/SeedGrpcService.proto rename src/{common => shared}/LibplanetConsole.Seed/SeedInfo.cs (96%) create mode 100644 src/shared/LibplanetConsole.Seed/Services/SeedChannel.cs create mode 100644 src/shared/LibplanetConsole.Seed/Services/SeedService.cs diff --git a/libplanet-console.sln b/libplanet-console.sln index b5766bf9..44a0e459 100644 --- a/libplanet-console.sln +++ b/libplanet-console.sln @@ -7,8 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4194F59A-6D6 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{0F5944E2-178A-44BF-8A09-29CAD668764A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibplanetConsole.Seed", "src\common\LibplanetConsole.Seed\LibplanetConsole.Seed.csproj", "{E91A50E1-2E90-446B-BDB0-D88E0F153290}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "console", "console", "{CAB76DA9-6E57-4422-98C6-DD2D6299F675}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibplanetConsole.Console", "src\console\LibplanetConsole.Console\LibplanetConsole.Console.csproj", "{7B2D3BF1-A244-4868-A6B7-B717DB7BCAA2}" @@ -55,16 +53,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibplanetConsole.Console.Ba EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibplanetConsole.Node.Bank", "src\node\LibplanetConsole.Node.Bank\LibplanetConsole.Node.Bank.csproj", "{27D02D73-6D2C-4E69-8BB7-CFE206B7872C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibplanetConsole.Console.Seed", "src\console\LibplanetConsole.Console.Seed\LibplanetConsole.Console.Seed.csproj", "{B7C47731-7948-42E4-87FA-E82BDA26BC7D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E91A50E1-2E90-446B-BDB0-D88E0F153290}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E91A50E1-2E90-446B-BDB0-D88E0F153290}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E91A50E1-2E90-446B-BDB0-D88E0F153290}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E91A50E1-2E90-446B-BDB0-D88E0F153290}.Release|Any CPU.Build.0 = Release|Any CPU {7B2D3BF1-A244-4868-A6B7-B717DB7BCAA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7B2D3BF1-A244-4868-A6B7-B717DB7BCAA2}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B2D3BF1-A244-4868-A6B7-B717DB7BCAA2}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -141,13 +137,16 @@ Global {27D02D73-6D2C-4E69-8BB7-CFE206B7872C}.Debug|Any CPU.Build.0 = Debug|Any CPU {27D02D73-6D2C-4E69-8BB7-CFE206B7872C}.Release|Any CPU.ActiveCfg = Release|Any CPU {27D02D73-6D2C-4E69-8BB7-CFE206B7872C}.Release|Any CPU.Build.0 = Release|Any CPU + {B7C47731-7948-42E4-87FA-E82BDA26BC7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B7C47731-7948-42E4-87FA-E82BDA26BC7D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B7C47731-7948-42E4-87FA-E82BDA26BC7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B7C47731-7948-42E4-87FA-E82BDA26BC7D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {0F5944E2-178A-44BF-8A09-29CAD668764A} = {4194F59A-6D6B-4651-B133-3FE6081BF1F9} - {E91A50E1-2E90-446B-BDB0-D88E0F153290} = {0F5944E2-178A-44BF-8A09-29CAD668764A} {CAB76DA9-6E57-4422-98C6-DD2D6299F675} = {4194F59A-6D6B-4651-B133-3FE6081BF1F9} {7B2D3BF1-A244-4868-A6B7-B717DB7BCAA2} = {CAB76DA9-6E57-4422-98C6-DD2D6299F675} {8F43268F-B73B-4737-8C2F-D74F066FA09A} = {56942891-CFBD-41E4-8881-47F455D7BEFD} @@ -170,10 +169,11 @@ Global {C13519B7-B343-44EE-8797-62B17AD4CC84} = {1DEAA4CE-E29B-4379-BAF6-20B79A5946CB} {12758854-4C5E-491B-B187-590D788C3B1A} = {CAB76DA9-6E57-4422-98C6-DD2D6299F675} {27D02D73-6D2C-4E69-8BB7-CFE206B7872C} = {4A8F8EE9-769C-4C97-89BC-19D038E69998} + {B7C47731-7948-42E4-87FA-E82BDA26BC7D} = {CAB76DA9-6E57-4422-98C6-DD2D6299F675} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3227501A-47F1-4FA6-A69C-B5801260FEC9} {1778FDCB-AC26-43E4-97FE-FC4F0C427672} = {23C68389-8F13-48E7-9878-440917F70DAF} {FEF8E9D4-CBB7-4EFC-A5C2-2C9E91498D79} = {4A8F8EE9-769C-4C97-89BC-19D038E69998} - SolutionGuid = {3227501A-47F1-4FA6-A69C-B5801260FEC9} EndGlobalSection EndGlobal diff --git a/src/client/LibplanetConsole.Client.Bank/Bank.cs b/src/client/LibplanetConsole.Client.Bank/Bank.cs index 58e2bda3..dbe9094e 100644 --- a/src/client/LibplanetConsole.Client.Bank/Bank.cs +++ b/src/client/LibplanetConsole.Client.Bank/Bank.cs @@ -1,6 +1,7 @@ using Grpc.Core; +using LibplanetConsole.Bank; +using LibplanetConsole.Bank.Grpc; using LibplanetConsole.Client.Services; -using LibplanetConsole.Grpc.Bank; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Client.Bank; diff --git a/src/client/LibplanetConsole.Client.Bank/Commands/BankCommand.cs b/src/client/LibplanetConsole.Client.Bank/Commands/BankCommand.cs index 8a1f6ef6..89b81ca7 100644 --- a/src/client/LibplanetConsole.Client.Bank/Commands/BankCommand.cs +++ b/src/client/LibplanetConsole.Client.Bank/Commands/BankCommand.cs @@ -1,6 +1,8 @@ using System.ComponentModel; using JSSoft.Commands; +using LibplanetConsole.Bank; using LibplanetConsole.Bank.DataAnnotations; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Client.Bank.Commands; diff --git a/src/client/LibplanetConsole.Client.Bank/CurrencyCollection.cs b/src/client/LibplanetConsole.Client.Bank/CurrencyCollection.cs index 5940165c..67f68abc 100644 --- a/src/client/LibplanetConsole.Client.Bank/CurrencyCollection.cs +++ b/src/client/LibplanetConsole.Client.Bank/CurrencyCollection.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.Bank; + namespace LibplanetConsole.Client.Bank; internal sealed class CurrencyCollection(Bank bank) : CurrencyCollectionBase, IClientContent diff --git a/src/client/LibplanetConsole.Client.Bank/ServiceCollectionExtensions.cs b/src/client/LibplanetConsole.Client.Bank/ServiceCollectionExtensions.cs index 8d9c4ee3..ea36b354 100644 --- a/src/client/LibplanetConsole.Client.Bank/ServiceCollectionExtensions.cs +++ b/src/client/LibplanetConsole.Client.Bank/ServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.Bank; using LibplanetConsole.Client.Bank.Commands; namespace LibplanetConsole.Client.Bank; diff --git a/src/client/LibplanetConsole.Client.Bank/Services/BankServiceGrpcV1.cs b/src/client/LibplanetConsole.Client.Bank/Services/BankServiceGrpcV1.cs index 1a83ad84..d2ae0105 100644 --- a/src/client/LibplanetConsole.Client.Bank/Services/BankServiceGrpcV1.cs +++ b/src/client/LibplanetConsole.Client.Bank/Services/BankServiceGrpcV1.cs @@ -1,5 +1,6 @@ using Grpc.Core; -using LibplanetConsole.Grpc.Bank; +using LibplanetConsole.Bank; +using LibplanetConsole.Bank.Grpc; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Client.Bank.Services; diff --git a/src/client/LibplanetConsole.Client.Executable/Application.cs b/src/client/LibplanetConsole.Client.Executable/Application.cs index adc23813..2d0654b2 100644 --- a/src/client/LibplanetConsole.Client.Executable/Application.cs +++ b/src/client/LibplanetConsole.Client.Executable/Application.cs @@ -81,7 +81,7 @@ public async Task RunAsync(CancellationToken cancellationToken) app.MapGet("/", () => "Libplanet-Client"); app.MapGrpcReflectionService().AllowAnonymous(); - await Console.Out.WriteLineAsync(); + await System.Console.Out.WriteLineAsync(); await app.RunAsync(cancellationToken); } } diff --git a/src/client/LibplanetConsole.Client.Executable/ConsoleConfigureOptions.cs b/src/client/LibplanetConsole.Client.Executable/ConsoleConfigureOptions.cs index addf9841..5d74703f 100644 --- a/src/client/LibplanetConsole.Client.Executable/ConsoleConfigureOptions.cs +++ b/src/client/LibplanetConsole.Client.Executable/ConsoleConfigureOptions.cs @@ -1,5 +1,5 @@ -using LibplanetConsole.Client.Services; -using LibplanetConsole.Grpc.Console; +using LibplanetConsole.Console.Grpc; +using LibplanetConsole.Console.Services; using Microsoft.Extensions.Options; namespace LibplanetConsole.Client.Executable; diff --git a/src/client/LibplanetConsole.Client.Executable/ConsoleHostedService.cs b/src/client/LibplanetConsole.Client.Executable/ConsoleHostedService.cs index 73dfc6b5..19d5505b 100644 --- a/src/client/LibplanetConsole.Client.Executable/ConsoleHostedService.cs +++ b/src/client/LibplanetConsole.Client.Executable/ConsoleHostedService.cs @@ -1,7 +1,7 @@ -using LibplanetConsole.Client.Services; using LibplanetConsole.Common; +using LibplanetConsole.Console.Grpc; +using LibplanetConsole.Console.Services; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.Console; namespace LibplanetConsole.Client.Executable; diff --git a/src/client/LibplanetConsole.Client.Executable/EntryCommands/RunCommand.cs b/src/client/LibplanetConsole.Client.Executable/EntryCommands/RunCommand.cs index d526cba1..f10413bd 100644 --- a/src/client/LibplanetConsole.Client.Executable/EntryCommands/RunCommand.cs +++ b/src/client/LibplanetConsole.Client.Executable/EntryCommands/RunCommand.cs @@ -95,7 +95,7 @@ protected override async Task OnExecuteAsync(CancellationToken cancellationToken } catch (CommandParsingException e) { - e.Print(Console.Out); + e.Print(System.Console.Out); Environment.Exit(1); } } diff --git a/src/client/LibplanetConsole.Client.Executable/EntryCommands/StartCommand.cs b/src/client/LibplanetConsole.Client.Executable/EntryCommands/StartCommand.cs index aa75a985..25886625 100644 --- a/src/client/LibplanetConsole.Client.Executable/EntryCommands/StartCommand.cs +++ b/src/client/LibplanetConsole.Client.Executable/EntryCommands/StartCommand.cs @@ -54,7 +54,7 @@ protected override async Task OnExecuteAsync(CancellationToken cancellationToken } catch (CommandParsingException e) { - e.Print(Console.Out); + e.Print(System.Console.Out); Environment.Exit(1); } } diff --git a/src/client/LibplanetConsole.Client.Executable/SystemTerminal.cs b/src/client/LibplanetConsole.Client.Executable/SystemTerminal.cs index 18b53350..fa0e0d1d 100644 --- a/src/client/LibplanetConsole.Client.Executable/SystemTerminal.cs +++ b/src/client/LibplanetConsole.Client.Executable/SystemTerminal.cs @@ -1,6 +1,7 @@ using System.Text; using JSSoft.Commands.Extensions; using JSSoft.Terminals; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Client.Executable; diff --git a/src/client/LibplanetConsole.Client.Executable/SystemTerminalHostedService.cs b/src/client/LibplanetConsole.Client.Executable/SystemTerminalHostedService.cs index 17661766..a9a981b5 100644 --- a/src/client/LibplanetConsole.Client.Executable/SystemTerminalHostedService.cs +++ b/src/client/LibplanetConsole.Client.Executable/SystemTerminalHostedService.cs @@ -31,9 +31,9 @@ public async Task StartAsync(CancellationToken cancellationToken) await sw.WriteLineAsync(); await commandContext.ExecuteAsync(args: [], cancellationToken); await sw.WriteSeparatorAsync(TerminalColorType.BrightGreen); - commandContext.Out = Console.Out; + commandContext.Out = System.Console.Out; await sw.WriteLineIfAsync(GetStartupCondition(options), GetStartupMessage()); - await Console.Out.WriteAsync(sw.ToString()); + await System.Console.Out.WriteAsync(sw.ToString()); await terminal.StartAsync(cancellationToken); _terminal = terminal; @@ -81,9 +81,10 @@ private static string GetStartupMessage() private async Task WaitInputAsync() { using var cancellationTokenSource = new CancellationTokenSource(); + var cancellationToken = cancellationTokenSource.Token; applicationLifetime.ApplicationStopping.Register(cancellationTokenSource.Cancel); - await Console.Out.WriteLineAsync("Press any key to exit."); - await Task.Run(() => Console.ReadKey(intercept: true), cancellationTokenSource.Token); + await System.Console.Out.WriteLineAsync("Press any key to exit."); + await Task.Run(() => System.Console.ReadKey(intercept: true), cancellationToken); applicationLifetime.StopApplication(); } diff --git a/src/client/LibplanetConsole.Client.Executable/Tracers/BlockChainEventTracer.cs b/src/client/LibplanetConsole.Client.Executable/Tracers/BlockChainEventTracer.cs index d862beac..b391bfce 100644 --- a/src/client/LibplanetConsole.Client.Executable/Tracers/BlockChainEventTracer.cs +++ b/src/client/LibplanetConsole.Client.Executable/Tracers/BlockChainEventTracer.cs @@ -1,3 +1,4 @@ +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Client.Executable.Tracers; diff --git a/src/client/LibplanetConsole.Client.Executable/Tracers/ClientEventTracer.cs b/src/client/LibplanetConsole.Client.Executable/Tracers/ClientEventTracer.cs index 40de7d04..9dfb007d 100644 --- a/src/client/LibplanetConsole.Client.Executable/Tracers/ClientEventTracer.cs +++ b/src/client/LibplanetConsole.Client.Executable/Tracers/ClientEventTracer.cs @@ -8,14 +8,14 @@ internal sealed class ClientEventTracer : ClientContentBase protected override Task OnStartAsync(CancellationToken cancellationToken) { var message = $"BlockChain has been started."; - Console.Out.WriteColoredLine(message, TerminalColorType.BrightGreen); + System.Console.Out.WriteColoredLine(message, TerminalColorType.BrightGreen); return Task.CompletedTask; } protected override Task OnStopAsync(CancellationToken cancellationToken) { var message = $"BlockChain has been stopped."; - Console.Out.WriteColoredLine(message, TerminalColorType.BrightGreen); + System.Console.Out.WriteColoredLine(message, TerminalColorType.BrightGreen); return Task.CompletedTask; } } diff --git a/src/client/LibplanetConsole.Client/AddressCollection.cs b/src/client/LibplanetConsole.Client/AddressCollection.cs index 49ec0d7d..e956cc6f 100644 --- a/src/client/LibplanetConsole.Client/AddressCollection.cs +++ b/src/client/LibplanetConsole.Client/AddressCollection.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.BlockChain; + namespace LibplanetConsole.Client; internal sealed class AddressCollection : AddressCollectionBase, IClientContent diff --git a/src/client/LibplanetConsole.Client/Client.cs b/src/client/LibplanetConsole.Client/Client.cs index 7978736f..6bc14138 100644 --- a/src/client/LibplanetConsole.Client/Client.cs +++ b/src/client/LibplanetConsole.Client/Client.cs @@ -1,9 +1,9 @@ using Grpc.Net.Client; -using LibplanetConsole.Client.Converters; +using LibplanetConsole.BlockChain.Converters; using LibplanetConsole.Client.Extensions; -using LibplanetConsole.Client.Services; using LibplanetConsole.Common; using LibplanetConsole.Common.Extensions; +using LibplanetConsole.Node.Services; namespace LibplanetConsole.Client; diff --git a/src/client/LibplanetConsole.Client/ClientBlockChain.cs b/src/client/LibplanetConsole.Client/ClientBlockChain.cs index 544cc30a..485bdff3 100644 --- a/src/client/LibplanetConsole.Client/ClientBlockChain.cs +++ b/src/client/LibplanetConsole.Client/ClientBlockChain.cs @@ -1,9 +1,10 @@ using System.Security.Cryptography; using Grpc.Core; using Grpc.Net.Client; -using LibplanetConsole.Client.Services; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Grpc; +using LibplanetConsole.BlockChain.Services; using LibplanetConsole.Common; -using LibplanetConsole.Grpc.BlockChain; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Client; diff --git a/src/client/LibplanetConsole.Client/ServiceCollectionExtensions.cs b/src/client/LibplanetConsole.Client/ServiceCollectionExtensions.cs index fcda6b11..a78b8140 100644 --- a/src/client/LibplanetConsole.Client/ServiceCollectionExtensions.cs +++ b/src/client/LibplanetConsole.Client/ServiceCollectionExtensions.cs @@ -1,4 +1,6 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Commands; using LibplanetConsole.Client.Commands; using LibplanetConsole.Common; using Microsoft.Extensions.Configuration; diff --git a/src/client/LibplanetConsole.Client/Services/BlockChainGrpcServiceV1.cs b/src/client/LibplanetConsole.Client/Services/BlockChainGrpcServiceV1.cs index 43d6778a..1a69a6ae 100644 --- a/src/client/LibplanetConsole.Client/Services/BlockChainGrpcServiceV1.cs +++ b/src/client/LibplanetConsole.Client/Services/BlockChainGrpcServiceV1.cs @@ -1,6 +1,7 @@ using Grpc.Core; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Grpc; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.BlockChain; using Microsoft.Extensions.Hosting; using static LibplanetConsole.Grpc.TypeUtility; diff --git a/src/client/LibplanetConsole.Client/Services/ClientGrpcServiceV1.cs b/src/client/LibplanetConsole.Client/Services/ClientGrpcServiceV1.cs index a9a2a284..24ee1461 100644 --- a/src/client/LibplanetConsole.Client/Services/ClientGrpcServiceV1.cs +++ b/src/client/LibplanetConsole.Client/Services/ClientGrpcServiceV1.cs @@ -1,7 +1,7 @@ using Grpc.Core; +using LibplanetConsole.Client.Grpc; using LibplanetConsole.Common; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.Client; using Microsoft.Extensions.Hosting; namespace LibplanetConsole.Client.Services; diff --git a/src/console/LibplanetConsole.Console.Bank/ClientBank.cs b/src/console/LibplanetConsole.Console.Bank/ClientBank.cs index 8686375d..892f58a0 100644 --- a/src/console/LibplanetConsole.Console.Bank/ClientBank.cs +++ b/src/console/LibplanetConsole.Console.Bank/ClientBank.cs @@ -1,6 +1,7 @@ using Grpc.Core; +using LibplanetConsole.Bank; +using LibplanetConsole.Bank.Grpc; using LibplanetConsole.Console.Services; -using LibplanetConsole.Grpc.Bank; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Console.Bank; diff --git a/src/console/LibplanetConsole.Console.Bank/Commands/BankCommand.cs b/src/console/LibplanetConsole.Console.Bank/Commands/BankCommand.cs index 4a2d438c..f9466765 100644 --- a/src/console/LibplanetConsole.Console.Bank/Commands/BankCommand.cs +++ b/src/console/LibplanetConsole.Console.Bank/Commands/BankCommand.cs @@ -1,6 +1,8 @@ using System.ComponentModel; using JSSoft.Commands; +using LibplanetConsole.Bank; using LibplanetConsole.Bank.DataAnnotations; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Console.Bank.Commands; diff --git a/src/console/LibplanetConsole.Console.Bank/Commands/ClientBankCommand.cs b/src/console/LibplanetConsole.Console.Bank/Commands/ClientBankCommand.cs index d9b7d86b..258303bd 100644 --- a/src/console/LibplanetConsole.Console.Bank/Commands/ClientBankCommand.cs +++ b/src/console/LibplanetConsole.Console.Bank/Commands/ClientBankCommand.cs @@ -1,6 +1,8 @@ using System.ComponentModel; using JSSoft.Commands; +using LibplanetConsole.Bank; using LibplanetConsole.Bank.DataAnnotations; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; using LibplanetConsole.Console.Commands; diff --git a/src/console/LibplanetConsole.Console.Bank/Commands/NodeBankCommand.cs b/src/console/LibplanetConsole.Console.Bank/Commands/NodeBankCommand.cs index ba806c41..fef9c4a9 100644 --- a/src/console/LibplanetConsole.Console.Bank/Commands/NodeBankCommand.cs +++ b/src/console/LibplanetConsole.Console.Bank/Commands/NodeBankCommand.cs @@ -1,6 +1,8 @@ using System.ComponentModel; using JSSoft.Commands; +using LibplanetConsole.Bank; using LibplanetConsole.Bank.DataAnnotations; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; using LibplanetConsole.Console.Commands; diff --git a/src/console/LibplanetConsole.Console.Bank/CurrencyCollection.cs b/src/console/LibplanetConsole.Console.Bank/CurrencyCollection.cs index 7017a68c..899f1d31 100644 --- a/src/console/LibplanetConsole.Console.Bank/CurrencyCollection.cs +++ b/src/console/LibplanetConsole.Console.Bank/CurrencyCollection.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.Bank; + namespace LibplanetConsole.Console.Bank; internal sealed class CurrencyCollection : CurrencyCollectionBase, IConsoleContent diff --git a/src/console/LibplanetConsole.Console.Bank/NodeBank.cs b/src/console/LibplanetConsole.Console.Bank/NodeBank.cs index a2e53d4e..b8ce2856 100644 --- a/src/console/LibplanetConsole.Console.Bank/NodeBank.cs +++ b/src/console/LibplanetConsole.Console.Bank/NodeBank.cs @@ -1,6 +1,7 @@ using Grpc.Core; +using LibplanetConsole.Bank; +using LibplanetConsole.Bank.Grpc; using LibplanetConsole.Console.Services; -using LibplanetConsole.Grpc.Bank; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Console.Bank; diff --git a/src/console/LibplanetConsole.Console.Bank/ServiceCollectionExtensions.cs b/src/console/LibplanetConsole.Console.Bank/ServiceCollectionExtensions.cs index d44bd623..134a5dbf 100644 --- a/src/console/LibplanetConsole.Console.Bank/ServiceCollectionExtensions.cs +++ b/src/console/LibplanetConsole.Console.Bank/ServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.Bank; using LibplanetConsole.Console.Bank.Commands; namespace LibplanetConsole.Console.Bank; diff --git a/src/console/LibplanetConsole.Console.Evidence/INodeEvidence.cs b/src/console/LibplanetConsole.Console.Evidence/INodeEvidence.cs index 4ed9fd01..586ec897 100644 --- a/src/console/LibplanetConsole.Console.Evidence/INodeEvidence.cs +++ b/src/console/LibplanetConsole.Console.Evidence/INodeEvidence.cs @@ -1,4 +1,5 @@ using Libplanet.Types.Evidence; +using LibplanetConsole.Evidence; namespace LibplanetConsole.Console.Evidence; diff --git a/src/console/LibplanetConsole.Console.Evidence/NodeEvidence.cs b/src/console/LibplanetConsole.Console.Evidence/NodeEvidence.cs index 6a5bb6e8..1e21479d 100644 --- a/src/console/LibplanetConsole.Console.Evidence/NodeEvidence.cs +++ b/src/console/LibplanetConsole.Console.Evidence/NodeEvidence.cs @@ -1,7 +1,8 @@ using Grpc.Core; using Libplanet.Types.Evidence; using LibplanetConsole.Console.Services; -using LibplanetConsole.Grpc.Evidence; +using LibplanetConsole.Evidence; +using LibplanetConsole.Evidence.Grpc; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Console.Evidence; diff --git a/src/console/LibplanetConsole.Console.Executable/Application.cs b/src/console/LibplanetConsole.Console.Executable/Application.cs index 4a629c91..6e718308 100644 --- a/src/console/LibplanetConsole.Console.Executable/Application.cs +++ b/src/console/LibplanetConsole.Console.Executable/Application.cs @@ -4,6 +4,7 @@ using LibplanetConsole.Console.Evidence; using LibplanetConsole.Console.Executable.Commands; using LibplanetConsole.Console.Executable.Tracers; +using LibplanetConsole.Console.Seed; using LibplanetConsole.Logging; using Serilog; @@ -51,6 +52,7 @@ public Application(WebApplicationBuilder builder) services.AddSingleton(); services.AddConsole(configuration); + services.AddSeed(); services.AddEvidence(); services.AddBank(); @@ -90,6 +92,7 @@ public async Task RunAsync(CancellationToken cancellationToken) using var app = _builder.Build(); app.UseConsole(); + app.UseSeed(); app.MapGet("/", () => "Libplanet-Console"); app.MapGrpcReflectionService().AllowAnonymous(); diff --git a/src/console/LibplanetConsole.Console.Executable/EntryCommands/InitializeCommand.cs b/src/console/LibplanetConsole.Console.Executable/EntryCommands/InitializeCommand.cs index 9574add2..b95bc51c 100644 --- a/src/console/LibplanetConsole.Console.Executable/EntryCommands/InitializeCommand.cs +++ b/src/console/LibplanetConsole.Console.Executable/EntryCommands/InitializeCommand.cs @@ -5,6 +5,7 @@ using LibplanetConsole.Common.Extensions; using LibplanetConsole.Common.IO; using LibplanetConsole.DataAnnotations; +using LibplanetConsole.Node; using static LibplanetConsole.Common.EndPointUtility; namespace LibplanetConsole.Console.Executable.EntryCommands; diff --git a/src/console/LibplanetConsole.Console.Executable/LibplanetConsole.Console.Executable.csproj b/src/console/LibplanetConsole.Console.Executable/LibplanetConsole.Console.Executable.csproj index 702ca7b6..d8c243b8 100644 --- a/src/console/LibplanetConsole.Console.Executable/LibplanetConsole.Console.Executable.csproj +++ b/src/console/LibplanetConsole.Console.Executable/LibplanetConsole.Console.Executable.csproj @@ -3,6 +3,7 @@ + diff --git a/src/console/LibplanetConsole.Console.Executable/NodeGenesisProcess.cs b/src/console/LibplanetConsole.Console.Executable/NodeGenesisProcess.cs index 9ae83f8b..d1d49499 100644 --- a/src/console/LibplanetConsole.Console.Executable/NodeGenesisProcess.cs +++ b/src/console/LibplanetConsole.Console.Executable/NodeGenesisProcess.cs @@ -1,4 +1,5 @@ using LibplanetConsole.Common; +using LibplanetConsole.Node; namespace LibplanetConsole.Console.Executable; diff --git a/src/console/LibplanetConsole.Console.Executable/Repository.cs b/src/console/LibplanetConsole.Console.Executable/Repository.cs index c9be1948..0653e5dd 100644 --- a/src/console/LibplanetConsole.Console.Executable/Repository.cs +++ b/src/console/LibplanetConsole.Console.Executable/Repository.cs @@ -8,6 +8,7 @@ using LibplanetConsole.Common.DataAnnotations; using LibplanetConsole.Common.Progresses; using LibplanetConsole.Console.Extensions; +using LibplanetConsole.Node; using LibplanetConsole.Options; using static LibplanetConsole.Common.EndPointUtility; diff --git a/src/console/LibplanetConsole.Console.Executable/SystemTerminal.cs b/src/console/LibplanetConsole.Console.Executable/SystemTerminal.cs index 9478f7cd..ddb6bf6b 100644 --- a/src/console/LibplanetConsole.Console.Executable/SystemTerminal.cs +++ b/src/console/LibplanetConsole.Console.Executable/SystemTerminal.cs @@ -1,6 +1,7 @@ using System.Text; using JSSoft.Commands.Extensions; using JSSoft.Terminals; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Console.Executable; diff --git a/src/common/LibplanetConsole.Seed/ISeedService.cs b/src/console/LibplanetConsole.Console.Seed/ISeedService.cs similarity index 64% rename from src/common/LibplanetConsole.Seed/ISeedService.cs rename to src/console/LibplanetConsole.Console.Seed/ISeedService.cs index 5cc8009b..df0b59db 100644 --- a/src/common/LibplanetConsole.Seed/ISeedService.cs +++ b/src/console/LibplanetConsole.Console.Seed/ISeedService.cs @@ -1,8 +1,8 @@ -namespace LibplanetConsole.Seed; +using LibplanetConsole.Seed; + +namespace LibplanetConsole.Console.Seed; public interface ISeedService { - bool IsEnabled { get; } - Task GetSeedAsync(PublicKey publicKey, CancellationToken cancellationToken); } diff --git a/src/common/LibplanetConsole.Seed/LibplanetConsole.Seed.csproj b/src/console/LibplanetConsole.Console.Seed/LibplanetConsole.Console.Seed.csproj similarity index 66% rename from src/common/LibplanetConsole.Seed/LibplanetConsole.Seed.csproj rename to src/console/LibplanetConsole.Console.Seed/LibplanetConsole.Console.Seed.csproj index f140bfee..4a587d59 100644 --- a/src/common/LibplanetConsole.Seed/LibplanetConsole.Seed.csproj +++ b/src/console/LibplanetConsole.Console.Seed/LibplanetConsole.Console.Seed.csproj @@ -11,12 +11,12 @@ - + + - - + @@ -24,7 +24,12 @@ - + + + + + diff --git a/src/console/LibplanetConsole.Console.Seed/NodeEndpointRouteBuilderExtensions.cs b/src/console/LibplanetConsole.Console.Seed/NodeEndpointRouteBuilderExtensions.cs new file mode 100644 index 00000000..70496d77 --- /dev/null +++ b/src/console/LibplanetConsole.Console.Seed/NodeEndpointRouteBuilderExtensions.cs @@ -0,0 +1,15 @@ +using LibplanetConsole.Console.Seed.Services; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Routing; + +namespace LibplanetConsole.Console.Seed; + +public static class NodeEndpointRouteBuilderExtensions +{ + public static IEndpointRouteBuilder UseSeed(this IEndpointRouteBuilder @this) + { + @this.MapGrpcService(); + + return @this; + } +} diff --git a/src/common/LibplanetConsole.Seed/Peer.cs b/src/console/LibplanetConsole.Console.Seed/Peer.cs similarity index 94% rename from src/common/LibplanetConsole.Seed/Peer.cs rename to src/console/LibplanetConsole.Console.Seed/Peer.cs index 4113051f..968d9e98 100644 --- a/src/common/LibplanetConsole.Seed/Peer.cs +++ b/src/console/LibplanetConsole.Console.Seed/Peer.cs @@ -2,10 +2,11 @@ using Libplanet.Net.Messages; using Libplanet.Net.Transports; using Serilog; +using ILogger = Serilog.ILogger; -namespace LibplanetConsole.Seed; +namespace LibplanetConsole.Console.Seed; -public sealed class Peer +internal sealed class Peer { private readonly ILogger _logger = Log.ForContext(); diff --git a/src/common/LibplanetConsole.Seed/PeerCollection.cs b/src/console/LibplanetConsole.Console.Seed/PeerCollection.cs similarity index 95% rename from src/common/LibplanetConsole.Seed/PeerCollection.cs rename to src/console/LibplanetConsole.Console.Seed/PeerCollection.cs index a4ce7fb9..c360c144 100644 --- a/src/common/LibplanetConsole.Seed/PeerCollection.cs +++ b/src/console/LibplanetConsole.Console.Seed/PeerCollection.cs @@ -2,10 +2,11 @@ using System.Collections.Concurrent; using Libplanet.Net.Transports; using Serilog; +using ILogger = Serilog.ILogger; -namespace LibplanetConsole.Seed; +namespace LibplanetConsole.Console.Seed; -public sealed class PeerCollection : IEnumerable +internal sealed class PeerCollection : IEnumerable { private readonly ConcurrentDictionary _infoByAddress = []; private readonly SeedOptions _seedOptions; diff --git a/src/common/LibplanetConsole.Seed/Protos/SeedGrpcService.proto b/src/console/LibplanetConsole.Console.Seed/Protos/SeedGrpcService.proto similarity index 86% rename from src/common/LibplanetConsole.Seed/Protos/SeedGrpcService.proto rename to src/console/LibplanetConsole.Console.Seed/Protos/SeedGrpcService.proto index 2207d470..8e193d58 100644 --- a/src/common/LibplanetConsole.Seed/Protos/SeedGrpcService.proto +++ b/src/console/LibplanetConsole.Console.Seed/Protos/SeedGrpcService.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option csharp_namespace = "LibplanetConsole.Grpc.Seed"; +option csharp_namespace = "LibplanetConsole.Seed.Grpc"; package libplanet.console.seed.v1; diff --git a/src/console/LibplanetConsole.Console.Seed/SeedHostedService.cs b/src/console/LibplanetConsole.Console.Seed/SeedHostedService.cs new file mode 100644 index 00000000..1e80fce3 --- /dev/null +++ b/src/console/LibplanetConsole.Console.Seed/SeedHostedService.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Hosting; + +namespace LibplanetConsole.Console.Seed; + +internal sealed class SeedHostedService(SeedService seedService) + : IHostedService +{ + private CancellationTokenSource? _cancellationTokenSource; + + public async Task StartAsync(CancellationToken cancellationToken) + { + await seedService.StartAsync(cancellationToken); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (_cancellationTokenSource is not null) + { + await _cancellationTokenSource.CancelAsync(); + _cancellationTokenSource.Dispose(); + _cancellationTokenSource = null; + } + + await seedService.StopAsync(cancellationToken); + } +} diff --git a/src/common/LibplanetConsole.Seed/SeedNode.cs b/src/console/LibplanetConsole.Console.Seed/SeedNode.cs similarity index 97% rename from src/common/LibplanetConsole.Seed/SeedNode.cs rename to src/console/LibplanetConsole.Console.Seed/SeedNode.cs index 71073415..13365d5b 100644 --- a/src/common/LibplanetConsole.Seed/SeedNode.cs +++ b/src/console/LibplanetConsole.Console.Seed/SeedNode.cs @@ -3,10 +3,11 @@ using Libplanet.Net.Transports; using Serilog; using static LibplanetConsole.Common.EndPointUtility; +using ILogger = Serilog.ILogger; -namespace LibplanetConsole.Seed; +namespace LibplanetConsole.Console.Seed; -public sealed class SeedNode(string name, SeedOptions seedOptions) +internal sealed class SeedNode(string name, SeedOptions seedOptions) { private readonly ILogger _logger = Log.ForContext(); diff --git a/src/common/LibplanetConsole.Seed/SeedOptions.cs b/src/console/LibplanetConsole.Console.Seed/SeedOptions.cs similarity index 82% rename from src/common/LibplanetConsole.Seed/SeedOptions.cs rename to src/console/LibplanetConsole.Console.Seed/SeedOptions.cs index 7047415d..18ef7426 100644 --- a/src/common/LibplanetConsole.Seed/SeedOptions.cs +++ b/src/console/LibplanetConsole.Console.Seed/SeedOptions.cs @@ -1,6 +1,6 @@ -namespace LibplanetConsole.Seed; +namespace LibplanetConsole.Console.Seed; -public sealed record class SeedOptions +internal sealed record class SeedOptions { public required PrivateKey PrivateKey { get; init; } diff --git a/src/console/LibplanetConsole.Console/SeedService.cs b/src/console/LibplanetConsole.Console.Seed/SeedService.cs similarity index 78% rename from src/console/LibplanetConsole.Console/SeedService.cs rename to src/console/LibplanetConsole.Console.Seed/SeedService.cs index 8f0e9c96..42298269 100644 --- a/src/console/LibplanetConsole.Console/SeedService.cs +++ b/src/console/LibplanetConsole.Console.Seed/SeedService.cs @@ -1,7 +1,7 @@ using LibplanetConsole.Common; using LibplanetConsole.Seed; -namespace LibplanetConsole.Console; +namespace LibplanetConsole.Console.Seed; internal sealed class SeedService(IApplicationOptions options) : ISeedService { @@ -9,8 +9,6 @@ internal sealed class SeedService(IApplicationOptions options) : ISeedService private SeedNode? _blocksyncSeedNode; private SeedNode? _consensusSeedNode; - bool ISeedService.IsEnabled => true; - public Task GetSeedAsync( PublicKey publicKey, CancellationToken cancellationToken) { @@ -32,21 +30,24 @@ public Task GetSeedAsync( public async Task StartAsync(CancellationToken cancellationToken) { + var blocksyncPort = options.BlocksyncPort; + var consensusPort = options.ConsensusPort; + var appProtocolVersion = AppProtocolVersion.FromToken(options.AppProtocolVersion); _blocksyncSeedNode = new SeedNode( "Blocksync", new() { PrivateKey = _seedNodePrivateKey, - Port = options.BlocksyncPort is 0 ? PortUtility.NextPort() : options.BlocksyncPort, - AppProtocolVersion = options.AppProtocolVersion, + Port = blocksyncPort is 0 ? PortUtility.NextPort() : blocksyncPort, + AppProtocolVersion = appProtocolVersion, }); _consensusSeedNode = new SeedNode( "Consensus", new() { PrivateKey = _seedNodePrivateKey, - Port = options.ConsensusPort is 0 ? PortUtility.NextPort() : options.ConsensusPort, - AppProtocolVersion = options.AppProtocolVersion, + Port = consensusPort is 0 ? PortUtility.NextPort() : consensusPort, + AppProtocolVersion = appProtocolVersion, }); await _blocksyncSeedNode.StartAsync(cancellationToken); await _consensusSeedNode.StartAsync(cancellationToken); diff --git a/src/console/LibplanetConsole.Console.Seed/ServiceCollectionExtensions.cs b/src/console/LibplanetConsole.Console.Seed/ServiceCollectionExtensions.cs new file mode 100644 index 00000000..f9b27fa6 --- /dev/null +++ b/src/console/LibplanetConsole.Console.Seed/ServiceCollectionExtensions.cs @@ -0,0 +1,14 @@ +namespace LibplanetConsole.Console.Seed; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddSeed(this IServiceCollection @this) + { + @this.AddSingleton() + .AddSingleton(s => s.GetRequiredService()); + + @this.AddHostedService(); + + return @this; + } +} diff --git a/src/console/LibplanetConsole.Console/Services/SeedGrpcServiceV1.cs b/src/console/LibplanetConsole.Console.Seed/Services/SeedGrpcServiceV1.cs similarity index 71% rename from src/console/LibplanetConsole.Console/Services/SeedGrpcServiceV1.cs rename to src/console/LibplanetConsole.Console.Seed/Services/SeedGrpcServiceV1.cs index 2223433d..8232a85c 100644 --- a/src/console/LibplanetConsole.Console/Services/SeedGrpcServiceV1.cs +++ b/src/console/LibplanetConsole.Console.Seed/Services/SeedGrpcServiceV1.cs @@ -1,10 +1,9 @@ using Grpc.Core; -using LibplanetConsole.Grpc.Seed; -using LibplanetConsole.Seed; +using LibplanetConsole.Seed.Grpc; -namespace LibplanetConsole.Console.Services; +namespace LibplanetConsole.Console.Seed.Services; -public sealed class SeedGrpcServiceV1(ISeedService seedService) +internal sealed class SeedGrpcServiceV1(ISeedService seedService) : SeedGrpcService.SeedGrpcServiceBase { public async override Task GetSeed( diff --git a/src/console/LibplanetConsole.Console/AddressCollection.cs b/src/console/LibplanetConsole.Console/AddressCollection.cs index 620f6c21..401f8df7 100644 --- a/src/console/LibplanetConsole.Console/AddressCollection.cs +++ b/src/console/LibplanetConsole.Console/AddressCollection.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.BlockChain; + namespace LibplanetConsole.Console; internal sealed class AddressCollection : AddressCollectionBase, IConsoleContent diff --git a/src/console/LibplanetConsole.Console/ApplicationInfoProvider.cs b/src/console/LibplanetConsole.Console/ApplicationInfoProvider.cs index 93c8b15f..7c457bff 100644 --- a/src/console/LibplanetConsole.Console/ApplicationInfoProvider.cs +++ b/src/console/LibplanetConsole.Console/ApplicationInfoProvider.cs @@ -12,7 +12,7 @@ public ApplicationInfoProvider(IApplicationOptions options) { LogPath = options.LogPath, GenesisHash = options.GenesisBlock.Hash.ToString(), - AppProtocolVersion = options.AppProtocolVersion.Token, + AppProtocolVersion = options.AppProtocolVersion, NoProcess = options.NoProcess, Detach = options.Detach, NewWindow = options.NewWindow, diff --git a/src/console/LibplanetConsole.Console/ApplicationOptions.cs b/src/console/LibplanetConsole.Console/ApplicationOptions.cs index 71606cb0..b012ad44 100644 --- a/src/console/LibplanetConsole.Console/ApplicationOptions.cs +++ b/src/console/LibplanetConsole.Console/ApplicationOptions.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using Libplanet.Net; using LibplanetConsole.Common; using LibplanetConsole.Common.DataAnnotations; +using LibplanetConsole.Node; using LibplanetConsole.Options; namespace LibplanetConsole.Console; @@ -15,7 +15,7 @@ public sealed class ApplicationOptions : OptionsBase, IAppli private PrivateKey? _privateKey; private Block? _genesisBlock; - private AppProtocolVersion? _appProtocolVersion; + private string? _appProtocolVersion; [PrivateKey] public string PrivateKey { get; set; } = string.Empty; @@ -56,7 +56,7 @@ public sealed class ApplicationOptions : OptionsBase, IAppli Block IApplicationOptions.GenesisBlock => _genesisBlock ??= GetGenesisBlock(); - AppProtocolVersion IApplicationOptions.AppProtocolVersion + string IApplicationOptions.AppProtocolVersion => _appProtocolVersion ??= GetAppProtocolVersion(); ProcessOptions? IApplicationOptions.ProcessOptions @@ -80,17 +80,17 @@ private Block GetGenesisBlock() throw new NotSupportedException("Genesis is not set."); } - private AppProtocolVersion GetAppProtocolVersion() + private string GetAppProtocolVersion() { if (AppProtocolVersionPath != string.Empty) { var lines = File.ReadAllLines(AppProtocolVersionPath); - return Libplanet.Net.AppProtocolVersion.FromToken(lines[0]); + return lines[0]; } if (AppProtocolVersion != string.Empty) { - return Libplanet.Net.AppProtocolVersion.FromToken(AppProtocolVersion); + return AppProtocolVersion; } throw new NotSupportedException("AppProtocolVersion is not set."); diff --git a/src/console/LibplanetConsole.Console/Client.cs b/src/console/LibplanetConsole.Console/Client.cs index 9a407266..97a2a6fa 100644 --- a/src/console/LibplanetConsole.Console/Client.cs +++ b/src/console/LibplanetConsole.Console/Client.cs @@ -1,12 +1,14 @@ using System.Diagnostics; using Grpc.Core; using Grpc.Net.Client; +using LibplanetConsole.Client; +using LibplanetConsole.Client.Grpc; +using LibplanetConsole.Client.Services; using LibplanetConsole.Common; using LibplanetConsole.Common.Extensions; using LibplanetConsole.Common.Threading; using LibplanetConsole.Console.Extensions; using LibplanetConsole.Console.Services; -using LibplanetConsole.Grpc.Client; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/ClientBlockChain.cs b/src/console/LibplanetConsole.Console/ClientBlockChain.cs index a20836ba..4b60eb5f 100644 --- a/src/console/LibplanetConsole.Console/ClientBlockChain.cs +++ b/src/console/LibplanetConsole.Console/ClientBlockChain.cs @@ -1,9 +1,10 @@ using System.Security.Cryptography; using Grpc.Core; using Grpc.Net.Client; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Grpc; +using LibplanetConsole.BlockChain.Services; using LibplanetConsole.Common; -using LibplanetConsole.Console.Services; -using LibplanetConsole.Grpc.BlockChain; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/ClientCollection.cs b/src/console/LibplanetConsole.Console/ClientCollection.cs index 8859cf14..c5e83fa3 100644 --- a/src/console/LibplanetConsole.Console/ClientCollection.cs +++ b/src/console/LibplanetConsole.Console/ClientCollection.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Specialized; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/Commands/ClientCommand.cs b/src/console/LibplanetConsole.Console/Commands/ClientCommand.cs index d13234e6..3ec9f94a 100644 --- a/src/console/LibplanetConsole.Console/Commands/ClientCommand.cs +++ b/src/console/LibplanetConsole.Console/Commands/ClientCommand.cs @@ -1,5 +1,6 @@ using JSSoft.Commands; using JSSoft.Terminals; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common; using LibplanetConsole.Common.Actions; using LibplanetConsole.Common.Extensions; diff --git a/src/console/LibplanetConsole.Console/Commands/ClientCommandAsyncBase.cs b/src/console/LibplanetConsole.Console/Commands/ClientCommandAsyncBase.cs index cdb8d45a..d1adc3fa 100644 --- a/src/console/LibplanetConsole.Console/Commands/ClientCommandAsyncBase.cs +++ b/src/console/LibplanetConsole.Console/Commands/ClientCommandAsyncBase.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; using LibplanetConsole.Console.Extensions; namespace LibplanetConsole.Console.Commands; diff --git a/src/console/LibplanetConsole.Console/Commands/ClientCommandBase.cs b/src/console/LibplanetConsole.Console/Commands/ClientCommandBase.cs index 5a46973b..a1effb6a 100644 --- a/src/console/LibplanetConsole.Console/Commands/ClientCommandBase.cs +++ b/src/console/LibplanetConsole.Console/Commands/ClientCommandBase.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; using LibplanetConsole.Console.Extensions; namespace LibplanetConsole.Console.Commands; diff --git a/src/console/LibplanetConsole.Console/Commands/ClientCommandMethodBase.cs b/src/console/LibplanetConsole.Console/Commands/ClientCommandMethodBase.cs index 35befd68..e96d9b26 100644 --- a/src/console/LibplanetConsole.Console/Commands/ClientCommandMethodBase.cs +++ b/src/console/LibplanetConsole.Console/Commands/ClientCommandMethodBase.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; using LibplanetConsole.Console.Extensions; namespace LibplanetConsole.Console.Commands; diff --git a/src/console/LibplanetConsole.Console/Commands/NodeCommand.cs b/src/console/LibplanetConsole.Console/Commands/NodeCommand.cs index 7e52319c..213c0fd6 100644 --- a/src/console/LibplanetConsole.Console/Commands/NodeCommand.cs +++ b/src/console/LibplanetConsole.Console/Commands/NodeCommand.cs @@ -1,5 +1,6 @@ using JSSoft.Commands; using JSSoft.Terminals; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common; using LibplanetConsole.Common.Actions; using LibplanetConsole.Common.Extensions; diff --git a/src/console/LibplanetConsole.Console/Commands/NodeCommandAsyncBase.cs b/src/console/LibplanetConsole.Console/Commands/NodeCommandAsyncBase.cs index 404e068e..f7b2e78e 100644 --- a/src/console/LibplanetConsole.Console/Commands/NodeCommandAsyncBase.cs +++ b/src/console/LibplanetConsole.Console/Commands/NodeCommandAsyncBase.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; using LibplanetConsole.Console.Extensions; namespace LibplanetConsole.Console.Commands; diff --git a/src/console/LibplanetConsole.Console/Commands/NodeCommandBase.cs b/src/console/LibplanetConsole.Console/Commands/NodeCommandBase.cs index b1fbf358..d2b6fa20 100644 --- a/src/console/LibplanetConsole.Console/Commands/NodeCommandBase.cs +++ b/src/console/LibplanetConsole.Console/Commands/NodeCommandBase.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; using LibplanetConsole.Console.Extensions; namespace LibplanetConsole.Console.Commands; diff --git a/src/console/LibplanetConsole.Console/Commands/NodeCommandMethodBase.cs b/src/console/LibplanetConsole.Console/Commands/NodeCommandMethodBase.cs index 4212e3fe..a3c91395 100644 --- a/src/console/LibplanetConsole.Console/Commands/NodeCommandMethodBase.cs +++ b/src/console/LibplanetConsole.Console/Commands/NodeCommandMethodBase.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; using LibplanetConsole.Console.Extensions; namespace LibplanetConsole.Console.Commands; diff --git a/src/console/LibplanetConsole.Console/ConsoleBlockChain.cs b/src/console/LibplanetConsole.Console/ConsoleBlockChain.cs index ce9aaa09..6d66d2b7 100644 --- a/src/console/LibplanetConsole.Console/ConsoleBlockChain.cs +++ b/src/console/LibplanetConsole.Console/ConsoleBlockChain.cs @@ -1,4 +1,5 @@ using System.Security.Cryptography; +using LibplanetConsole.BlockChain; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/ConsoleHost.cs b/src/console/LibplanetConsole.Console/ConsoleHost.cs index 6fcadebc..ca243af3 100644 --- a/src/console/LibplanetConsole.Console/ConsoleHost.cs +++ b/src/console/LibplanetConsole.Console/ConsoleHost.cs @@ -1,4 +1,4 @@ -using LibplanetConsole.Console.Converters; +using LibplanetConsole.BlockChain.Converters; using LibplanetConsole.Console.Extensions; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/ConsoleHostedService.cs b/src/console/LibplanetConsole.Console/ConsoleHostedService.cs index b6696b86..cb66f72a 100644 --- a/src/console/LibplanetConsole.Console/ConsoleHostedService.cs +++ b/src/console/LibplanetConsole.Console/ConsoleHostedService.cs @@ -5,7 +5,6 @@ namespace LibplanetConsole.Console; internal sealed class ConsoleHostedService( IServiceProvider serviceProvider, - SeedService seedService, ConsoleHost console, IHostApplicationLifetime applicationLifetime) : IHostedService @@ -17,7 +16,6 @@ public async Task StartAsync(CancellationToken cancellationToken) console.Contents = GetConsoleContents(serviceProvider); applicationLifetime.ApplicationStarted.Register( async () => await console.InitializeAsync()); - await seedService.StartAsync(cancellationToken); await console.StartAsync(cancellationToken); } @@ -31,7 +29,6 @@ public async Task StopAsync(CancellationToken cancellationToken) } await console.StopAsync(cancellationToken); - await seedService.StopAsync(cancellationToken); } private static IConsoleContent[] GetConsoleContents(IServiceProvider serviceProvider) diff --git a/src/console/LibplanetConsole.Console/Extensions/INodeCollectionExtensions.cs b/src/console/LibplanetConsole.Console/Extensions/INodeCollectionExtensions.cs index 8f0f9f7b..e2fbab46 100644 --- a/src/console/LibplanetConsole.Console/Extensions/INodeCollectionExtensions.cs +++ b/src/console/LibplanetConsole.Console/Extensions/INodeCollectionExtensions.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.BlockChain; + namespace LibplanetConsole.Console.Extensions; public static class INodeCollectionExtensions diff --git a/src/console/LibplanetConsole.Console/IApplicationOptions.cs b/src/console/LibplanetConsole.Console/IApplicationOptions.cs index 01b26916..e9332d38 100644 --- a/src/console/LibplanetConsole.Console/IApplicationOptions.cs +++ b/src/console/LibplanetConsole.Console/IApplicationOptions.cs @@ -1,5 +1,3 @@ -using Libplanet.Net; - namespace LibplanetConsole.Console; public interface IApplicationOptions @@ -12,7 +10,7 @@ public interface IApplicationOptions Block GenesisBlock { get; } - AppProtocolVersion AppProtocolVersion { get; } + string AppProtocolVersion { get; } string LogPath { get; } diff --git a/src/console/LibplanetConsole.Console/IClient.cs b/src/console/LibplanetConsole.Console/IClient.cs index 378534c7..a3262044 100644 --- a/src/console/LibplanetConsole.Console/IClient.cs +++ b/src/console/LibplanetConsole.Console/IClient.cs @@ -1,3 +1,4 @@ +using LibplanetConsole.Client; using LibplanetConsole.Common; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/INode.cs b/src/console/LibplanetConsole.Console/INode.cs index 7382d284..074d3b38 100644 --- a/src/console/LibplanetConsole.Console/INode.cs +++ b/src/console/LibplanetConsole.Console/INode.cs @@ -1,4 +1,5 @@ using LibplanetConsole.Common; +using LibplanetConsole.Node; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/LibplanetConsole.Console.csproj b/src/console/LibplanetConsole.Console/LibplanetConsole.Console.csproj index be893683..4b700033 100644 --- a/src/console/LibplanetConsole.Console/LibplanetConsole.Console.csproj +++ b/src/console/LibplanetConsole.Console/LibplanetConsole.Console.csproj @@ -1,7 +1,6 @@ - diff --git a/src/console/LibplanetConsole.Console/Node.cs b/src/console/LibplanetConsole.Console/Node.cs index cd9c48e9..2ea7958c 100644 --- a/src/console/LibplanetConsole.Console/Node.cs +++ b/src/console/LibplanetConsole.Console/Node.cs @@ -6,8 +6,9 @@ using LibplanetConsole.Common.IO; using LibplanetConsole.Common.Threading; using LibplanetConsole.Console.Extensions; -using LibplanetConsole.Console.Services; -using LibplanetConsole.Grpc.Node; +using LibplanetConsole.Node; +using LibplanetConsole.Node.Grpc; +using LibplanetConsole.Node.Services; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; @@ -451,7 +452,7 @@ private NodeProcess CreateProcess(ProcessOptions options) var applicationOptions = _serviceProvider.GetRequiredService(); var genesisPath = TempFile.WriteAllBytes( BlockUtility.SerializeBlock(applicationOptions.GenesisBlock)); - var apvPath = TempFile.WriteAllText(applicationOptions.AppProtocolVersion.Token); + var apvPath = TempFile.WriteAllText(applicationOptions.AppProtocolVersion); process.ExtendedArguments.Add("--genesis-path"); process.ExtendedArguments.Add(genesisPath); process.ExtendedArguments.Add("--apv-path"); diff --git a/src/console/LibplanetConsole.Console/NodeBlockChain.cs b/src/console/LibplanetConsole.Console/NodeBlockChain.cs index 87fd4956..ed466ecb 100644 --- a/src/console/LibplanetConsole.Console/NodeBlockChain.cs +++ b/src/console/LibplanetConsole.Console/NodeBlockChain.cs @@ -1,9 +1,10 @@ using System.Security.Cryptography; using Grpc.Core; using Grpc.Net.Client; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Grpc; +using LibplanetConsole.BlockChain.Services; using LibplanetConsole.Common; -using LibplanetConsole.Console.Services; -using LibplanetConsole.Grpc.BlockChain; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/NodeCollection.cs b/src/console/LibplanetConsole.Console/NodeCollection.cs index 369ecbc9..77a13d06 100644 --- a/src/console/LibplanetConsole.Console/NodeCollection.cs +++ b/src/console/LibplanetConsole.Console/NodeCollection.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Specialized; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Console; diff --git a/src/console/LibplanetConsole.Console/NodeEndpointRouteBuilderExtensions.cs b/src/console/LibplanetConsole.Console/NodeEndpointRouteBuilderExtensions.cs index 756d2969..71b3bab5 100644 --- a/src/console/LibplanetConsole.Console/NodeEndpointRouteBuilderExtensions.cs +++ b/src/console/LibplanetConsole.Console/NodeEndpointRouteBuilderExtensions.cs @@ -8,7 +8,6 @@ public static class NodeEndpointRouteBuilderExtensions { public static IEndpointRouteBuilder UseConsole(this IEndpointRouteBuilder @this) { - @this.MapGrpcService(); @this.MapGrpcService(); return @this; diff --git a/src/console/LibplanetConsole.Console/ServiceCollectionExtensions.cs b/src/console/LibplanetConsole.Console/ServiceCollectionExtensions.cs index ff2aab12..342b3734 100644 --- a/src/console/LibplanetConsole.Console/ServiceCollectionExtensions.cs +++ b/src/console/LibplanetConsole.Console/ServiceCollectionExtensions.cs @@ -1,9 +1,10 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Commands; using LibplanetConsole.Common; using LibplanetConsole.Console.Commands; using LibplanetConsole.Console.Commands.Clients; using LibplanetConsole.Console.Commands.Nodes; -using LibplanetConsole.Seed; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; @@ -24,8 +25,6 @@ public static IServiceCollection AddConsole( s => s.GetRequiredService>().Value); @this.AddSingleton(synchronizationContext); - @this.AddSingleton() - .AddSingleton(s => s.GetRequiredService()); @this.AddSingleton() .AddSingleton(s => s.GetRequiredService()) .AddSingleton(s => s.GetRequiredService()); diff --git a/src/console/LibplanetConsole.Console/Services/ConsoleGrpcServiceV1.cs b/src/console/LibplanetConsole.Console/Services/ConsoleGrpcServiceV1.cs index bdb786f4..6abdc8ac 100644 --- a/src/console/LibplanetConsole.Console/Services/ConsoleGrpcServiceV1.cs +++ b/src/console/LibplanetConsole.Console/Services/ConsoleGrpcServiceV1.cs @@ -1,7 +1,8 @@ using Grpc.Core; using LibplanetConsole.Common; +using LibplanetConsole.Console.Grpc; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.Console; +using LibplanetConsole.Node; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; @@ -22,7 +23,7 @@ public override Task GetNodeSettings( var genesis = BlockUtility.SerializeBlock(options.GenesisBlock); return Task.FromResult(new GetNodeSettingsResponse { - AppProtocolVersion = options.AppProtocolVersion.Token, + AppProtocolVersion = options.AppProtocolVersion, Genesis = TypeUtility.ToGrpc(genesis), ProcessId = Environment.ProcessId, SeedEndPoint = EndPointUtility.ToString(GetSeedEndPoint()), diff --git a/src/node/LibplanetConsole.Node.Bank/Bank.cs b/src/node/LibplanetConsole.Node.Bank/Bank.cs index 17987308..3684ae5c 100644 --- a/src/node/LibplanetConsole.Node.Bank/Bank.cs +++ b/src/node/LibplanetConsole.Node.Bank/Bank.cs @@ -1,5 +1,6 @@ using Libplanet.Action.State; using LibplanetConsole.Bank.Actions; +using LibplanetConsole.BlockChain; namespace LibplanetConsole.Node.Bank; diff --git a/src/node/LibplanetConsole.Node.Bank/Commands/BankCommand.cs b/src/node/LibplanetConsole.Node.Bank/Commands/BankCommand.cs index 9afe217c..9d5bc23c 100644 --- a/src/node/LibplanetConsole.Node.Bank/Commands/BankCommand.cs +++ b/src/node/LibplanetConsole.Node.Bank/Commands/BankCommand.cs @@ -1,6 +1,8 @@ using System.ComponentModel; using JSSoft.Commands; +using LibplanetConsole.Bank; using LibplanetConsole.Bank.DataAnnotations; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Node.Bank.Commands; diff --git a/src/node/LibplanetConsole.Node.Bank/CurrencyCollection.cs b/src/node/LibplanetConsole.Node.Bank/CurrencyCollection.cs index 54044bbf..e8ecebb8 100644 --- a/src/node/LibplanetConsole.Node.Bank/CurrencyCollection.cs +++ b/src/node/LibplanetConsole.Node.Bank/CurrencyCollection.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.Bank; + namespace LibplanetConsole.Node.Bank; internal sealed class CurrencyCollection(IServiceProvider serviceProvider) diff --git a/src/node/LibplanetConsole.Node.Bank/ICurrencyProvider.cs b/src/node/LibplanetConsole.Node.Bank/ICurrencyProvider.cs index f85d76fb..c78189cc 100644 --- a/src/node/LibplanetConsole.Node.Bank/ICurrencyProvider.cs +++ b/src/node/LibplanetConsole.Node.Bank/ICurrencyProvider.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.Bank; + namespace LibplanetConsole.Node.Bank; public interface ICurrencyProvider diff --git a/src/node/LibplanetConsole.Node.Bank/ServiceCollectionExtensions.cs b/src/node/LibplanetConsole.Node.Bank/ServiceCollectionExtensions.cs index c2407b23..abba4881 100644 --- a/src/node/LibplanetConsole.Node.Bank/ServiceCollectionExtensions.cs +++ b/src/node/LibplanetConsole.Node.Bank/ServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.Bank; using LibplanetConsole.Node.Bank.Commands; namespace LibplanetConsole.Node.Bank; diff --git a/src/node/LibplanetConsole.Node.Bank/Services/BankServiceGrpcV1.cs b/src/node/LibplanetConsole.Node.Bank/Services/BankServiceGrpcV1.cs index 72c549ca..2e26159f 100644 --- a/src/node/LibplanetConsole.Node.Bank/Services/BankServiceGrpcV1.cs +++ b/src/node/LibplanetConsole.Node.Bank/Services/BankServiceGrpcV1.cs @@ -1,5 +1,6 @@ using Grpc.Core; -using LibplanetConsole.Grpc.Bank; +using LibplanetConsole.Bank; +using LibplanetConsole.Bank.Grpc; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Node.Bank.Services; diff --git a/src/node/LibplanetConsole.Node.Evidence/Evidence.cs b/src/node/LibplanetConsole.Node.Evidence/Evidence.cs index 041f2886..308781f9 100644 --- a/src/node/LibplanetConsole.Node.Evidence/Evidence.cs +++ b/src/node/LibplanetConsole.Node.Evidence/Evidence.cs @@ -1,5 +1,5 @@ -using Libplanet.Blockchain; using Libplanet.Types.Evidence; +using LibplanetConsole.Evidence; namespace LibplanetConsole.Node.Evidence; @@ -10,7 +10,7 @@ internal sealed class Evidence(INode node) public Task AddEvidenceAsync(CancellationToken cancellationToken) { - var blockChain = node.GetRequiredService(); + var blockChain = node.GetRequiredService(); var height = blockChain.Tip.Index; var validatorAddress = node.Address; var evidence = new TestEvidence(height, validatorAddress, DateTimeOffset.UtcNow); @@ -21,7 +21,7 @@ public Task AddEvidenceAsync(CancellationToken cancellationToken) public async Task GetEvidenceAsync( long height, CancellationToken cancellationToken) { - var blockChain = node.GetRequiredService(); + var blockChain = node.GetRequiredService(); var block = height == -1 ? blockChain.Tip : blockChain[height]; var evidences = block.Evidence.Select(item => new EvidenceInfo() { @@ -38,7 +38,7 @@ public async Task GetEvidenceAsync( public async Task GetEvidenceAsync( EvidenceId evidenceId, CancellationToken cancellationToken) { - var blockChain = node.GetRequiredService(); + var blockChain = node.GetRequiredService(); if (blockChain.GetCommittedEvidence(evidenceId) is { } evidence) { await Task.CompletedTask; @@ -52,7 +52,7 @@ public async Task GetEvidenceAsync( public async Task GetPendingEvidenceAsync(CancellationToken cancellationToken) { - var blockChain = node.GetRequiredService(); + var blockChain = node.GetRequiredService(); var evidences = blockChain.GetPendingEvidence().Select(item => (EvidenceInfo)item); await Task.CompletedTask; return [.. evidences]; @@ -61,7 +61,7 @@ public async Task GetPendingEvidenceAsync(CancellationToken canc public async Task GetPendingEvidenceAsync( EvidenceId evidenceId, CancellationToken cancellationToken) { - var blockChain = node.GetRequiredService(); + var blockChain = node.GetRequiredService(); if (blockChain.GetPendingEvidence(evidenceId) is { } evidence) { await Task.CompletedTask; diff --git a/src/node/LibplanetConsole.Node.Evidence/IEvidence.cs b/src/node/LibplanetConsole.Node.Evidence/IEvidence.cs index aea671b3..18285894 100644 --- a/src/node/LibplanetConsole.Node.Evidence/IEvidence.cs +++ b/src/node/LibplanetConsole.Node.Evidence/IEvidence.cs @@ -1,4 +1,5 @@ using Libplanet.Types.Evidence; +using LibplanetConsole.Evidence; namespace LibplanetConsole.Node.Evidence; diff --git a/src/node/LibplanetConsole.Node.Evidence/Services/EvidenceServiceGrpcV1.cs b/src/node/LibplanetConsole.Node.Evidence/Services/EvidenceServiceGrpcV1.cs index 79c01302..dd095bee 100644 --- a/src/node/LibplanetConsole.Node.Evidence/Services/EvidenceServiceGrpcV1.cs +++ b/src/node/LibplanetConsole.Node.Evidence/Services/EvidenceServiceGrpcV1.cs @@ -1,5 +1,6 @@ using Grpc.Core; -using LibplanetConsole.Grpc.Evidence; +using LibplanetConsole.Evidence; +using LibplanetConsole.Evidence.Grpc; using static LibplanetConsole.Grpc.TypeUtility; namespace LibplanetConsole.Node.Evidence.Services; diff --git a/src/node/LibplanetConsole.Node.Executable/AddressProvider.cs b/src/node/LibplanetConsole.Node.Executable/AddressProvider.cs index beb4699f..4e83c620 100644 --- a/src/node/LibplanetConsole.Node.Executable/AddressProvider.cs +++ b/src/node/LibplanetConsole.Node.Executable/AddressProvider.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.BlockChain; + namespace LibplanetConsole.Node.Executable; internal sealed class AddressProvider(IApplicationOptions options) : IAddressProvider diff --git a/src/node/LibplanetConsole.Node.Executable/Application.cs b/src/node/LibplanetConsole.Node.Executable/Application.cs index 92dfde67..e69b8409 100644 --- a/src/node/LibplanetConsole.Node.Executable/Application.cs +++ b/src/node/LibplanetConsole.Node.Executable/Application.cs @@ -94,7 +94,7 @@ public async Task RunAsync(CancellationToken cancellationToken) app.MapGet("/", () => "Libplanet-Node"); app.MapGrpcReflectionService().AllowAnonymous(); - await Console.Out.WriteLineAsync(); + await System.Console.Out.WriteLineAsync(); await app.RunAsync(cancellationToken); } } diff --git a/src/node/LibplanetConsole.Node.Executable/ConsoleConfigureOptions.cs b/src/node/LibplanetConsole.Node.Executable/ConsoleConfigureOptions.cs index 19cfa831..c51b2e10 100644 --- a/src/node/LibplanetConsole.Node.Executable/ConsoleConfigureOptions.cs +++ b/src/node/LibplanetConsole.Node.Executable/ConsoleConfigureOptions.cs @@ -1,7 +1,7 @@ using Google.Protobuf; +using LibplanetConsole.Console.Grpc; +using LibplanetConsole.Console.Services; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.Console; -using LibplanetConsole.Node.Services; using Microsoft.Extensions.Options; namespace LibplanetConsole.Node.Executable; diff --git a/src/node/LibplanetConsole.Node.Executable/ConsoleHostedService.cs b/src/node/LibplanetConsole.Node.Executable/ConsoleHostedService.cs index 9025375a..a235aa05 100644 --- a/src/node/LibplanetConsole.Node.Executable/ConsoleHostedService.cs +++ b/src/node/LibplanetConsole.Node.Executable/ConsoleHostedService.cs @@ -1,7 +1,7 @@ using LibplanetConsole.Common; +using LibplanetConsole.Console.Grpc; +using LibplanetConsole.Console.Services; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.Console; -using LibplanetConsole.Node.Services; namespace LibplanetConsole.Node.Executable; diff --git a/src/node/LibplanetConsole.Node.Executable/CurrencyProvider.cs b/src/node/LibplanetConsole.Node.Executable/CurrencyProvider.cs index 1b367065..4ec519cb 100644 --- a/src/node/LibplanetConsole.Node.Executable/CurrencyProvider.cs +++ b/src/node/LibplanetConsole.Node.Executable/CurrencyProvider.cs @@ -1,3 +1,4 @@ +using LibplanetConsole.Bank; using LibplanetConsole.Node.Bank; namespace LibplanetConsole.Node.Executable; diff --git a/src/node/LibplanetConsole.Node.Executable/EntryCommands/RunCommand.cs b/src/node/LibplanetConsole.Node.Executable/EntryCommands/RunCommand.cs index da845b1d..e31c92d3 100644 --- a/src/node/LibplanetConsole.Node.Executable/EntryCommands/RunCommand.cs +++ b/src/node/LibplanetConsole.Node.Executable/EntryCommands/RunCommand.cs @@ -164,7 +164,7 @@ protected override async Task OnExecuteAsync(CancellationToken cancellationToken } catch (CommandParsingException e) { - e.Print(Console.Out); + e.Print(System.Console.Out); Environment.Exit(1); } } diff --git a/src/node/LibplanetConsole.Node.Executable/EntryCommands/StartCommand.cs b/src/node/LibplanetConsole.Node.Executable/EntryCommands/StartCommand.cs index 91f6ce78..dbcdcfcc 100644 --- a/src/node/LibplanetConsole.Node.Executable/EntryCommands/StartCommand.cs +++ b/src/node/LibplanetConsole.Node.Executable/EntryCommands/StartCommand.cs @@ -53,7 +53,7 @@ protected override async Task OnExecuteAsync(CancellationToken cancellationToken } catch (CommandParsingException e) { - e.Print(Console.Out); + e.Print(System.Console.Out); Environment.Exit(1); } } diff --git a/src/node/LibplanetConsole.Node.Executable/SystemTerminal.cs b/src/node/LibplanetConsole.Node.Executable/SystemTerminal.cs index d8bb74a9..9e466981 100644 --- a/src/node/LibplanetConsole.Node.Executable/SystemTerminal.cs +++ b/src/node/LibplanetConsole.Node.Executable/SystemTerminal.cs @@ -1,6 +1,7 @@ using System.Text; using JSSoft.Commands.Extensions; using JSSoft.Terminals; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Node.Executable; diff --git a/src/node/LibplanetConsole.Node.Executable/SystemTerminalHostedService.cs b/src/node/LibplanetConsole.Node.Executable/SystemTerminalHostedService.cs index 017eedce..201412a1 100644 --- a/src/node/LibplanetConsole.Node.Executable/SystemTerminalHostedService.cs +++ b/src/node/LibplanetConsole.Node.Executable/SystemTerminalHostedService.cs @@ -31,8 +31,8 @@ public async Task StartAsync(CancellationToken cancellationToken) await sw.WriteLineAsync(); await commandContext.ExecuteAsync(args: [], cancellationToken); await sw.WriteSeparatorAsync(TerminalColorType.BrightGreen); - commandContext.Out = Console.Out; - await Console.Out.WriteAsync(sw.ToString()); + commandContext.Out = System.Console.Out; + await System.Console.Out.WriteAsync(sw.ToString()); await terminal.StartAsync(cancellationToken); _terminal = terminal; @@ -64,9 +64,10 @@ public async Task StopAsync(CancellationToken cancellationToken) private async Task WaitInputAsync() { using var cancellationTokenSource = new CancellationTokenSource(); + var cancellationToken = cancellationTokenSource.Token; applicationLifetime.ApplicationStopping.Register(cancellationTokenSource.Cancel); - await Console.Out.WriteLineAsync("Press any key to exit."); - await Task.Run(() => Console.ReadKey(intercept: true), cancellationTokenSource.Token); + await System.Console.Out.WriteLineAsync("Press any key to exit."); + await Task.Run(() => System.Console.ReadKey(intercept: true), cancellationToken); applicationLifetime.StopApplication(); } diff --git a/src/node/LibplanetConsole.Node.Executable/Tracers/BlockChainEventTracer.cs b/src/node/LibplanetConsole.Node.Executable/Tracers/BlockChainEventTracer.cs index 3e780abe..12c786af 100644 --- a/src/node/LibplanetConsole.Node.Executable/Tracers/BlockChainEventTracer.cs +++ b/src/node/LibplanetConsole.Node.Executable/Tracers/BlockChainEventTracer.cs @@ -1,3 +1,4 @@ +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Extensions; namespace LibplanetConsole.Node.Executable.Tracers; diff --git a/src/node/LibplanetConsole.Node.Executable/Tracers/NodeEventTracer.cs b/src/node/LibplanetConsole.Node.Executable/Tracers/NodeEventTracer.cs index 2b0eb0a7..be75b1d1 100644 --- a/src/node/LibplanetConsole.Node.Executable/Tracers/NodeEventTracer.cs +++ b/src/node/LibplanetConsole.Node.Executable/Tracers/NodeEventTracer.cs @@ -29,12 +29,12 @@ void IDisposable.Dispose() private void Node_Started(object? sender, EventArgs e) { var message = $"Node has been started."; - Console.Out.WriteColoredLine(message, TerminalColorType.BrightGreen); + System.Console.Out.WriteColoredLine(message, TerminalColorType.BrightGreen); } private void Node_Stopped(object? sender, EventArgs e) { var message = $"Node has been stopped."; - Console.Out.WriteColoredLine(message, TerminalColorType.BrightGreen); + System.Console.Out.WriteColoredLine(message, TerminalColorType.BrightGreen); } } diff --git a/src/node/LibplanetConsole.Node.Explorer/BlockChainContext.cs b/src/node/LibplanetConsole.Node.Explorer/BlockChainContext.cs index feb793c1..25821978 100644 --- a/src/node/LibplanetConsole.Node.Explorer/BlockChainContext.cs +++ b/src/node/LibplanetConsole.Node.Explorer/BlockChainContext.cs @@ -1,5 +1,4 @@ using System.Reflection; -using Libplanet.Blockchain; using Libplanet.Explorer.Indexing; using Libplanet.Explorer.Interfaces; using Libplanet.Net; @@ -11,7 +10,8 @@ internal sealed class BlockChainContext(INode node) : IBlockChainContext { public bool Preloaded => false; - public BlockChain BlockChain => node.GetRequiredService(); + public Libplanet.Blockchain.BlockChain BlockChain + => node.GetRequiredService(); #pragma warning disable S3011 // Reflection should not be used to increase accessibility ... public IStore Store @@ -19,7 +19,8 @@ public IStore Store get { var bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; - var propertyInfo = typeof(BlockChain).GetProperty("Store", bindingFlags) ?? + var blockChainType = typeof(Libplanet.Blockchain.BlockChain); + var propertyInfo = blockChainType.GetProperty("Store", bindingFlags) ?? throw new InvalidOperationException("Store property not found."); if (propertyInfo.GetValue(BlockChain) is IStore store) { diff --git a/src/node/LibplanetConsole.Node/AddressCollection.cs b/src/node/LibplanetConsole.Node/AddressCollection.cs index 87404b43..2524bc7d 100644 --- a/src/node/LibplanetConsole.Node/AddressCollection.cs +++ b/src/node/LibplanetConsole.Node/AddressCollection.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.BlockChain; + namespace LibplanetConsole.Node; internal sealed class AddressCollection(IEnumerable addressProviders) diff --git a/src/node/LibplanetConsole.Node/ApplicationOptions.cs b/src/node/LibplanetConsole.Node/ApplicationOptions.cs index 27ee047c..e668df55 100644 --- a/src/node/LibplanetConsole.Node/ApplicationOptions.cs +++ b/src/node/LibplanetConsole.Node/ApplicationOptions.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Libplanet.Net; using LibplanetConsole.Common; using LibplanetConsole.Common.DataAnnotations; using LibplanetConsole.Options; diff --git a/src/node/LibplanetConsole.Node/BlockChainUtility.cs b/src/node/LibplanetConsole.Node/BlockChainUtility.cs index 44bfc644..73824e8d 100644 --- a/src/node/LibplanetConsole.Node/BlockChainUtility.cs +++ b/src/node/LibplanetConsole.Node/BlockChainUtility.cs @@ -4,13 +4,12 @@ using Libplanet.RocksDBStore; using Libplanet.Store; using Libplanet.Store.Trie; -using BlockChain = Libplanet.Blockchain.BlockChain; namespace LibplanetConsole.Node; internal static class BlockChainUtility { - public static BlockChain CreateBlockChain( + public static Libplanet.Blockchain.BlockChain CreateBlockChain( Block genesisBlock, IStore store, IStateStore stateStore, @@ -36,7 +35,7 @@ public static BlockChain CreateBlockChain( var renderers = new IRenderer[] { renderer }; if (store.GetCanonicalChainId() is null) { - return BlockChain.Create( + return Libplanet.Blockchain.BlockChain.Create( policy: policy, stagePolicy: stagePolicy, store: store, @@ -47,7 +46,7 @@ public static BlockChain CreateBlockChain( blockChainStates: blockChainStates); } - return new BlockChain( + return new Libplanet.Blockchain.BlockChain( policy: policy, stagePolicy: stagePolicy, store: store, diff --git a/src/node/LibplanetConsole.Node/Commands/NonceCommand.cs b/src/node/LibplanetConsole.Node/Commands/NonceCommand.cs index 258da674..2ce018ee 100644 --- a/src/node/LibplanetConsole.Node/Commands/NonceCommand.cs +++ b/src/node/LibplanetConsole.Node/Commands/NonceCommand.cs @@ -1,4 +1,5 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; namespace LibplanetConsole.Node.Commands; diff --git a/src/node/LibplanetConsole.Node/IAddressProvider.cs b/src/node/LibplanetConsole.Node/IAddressProvider.cs index 748e9940..312f56b5 100644 --- a/src/node/LibplanetConsole.Node/IAddressProvider.cs +++ b/src/node/LibplanetConsole.Node/IAddressProvider.cs @@ -1,3 +1,5 @@ +using LibplanetConsole.BlockChain; + namespace LibplanetConsole.Node; public interface IAddressProvider diff --git a/src/node/LibplanetConsole.Node/IApplicationOptions.cs b/src/node/LibplanetConsole.Node/IApplicationOptions.cs index 9ffdeaa6..029febfe 100644 --- a/src/node/LibplanetConsole.Node/IApplicationOptions.cs +++ b/src/node/LibplanetConsole.Node/IApplicationOptions.cs @@ -1,5 +1,3 @@ -using Libplanet.Net; - namespace LibplanetConsole.Node; public interface IApplicationOptions diff --git a/src/node/LibplanetConsole.Node/LibplanetConsole.Node.csproj b/src/node/LibplanetConsole.Node/LibplanetConsole.Node.csproj index 87ca6b8d..7e2309bf 100644 --- a/src/node/LibplanetConsole.Node/LibplanetConsole.Node.csproj +++ b/src/node/LibplanetConsole.Node/LibplanetConsole.Node.csproj @@ -15,7 +15,11 @@ - + + + + + @@ -28,6 +32,7 @@ + @@ -37,6 +42,8 @@ GrpcServices="Server" ProtoRoot="$(ProtoRootDirectory)" /> + diff --git a/src/node/LibplanetConsole.Node/Node.BlockChain.cs b/src/node/LibplanetConsole.Node/Node.BlockChain.cs index 9fa96a0c..a3235b06 100644 --- a/src/node/LibplanetConsole.Node/Node.BlockChain.cs +++ b/src/node/LibplanetConsole.Node/Node.BlockChain.cs @@ -1,6 +1,7 @@ using System.Security.Cryptography; using System.Text; using Libplanet.Action.State; +using LibplanetConsole.BlockChain; using LibplanetConsole.Common.Exceptions; namespace LibplanetConsole.Node; diff --git a/src/node/LibplanetConsole.Node/Node.cs b/src/node/LibplanetConsole.Node/Node.cs index 077c99d0..3961cda0 100644 --- a/src/node/LibplanetConsole.Node/Node.cs +++ b/src/node/LibplanetConsole.Node/Node.cs @@ -1,20 +1,19 @@ using System.Collections.Concurrent; using System.Security.Cryptography; -using Grpc.Net.Client; -using Libplanet.Blockchain; using Libplanet.Blockchain.Renderers; -using Libplanet.Net; using Libplanet.Net.Consensus; using Libplanet.Net.Options; using Libplanet.Net.Transports; using Libplanet.Store; using Libplanet.Store.Trie; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Converters; using LibplanetConsole.Common; using LibplanetConsole.Common.Exceptions; using LibplanetConsole.Common.Extensions; -using LibplanetConsole.Node.Converters; using LibplanetConsole.Node.Extensions; using LibplanetConsole.Seed; +using LibplanetConsole.Seed.Services; namespace LibplanetConsole.Node; @@ -85,7 +84,8 @@ public Node( public Address Address => PublicKey.Address; - public BlockChain BlockChain => _swarm?.BlockChain ?? throw new InvalidOperationException(); + public Libplanet.Blockchain.BlockChain BlockChain + => _swarm?.BlockChain ?? throw new InvalidOperationException(); public NodeInfo Info { get; private set; } = NodeInfo.Empty; @@ -133,7 +133,7 @@ public EndPoint? SeedEndPoint return _swarm; } - if (serviceType == typeof(BlockChain)) + if (serviceType == typeof(Libplanet.Blockchain.BlockChain)) { return BlockChain; } @@ -319,13 +319,9 @@ private static async Task CreateTransport( { logger.LogDebug( "Getting seed info from {SeedEndPoint}", EndPointUtility.ToString(seedEndPoint)); - var address = $"http://{EndPointUtility.ToString(seedEndPoint)}"; - var channelOptions = new GrpcChannelOptions - { - }; - using var channel = GrpcChannel.ForAddress(address, channelOptions); - var client = new Grpc.Seed.SeedGrpcService.SeedGrpcServiceClient(channel); - var request = new Grpc.Seed.GetSeedRequest + using var channel = SeedChannel.CreateChannel(seedEndPoint); + var client = new SeedService(channel); + var request = new Seed.Grpc.GetSeedRequest { PublicKey = new PrivateKey().PublicKey.ToHex(compress: true), }; diff --git a/src/node/LibplanetConsole.Node/ServiceCollectionExtensions.cs b/src/node/LibplanetConsole.Node/ServiceCollectionExtensions.cs index 2a835f93..d651f49c 100644 --- a/src/node/LibplanetConsole.Node/ServiceCollectionExtensions.cs +++ b/src/node/LibplanetConsole.Node/ServiceCollectionExtensions.cs @@ -1,4 +1,6 @@ using JSSoft.Commands; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Commands; using LibplanetConsole.Common; using LibplanetConsole.Node.Commands; using Microsoft.Extensions.Configuration; diff --git a/src/node/LibplanetConsole.Node/Services/BlockChainGrpcServiceV1.cs b/src/node/LibplanetConsole.Node/Services/BlockChainGrpcServiceV1.cs index 80ce6fd9..18a135a0 100644 --- a/src/node/LibplanetConsole.Node/Services/BlockChainGrpcServiceV1.cs +++ b/src/node/LibplanetConsole.Node/Services/BlockChainGrpcServiceV1.cs @@ -1,6 +1,7 @@ using Grpc.Core; +using LibplanetConsole.BlockChain; +using LibplanetConsole.BlockChain.Grpc; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.BlockChain; using Microsoft.Extensions.Hosting; using static LibplanetConsole.Grpc.TypeUtility; diff --git a/src/node/LibplanetConsole.Node/Services/NodeGrpcServiceV1.cs b/src/node/LibplanetConsole.Node/Services/NodeGrpcServiceV1.cs index 7fa7db9f..111500d4 100644 --- a/src/node/LibplanetConsole.Node/Services/NodeGrpcServiceV1.cs +++ b/src/node/LibplanetConsole.Node/Services/NodeGrpcServiceV1.cs @@ -1,7 +1,7 @@ using Grpc.Core; using LibplanetConsole.Common; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.Node; +using LibplanetConsole.Node.Grpc; using Microsoft.Extensions.Hosting; namespace LibplanetConsole.Node.Services; diff --git a/src/shared/LibplanetConsole.Bank/CurrencyCollectionBase.cs b/src/shared/LibplanetConsole.Bank/CurrencyCollectionBase.cs index 0b6a3e92..e7e89ae4 100644 --- a/src/shared/LibplanetConsole.Bank/CurrencyCollectionBase.cs +++ b/src/shared/LibplanetConsole.Bank/CurrencyCollectionBase.cs @@ -7,15 +7,7 @@ using LibplanetConsole.Bank.DataAnnotations; using LibplanetConsole.Common; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node.Bank; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Bank; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console.Bank; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.Bank; internal abstract class CurrencyCollectionBase : ICurrencyCollection { diff --git a/src/shared/LibplanetConsole.Bank/CurrencyInfo.cs b/src/shared/LibplanetConsole.Bank/CurrencyInfo.cs index 2f0c701f..08832766 100644 --- a/src/shared/LibplanetConsole.Bank/CurrencyInfo.cs +++ b/src/shared/LibplanetConsole.Bank/CurrencyInfo.cs @@ -1,15 +1,7 @@ -using LibplanetConsole.Grpc.Bank; +using LibplanetConsole.Bank.Grpc; using static LibplanetConsole.Grpc.TypeUtility; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node.Bank; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Bank; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console.Bank; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.Bank; public readonly partial record struct CurrencyInfo { diff --git a/src/shared/LibplanetConsole.Bank/ICurrencyCollection.cs b/src/shared/LibplanetConsole.Bank/ICurrencyCollection.cs index cc99540a..c088a78c 100644 --- a/src/shared/LibplanetConsole.Bank/ICurrencyCollection.cs +++ b/src/shared/LibplanetConsole.Bank/ICurrencyCollection.cs @@ -1,14 +1,6 @@ using System.Diagnostics.CodeAnalysis; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node.Bank; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Bank; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console.Bank; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.Bank; public interface ICurrencyCollection : IEnumerable { diff --git a/src/shared/LibplanetConsole.Bank/Protos/BankGrpcService.proto b/src/shared/LibplanetConsole.Bank/Protos/BankGrpcService.proto index d073415b..e5989529 100644 --- a/src/shared/LibplanetConsole.Bank/Protos/BankGrpcService.proto +++ b/src/shared/LibplanetConsole.Bank/Protos/BankGrpcService.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option csharp_namespace = "LibplanetConsole.Grpc.Bank"; +option csharp_namespace = "LibplanetConsole.Bank.Grpc"; package libplanet.console.bank.v1; diff --git a/src/shared/LibplanetConsole.BlockChain/AddressCollectionBase.cs b/src/shared/LibplanetConsole.BlockChain/AddressCollectionBase.cs index 9aad3aa8..0c10935a 100644 --- a/src/shared/LibplanetConsole.BlockChain/AddressCollectionBase.cs +++ b/src/shared/LibplanetConsole.BlockChain/AddressCollectionBase.cs @@ -3,15 +3,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.BlockChain; internal abstract class AddressCollectionBase : IAddressCollection { diff --git a/src/shared/LibplanetConsole.BlockChain/AddressInfo.cs b/src/shared/LibplanetConsole.BlockChain/AddressInfo.cs index 5a18f025..6b97ef98 100644 --- a/src/shared/LibplanetConsole.BlockChain/AddressInfo.cs +++ b/src/shared/LibplanetConsole.BlockChain/AddressInfo.cs @@ -1,16 +1,8 @@ using System.Text.Json.Serialization; -using LibplanetConsole.Grpc.BlockChain; +using LibplanetConsole.BlockChain.Grpc; using static LibplanetConsole.Grpc.TypeUtility; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.BlockChain; public readonly partial record struct AddressInfo { diff --git a/src/shared/LibplanetConsole.BlockChain/BlockEventArgs.cs b/src/shared/LibplanetConsole.BlockChain/BlockEventArgs.cs index 6b3a743b..d11a35ba 100644 --- a/src/shared/LibplanetConsole.BlockChain/BlockEventArgs.cs +++ b/src/shared/LibplanetConsole.BlockChain/BlockEventArgs.cs @@ -1,12 +1,4 @@ -#if LIBPLANET_NODE -namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.BlockChain; public sealed class BlockEventArgs(BlockInfo blockInfo) : EventArgs { diff --git a/src/shared/LibplanetConsole.BlockChain/BlockInfo.Node.cs b/src/shared/LibplanetConsole.BlockChain/BlockInfo.Node.cs index 9f23d1f4..a9c7cbba 100644 --- a/src/shared/LibplanetConsole.BlockChain/BlockInfo.Node.cs +++ b/src/shared/LibplanetConsole.BlockChain/BlockInfo.Node.cs @@ -1,5 +1,5 @@ #if LIBPLANET_NODE -namespace LibplanetConsole.Node; +namespace LibplanetConsole.BlockChain; public readonly partial record struct BlockInfo { diff --git a/src/shared/LibplanetConsole.BlockChain/BlockInfo.cs b/src/shared/LibplanetConsole.BlockChain/BlockInfo.cs index c11ea19e..f94e69b6 100644 --- a/src/shared/LibplanetConsole.BlockChain/BlockInfo.cs +++ b/src/shared/LibplanetConsole.BlockChain/BlockInfo.cs @@ -1,15 +1,7 @@ -using LibplanetConsole.Grpc.BlockChain; +using LibplanetConsole.BlockChain.Grpc; using static LibplanetConsole.Grpc.TypeUtility; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.BlockChain; public readonly partial record struct BlockInfo(long Height, BlockHash Hash, Address Miner) { diff --git a/src/shared/LibplanetConsole.BlockChain/Commands/AddressCommand.cs b/src/shared/LibplanetConsole.BlockChain/Commands/AddressCommand.cs index 1c1dfad5..878e45a1 100644 --- a/src/shared/LibplanetConsole.BlockChain/Commands/AddressCommand.cs +++ b/src/shared/LibplanetConsole.BlockChain/Commands/AddressCommand.cs @@ -2,15 +2,7 @@ using JSSoft.Commands.Extensions; using LibplanetConsole.Common.Extensions; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node.Commands; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Commands; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console.Commands; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.BlockChain.Commands; [CommandSummary("Prints the address of the node")] internal sealed class AddressCommand(IAddressCollection addresses) : CommandBase diff --git a/src/shared/LibplanetConsole.BlockChain/Converters/AddressTypeConverter.cs b/src/shared/LibplanetConsole.BlockChain/Converters/AddressTypeConverter.cs index 7d9ce6ea..2e74445d 100644 --- a/src/shared/LibplanetConsole.BlockChain/Converters/AddressTypeConverter.cs +++ b/src/shared/LibplanetConsole.BlockChain/Converters/AddressTypeConverter.cs @@ -1,15 +1,7 @@ using System.ComponentModel; using System.Globalization; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node.Converters; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Converters; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console.Converters; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.BlockChain.Converters; internal sealed class AddressTypeConverter : TypeConverter { diff --git a/src/shared/LibplanetConsole.BlockChain/IAddressCollection.cs b/src/shared/LibplanetConsole.BlockChain/IAddressCollection.cs index d3b8c5be..75cd4560 100644 --- a/src/shared/LibplanetConsole.BlockChain/IAddressCollection.cs +++ b/src/shared/LibplanetConsole.BlockChain/IAddressCollection.cs @@ -2,15 +2,7 @@ using System.Text.RegularExpressions; using LibplanetConsole.Common.DataAnnotations; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.BlockChain; public interface IAddressCollection : IEnumerable
{ diff --git a/src/shared/LibplanetConsole.BlockChain/IBlockChain.cs b/src/shared/LibplanetConsole.BlockChain/IBlockChain.cs index 5bea0192..032854d5 100644 --- a/src/shared/LibplanetConsole.BlockChain/IBlockChain.cs +++ b/src/shared/LibplanetConsole.BlockChain/IBlockChain.cs @@ -1,14 +1,6 @@ using System.Security.Cryptography; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif +namespace LibplanetConsole.BlockChain; public interface IBlockChain { diff --git a/src/shared/LibplanetConsole.BlockChain/Protos/BlockChainGrpcService.proto b/src/shared/LibplanetConsole.BlockChain/Protos/BlockChainGrpcService.proto index f35d9a3d..8994f8e0 100644 --- a/src/shared/LibplanetConsole.BlockChain/Protos/BlockChainGrpcService.proto +++ b/src/shared/LibplanetConsole.BlockChain/Protos/BlockChainGrpcService.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option csharp_namespace = "LibplanetConsole.Grpc.BlockChain"; +option csharp_namespace = "LibplanetConsole.BlockChain.Grpc"; package libplanet.console.blockchain.v1; diff --git a/src/shared/LibplanetConsole.BlockChain/Services/BlockChainService.cs b/src/shared/LibplanetConsole.BlockChain/Services/BlockChainService.cs index 36f2c200..d57d68b1 100644 --- a/src/shared/LibplanetConsole.BlockChain/Services/BlockChainService.cs +++ b/src/shared/LibplanetConsole.BlockChain/Services/BlockChainService.cs @@ -1,14 +1,10 @@ #if LIBPLANET_CLIENT || LIBPLANET_CONSOLE using Grpc.Net.Client; +using LibplanetConsole.BlockChain.Grpc; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.BlockChain; -using static LibplanetConsole.Grpc.BlockChain.BlockChainGrpcService; - -#if LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Services; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console.Services; -#endif +using static LibplanetConsole.BlockChain.Grpc.BlockChainGrpcService; + +namespace LibplanetConsole.BlockChain.Services; internal sealed class BlockChainService(GrpcChannel channel) : BlockChainGrpcServiceClient(channel), IDisposable diff --git a/src/shared/LibplanetConsole.Client/ClientEventArgs.cs b/src/shared/LibplanetConsole.Client/ClientEventArgs.cs index 8c4c5748..81d659ef 100644 --- a/src/shared/LibplanetConsole.Client/ClientEventArgs.cs +++ b/src/shared/LibplanetConsole.Client/ClientEventArgs.cs @@ -1,11 +1,5 @@ #if LIBPLANET_CLIENT || LIBPLANET_CONSOLE -#if LIBPLANET_CLIENT namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif public sealed class ClientEventArgs(ClientInfo clientInfo) : EventArgs { diff --git a/src/shared/LibplanetConsole.Client/ClientInfo.cs b/src/shared/LibplanetConsole.Client/ClientInfo.cs index 6bbf1d94..a23c4112 100644 --- a/src/shared/LibplanetConsole.Client/ClientInfo.cs +++ b/src/shared/LibplanetConsole.Client/ClientInfo.cs @@ -1,14 +1,8 @@ #if LIBPLANET_CLIENT || LIBPLANET_CONSOLE -using LibplanetConsole.Grpc.Client; +using LibplanetConsole.Client.Grpc; using static LibplanetConsole.Grpc.TypeUtility; -#if LIBPLANET_CLIENT namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif public readonly record struct ClientInfo { diff --git a/src/shared/LibplanetConsole.Client/Protos/ClientGrpcService.proto b/src/shared/LibplanetConsole.Client/Protos/ClientGrpcService.proto index b1913ff0..ddb49c23 100644 --- a/src/shared/LibplanetConsole.Client/Protos/ClientGrpcService.proto +++ b/src/shared/LibplanetConsole.Client/Protos/ClientGrpcService.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option csharp_namespace = "LibplanetConsole.Grpc.Client"; +option csharp_namespace = "LibplanetConsole.Client.Grpc"; package libplanet.console.client.v1; diff --git a/src/shared/LibplanetConsole.Client/Services/ClientService.cs b/src/shared/LibplanetConsole.Client/Services/ClientService.cs index 687d34f5..bb1e0a1c 100644 --- a/src/shared/LibplanetConsole.Client/Services/ClientService.cs +++ b/src/shared/LibplanetConsole.Client/Services/ClientService.cs @@ -1,12 +1,12 @@ #if LIBPLANET_CONSOLE using Grpc.Core; using Grpc.Net.Client; +using LibplanetConsole.Client.Grpc; using LibplanetConsole.Console; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.Client; -using static LibplanetConsole.Grpc.Client.ClientGrpcService; +using static LibplanetConsole.Client.Grpc.ClientGrpcService; -namespace LibplanetConsole.Console.Services; +namespace LibplanetConsole.Client.Services; internal sealed class ClientService : ClientGrpcServiceClient, IDisposable { diff --git a/src/shared/LibplanetConsole.Console/Protos/ConsoleGrpcService.proto b/src/shared/LibplanetConsole.Console/Protos/ConsoleGrpcService.proto index 21b1a7a0..65a306b4 100644 --- a/src/shared/LibplanetConsole.Console/Protos/ConsoleGrpcService.proto +++ b/src/shared/LibplanetConsole.Console/Protos/ConsoleGrpcService.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option csharp_namespace = "LibplanetConsole.Grpc.Console"; +option csharp_namespace = "LibplanetConsole.Console.Grpc"; package libplanet.console.console.v1; diff --git a/src/shared/LibplanetConsole.Console/Services/ConsoleChannel.cs b/src/shared/LibplanetConsole.Console/Services/ConsoleChannel.cs index 210a9b56..bb37d303 100644 --- a/src/shared/LibplanetConsole.Console/Services/ConsoleChannel.cs +++ b/src/shared/LibplanetConsole.Console/Services/ConsoleChannel.cs @@ -4,11 +4,7 @@ using Grpc.Net.Client.Configuration; using LibplanetConsole.Common; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node.Services; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Services; -#endif +namespace LibplanetConsole.Console.Services; internal static class ConsoleChannel { diff --git a/src/shared/LibplanetConsole.Console/Services/ConsoleService.cs b/src/shared/LibplanetConsole.Console/Services/ConsoleService.cs index 012adae7..f96c922b 100644 --- a/src/shared/LibplanetConsole.Console/Services/ConsoleService.cs +++ b/src/shared/LibplanetConsole.Console/Services/ConsoleService.cs @@ -1,12 +1,8 @@ #if LIBPLANET_NODE || LIBPLANET_CLIENT using Grpc.Net.Client; -using static LibplanetConsole.Grpc.Console.ConsoleGrpcService; +using static LibplanetConsole.Console.Grpc.ConsoleGrpcService; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node.Services; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Services; -#endif +namespace LibplanetConsole.Console.Services; internal sealed class ConsoleService(GrpcChannel channel) : ConsoleGrpcServiceClient(channel) diff --git a/src/shared/LibplanetConsole.Evidence/EvidenceInfo.cs b/src/shared/LibplanetConsole.Evidence/EvidenceInfo.cs index 15117787..3126db8d 100644 --- a/src/shared/LibplanetConsole.Evidence/EvidenceInfo.cs +++ b/src/shared/LibplanetConsole.Evidence/EvidenceInfo.cs @@ -1,12 +1,8 @@ #if LIBPLANET_NODE || LIBPLANET_CONSOLE using Libplanet.Types.Evidence; -using LibplanetConsole.Grpc.Evidence; +using LibplanetConsole.Evidence.Grpc; -#if LIBPLANET_NODE -namespace LibplanetConsole.Node.Evidence; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console.Evidence; -#endif +namespace LibplanetConsole.Evidence; public readonly record struct EvidenceInfo { diff --git a/src/shared/LibplanetConsole.Evidence/Protos/EvidenceGrpcService.proto b/src/shared/LibplanetConsole.Evidence/Protos/EvidenceGrpcService.proto index 085a6769..fd68dd87 100644 --- a/src/shared/LibplanetConsole.Evidence/Protos/EvidenceGrpcService.proto +++ b/src/shared/LibplanetConsole.Evidence/Protos/EvidenceGrpcService.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option csharp_namespace = "LibplanetConsole.Grpc.Evidence"; +option csharp_namespace = "LibplanetConsole.Evidence.Grpc"; package libplanet.console.evidence.v1; diff --git a/src/shared/LibplanetConsole.Node/BlockUtility.cs b/src/shared/LibplanetConsole.Node/BlockUtility.cs index 12e4f7a8..2eb80919 100644 --- a/src/shared/LibplanetConsole.Node/BlockUtility.cs +++ b/src/shared/LibplanetConsole.Node/BlockUtility.cs @@ -1,12 +1,4 @@ -#if LIBPLANET_NODE namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif public static partial class BlockUtility { diff --git a/src/shared/LibplanetConsole.Node/GenesisOptions.cs b/src/shared/LibplanetConsole.Node/GenesisOptions.cs index c55fd40e..94465ce6 100644 --- a/src/shared/LibplanetConsole.Node/GenesisOptions.cs +++ b/src/shared/LibplanetConsole.Node/GenesisOptions.cs @@ -1,12 +1,4 @@ -#if LIBPLANET_NODE namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif public sealed record class GenesisOptions { diff --git a/src/shared/LibplanetConsole.Node/NodeEventArgs.cs b/src/shared/LibplanetConsole.Node/NodeEventArgs.cs index 671d8142..4da4cc32 100644 --- a/src/shared/LibplanetConsole.Node/NodeEventArgs.cs +++ b/src/shared/LibplanetConsole.Node/NodeEventArgs.cs @@ -1,12 +1,4 @@ -#if LIBPLANET_NODE namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif public sealed class NodeEventArgs(NodeInfo nodeInfo) : EventArgs { diff --git a/src/shared/LibplanetConsole.Node/NodeInfo.cs b/src/shared/LibplanetConsole.Node/NodeInfo.cs index 62defc22..d6503ad4 100644 --- a/src/shared/LibplanetConsole.Node/NodeInfo.cs +++ b/src/shared/LibplanetConsole.Node/NodeInfo.cs @@ -1,15 +1,8 @@ -using LibplanetConsole.Grpc.Node; +using LibplanetConsole.BlockChain; +using LibplanetConsole.Node.Grpc; using static LibplanetConsole.Grpc.TypeUtility; -#if LIBPLANET_NODE namespace LibplanetConsole.Node; -#elif LIBPLANET_CLIENT -namespace LibplanetConsole.Client; -#elif LIBPLANET_CONSOLE -namespace LibplanetConsole.Console; -#else -#error LIBPLANET_NODE, LIBPLANET_CLIENT, or LIBPLANET_CONSOLE must be defined. -#endif public readonly record struct NodeInfo { diff --git a/src/shared/LibplanetConsole.Node/Protos/NodeGrpcService.proto b/src/shared/LibplanetConsole.Node/Protos/NodeGrpcService.proto index ac48d305..36e8ad64 100644 --- a/src/shared/LibplanetConsole.Node/Protos/NodeGrpcService.proto +++ b/src/shared/LibplanetConsole.Node/Protos/NodeGrpcService.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option csharp_namespace = "LibplanetConsole.Grpc.Node"; +option csharp_namespace = "LibplanetConsole.Node.Grpc"; package libplanet.console.node.v1; import "src/shared/LibplanetConsole.BlockChain/Protos/BlockChainGrpcService.proto"; diff --git a/src/shared/LibplanetConsole.Node/Services/NodeChannel.cs b/src/shared/LibplanetConsole.Node/Services/NodeChannel.cs index fdafea10..99236d35 100644 --- a/src/shared/LibplanetConsole.Node/Services/NodeChannel.cs +++ b/src/shared/LibplanetConsole.Node/Services/NodeChannel.cs @@ -3,13 +3,9 @@ using Grpc.Net.Client; using Grpc.Net.Client.Configuration; using LibplanetConsole.Common; -using static LibplanetConsole.Grpc.Node.NodeGrpcService; +using static LibplanetConsole.Node.Grpc.NodeGrpcService; -#if LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Services; -#else -namespace LibplanetConsole.Console.Services; -#endif +namespace LibplanetConsole.Node.Services; internal static class NodeChannel { diff --git a/src/shared/LibplanetConsole.Node/Services/NodeService.cs b/src/shared/LibplanetConsole.Node/Services/NodeService.cs index 088b4121..4b39ec59 100644 --- a/src/shared/LibplanetConsole.Node/Services/NodeService.cs +++ b/src/shared/LibplanetConsole.Node/Services/NodeService.cs @@ -2,14 +2,10 @@ using Grpc.Core; using Grpc.Net.Client; using LibplanetConsole.Grpc; -using LibplanetConsole.Grpc.Node; -using static LibplanetConsole.Grpc.Node.NodeGrpcService; - -#if LIBPLANET_CLIENT -namespace LibplanetConsole.Client.Services; -#else -namespace LibplanetConsole.Console.Services; -#endif +using LibplanetConsole.Node.Grpc; +using static LibplanetConsole.Node.Grpc.NodeGrpcService; + +namespace LibplanetConsole.Node.Services; internal sealed class NodeService : NodeGrpcServiceClient, IDisposable { diff --git a/src/common/LibplanetConsole.Seed/BoundPeerUtility.cs b/src/shared/LibplanetConsole.Seed/BoundPeerUtility.cs similarity index 94% rename from src/common/LibplanetConsole.Seed/BoundPeerUtility.cs rename to src/shared/LibplanetConsole.Seed/BoundPeerUtility.cs index ed84722f..089bc721 100644 --- a/src/common/LibplanetConsole.Seed/BoundPeerUtility.cs +++ b/src/shared/LibplanetConsole.Seed/BoundPeerUtility.cs @@ -1,5 +1,4 @@ -using System.Net; -using LibplanetConsole.Common; +using LibplanetConsole.Common; namespace LibplanetConsole.Seed; diff --git a/src/common/LibplanetConsole.Seed/Converters/BoundPeerJsonConverter.cs b/src/shared/LibplanetConsole.Seed/Converters/BoundPeerJsonConverter.cs similarity index 100% rename from src/common/LibplanetConsole.Seed/Converters/BoundPeerJsonConverter.cs rename to src/shared/LibplanetConsole.Seed/Converters/BoundPeerJsonConverter.cs diff --git a/src/shared/LibplanetConsole.Seed/Protos/SeedGrpcService.proto b/src/shared/LibplanetConsole.Seed/Protos/SeedGrpcService.proto new file mode 100644 index 00000000..8e193d58 --- /dev/null +++ b/src/shared/LibplanetConsole.Seed/Protos/SeedGrpcService.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +option csharp_namespace = "LibplanetConsole.Seed.Grpc"; + +package libplanet.console.seed.v1; + +service SeedGrpcService { + rpc GetSeed(GetSeedRequest) returns (GetSeedResponse); +} + +message SeedInfoProto { + string blocksyncSeedPeer = 1; + string consensusSeedPeer = 2; +} + +message GetSeedRequest { + string publicKey = 1; +} + +message GetSeedResponse { + SeedInfoProto seedResult = 1; +} diff --git a/src/common/LibplanetConsole.Seed/SeedInfo.cs b/src/shared/LibplanetConsole.Seed/SeedInfo.cs similarity index 96% rename from src/common/LibplanetConsole.Seed/SeedInfo.cs rename to src/shared/LibplanetConsole.Seed/SeedInfo.cs index 64b395ba..f9bd299f 100644 --- a/src/common/LibplanetConsole.Seed/SeedInfo.cs +++ b/src/shared/LibplanetConsole.Seed/SeedInfo.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -using LibplanetConsole.Grpc.Seed; using LibplanetConsole.Seed.Converters; +using LibplanetConsole.Seed.Grpc; namespace LibplanetConsole.Seed; diff --git a/src/shared/LibplanetConsole.Seed/Services/SeedChannel.cs b/src/shared/LibplanetConsole.Seed/Services/SeedChannel.cs new file mode 100644 index 00000000..a7673c69 --- /dev/null +++ b/src/shared/LibplanetConsole.Seed/Services/SeedChannel.cs @@ -0,0 +1,67 @@ +#if LIBPLANET_NODE +using Grpc.Core; +using Grpc.Net.Client; +using Grpc.Net.Client.Configuration; +using LibplanetConsole.Common; + +namespace LibplanetConsole.Seed.Services; + +internal static class SeedChannel +{ + private static readonly GrpcChannelOptions _channelOptions = new() + { + ThrowOperationCanceledOnCancellation = true, + MaxRetryAttempts = 10, + MaxReceiveMessageSize = 10 * 1024 * 1024, // 10 MB + ServiceConfig = new() + { + MethodConfigs = + { + new MethodConfig + { + Names = + { + new MethodName + { + Service = "libplanet.console.console.v1.ConsoleGrpcService", + Method = "GetNodeSettings", + }, + new MethodName + { + Service = "libplanet.console.console.v1.ConsoleGrpcService", + Method = "GetClientSettings", + }, + new MethodName + { + Service = "libplanet.console.console.v1.ConsoleGrpcService", + Method = "AttachNode", + }, + new MethodName + { + Service = "libplanet.console.console.v1.ConsoleGrpcService", + Method = "AttachClient", + }, + }, + RetryPolicy = new RetryPolicy + { + MaxAttempts = 5, + InitialBackoff = TimeSpan.FromSeconds(1), + MaxBackoff = TimeSpan.FromSeconds(5), + BackoffMultiplier = 1.5, + RetryableStatusCodes = + { + StatusCode.Unavailable, + }, + }, + }, + }, + }, + }; + + public static GrpcChannel CreateChannel(EndPoint endPoint) + { + var address = $"http://{EndPointUtility.ToString(endPoint)}"; + return GrpcChannel.ForAddress(address, _channelOptions); + } +} +#endif // LIBPLANET_NODE diff --git a/src/shared/LibplanetConsole.Seed/Services/SeedService.cs b/src/shared/LibplanetConsole.Seed/Services/SeedService.cs new file mode 100644 index 00000000..b487c223 --- /dev/null +++ b/src/shared/LibplanetConsole.Seed/Services/SeedService.cs @@ -0,0 +1,11 @@ +#if LIBPLANET_NODE +using Grpc.Net.Client; +using static LibplanetConsole.Seed.Grpc.SeedGrpcService; + +namespace LibplanetConsole.Seed.Services; + +internal sealed class SeedService(GrpcChannel channel) + : SeedGrpcServiceClient(channel) +{ +} +#endif // LIBPLANET_NODE