Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename evidence or explorer-related codes #72

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .submodules/lib9c
Submodule lib9c deleted from 178eaf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LibplanetConsole.Client.Example;
internal sealed class ExampleClientInfoProvider(ExampleClient exampleClient)
: InfoProviderBase<IApplication>(nameof(ExampleClient))
{
protected override object? GetInfos(IApplication obj)
protected override object? GetInfo(IApplication obj)
{
return new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public ApplicationInfoProvider()
{
}

protected override object? GetInfos(ApplicationBase obj) => obj.Info;
protected override object? GetInfo(ApplicationBase obj) => obj.Info;
}
2 changes: 1 addition & 1 deletion src/client/LibplanetConsole.Client/ClientInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LibplanetConsole.Client;
internal sealed class ClientInfoProvider(Client client)
: InfoProviderBase<ApplicationBase>(nameof(Client))
{
protected override object? GetInfos(ApplicationBase obj)
protected override object? GetInfo(ApplicationBase obj)
{
return client.Info;
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/LibplanetConsole.Common/InfoProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public abstract class InfoProviderBase<T>(string name) : IInfoProvider
{
if (obj is T t)
{
return GetInfos(t);
return GetInfo(t);
}

throw new NotSupportedException("The object is not supported.");
}

protected abstract object? GetInfos(T obj);
protected abstract object? GetInfo(T obj);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public async Task NewAsync(
string nodeAddress = "", CancellationToken cancellationToken = default)
{
var node = nodes.Current ?? throw new InvalidOperationException("No node is selected.");
var evidenceContent = node.GetRequiredService<IEvidenceContent>();
var evidenceInfo = await evidenceContent.AddEvidenceAsync(cancellationToken);
var evidence = node.GetRequiredService<IEvidence>();
var evidenceInfo = await evidence.AddEvidenceAsync(cancellationToken);
await Out.WriteLineAsJsonAsync(evidenceInfo);
}

Expand All @@ -28,16 +28,16 @@ public async Task RaiseAsync(
CancellationToken cancellationToken = default)
{
var node = nodes.Current ?? throw new InvalidOperationException("No node is selected.");
var evidenceContent = node.GetRequiredService<IEvidenceContent>();
await evidenceContent.ViolateAsync(cancellationToken);
var evidence = node.GetRequiredService<IEvidence>();
await evidence.ViolateAsync(cancellationToken);
}

[CommandMethod]
public async Task ListAsync(long height = -1, CancellationToken cancellationToken = default)
{
var node = nodes.Current ?? throw new InvalidOperationException("No node is selected.");
var evidenceContent = node.GetRequiredService<IEvidenceContent>();
var evidenceInfos = await evidenceContent.GetEvidenceAsync(height, cancellationToken);
var evidence = node.GetRequiredService<IEvidence>();
var evidenceInfos = await evidence.GetEvidenceAsync(height, cancellationToken);
await Out.WriteLineAsJsonAsync(evidenceInfos);
}

Expand All @@ -47,8 +47,8 @@ public async Task UnjailAsync(
CancellationToken cancellationToken = default)
{
var node = nodes.Current ?? throw new InvalidOperationException("No node is selected.");
var evidenceContent = node.GetService<IEvidenceContent>();
await evidenceContent.UnjailAsync(cancellationToken);
var evidence = node.GetService<IEvidenceContent>();
await evidence.UnjailAsync(cancellationToken);
}
#endif // LIBPLANET_DPOS
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
namespace LibplanetConsole.Console.Evidence;

[Export(typeof(INodeContent))]
[Export(typeof(IEvidenceContent))]
[Export(typeof(IEvidence))]
[Export(typeof(INodeContentService))]
[method: ImportingConstructor]
internal sealed class EvidenceNodeContent(INode node)
: INodeContent, IEvidenceContent, INodeContentService
internal sealed class Evidence(INode node)
: INodeContent, IEvidence, INodeContentService
{
private readonly RemoteService<IEvidenceService> _evidenceService = new();

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

namespace LibplanetConsole.Console.Evidence;

internal interface IEvidenceContent
internal interface IEvidence
{
Task<EvidenceInfo> AddEvidenceAsync(CancellationToken cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ExampleClientInfoProvider()
{
}

protected override object? GetInfos(ExampleClientContent obj)
protected override object? GetInfo(ExampleClientContent obj)
{
return new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ExampleNodeInfoProvider()
{
}

protected override object? GetInfos(ExampleNodeContent obj)
protected override object? GetInfo(ExampleNodeContent obj)
{
return new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public async Task StartAsync(
string endPoint = "", CancellationToken cancellationToken = default)
{
var node = application.GetNode(Address);
var explorerNode = node.GetRequiredService<IExplorerNodeContent>();
var explorer = node.GetRequiredService<IExplorer>();
if (endPoint != string.Empty)
{
explorerNode.EndPoint = EndPointUtility.Parse(endPoint);
explorer.EndPoint = EndPointUtility.Parse(endPoint);
}

await explorerNode.StartAsync(cancellationToken);
await explorer.StartAsync(cancellationToken);
}

[CommandMethod]
Expand All @@ -41,7 +41,7 @@ public async Task StartAsync(
public async Task StopAsync(CancellationToken cancellationToken = default)
{
var node = application.GetNode(Address);
var explorerNode = node.GetRequiredService<IExplorerNodeContent>();
await explorerNode.StopAsync(cancellationToken);
var explorer = node.GetRequiredService<IExplorer>();
await explorer.StopAsync(cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
namespace LibplanetConsole.Console.Explorer;

[Export(typeof(IInfoProvider))]
internal sealed class ExplorerNodeInfoProvider
internal sealed class ExplorerInfoProvider
: InfoProviderBase<ExplorerNodeContent>
{
public ExplorerNodeInfoProvider()
public ExplorerInfoProvider()
: base("Explorer")
{
}

protected override object? GetInfos(ExplorerNodeContent obj)
protected override object? GetInfo(ExplorerNodeContent obj)
{
return new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace LibplanetConsole.Console.Explorer;

[Export(typeof(IExplorerNodeContent))]
[Export(typeof(IExplorer))]
[Export(typeof(INodeContentService))]
[Export(typeof(INodeContent))]
[method: ImportingConstructor]
internal sealed class ExplorerNodeContent(INode node, ILogger logger, ExplorerSettings settings)
: NodeContentBase(node), IExplorerNodeContent, IExplorerCallback, INodeContentService
: NodeContentBase(node), IExplorer, IExplorerCallback, INodeContentService
{
private readonly ILogger _logger = logger;
private readonly ExecutionScope _executionScope = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LibplanetConsole.Console.Explorer;

public interface IExplorerNodeContent
public interface IExplorer
{
event EventHandler? Started;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public ApplicationInfoProvider()
{
}

protected override object? GetInfos(ApplicationBase obj) => obj.Info;
protected override object? GetInfo(ApplicationBase obj) => obj.Info;
}
2 changes: 1 addition & 1 deletion src/console/LibplanetConsole.Console/ClientInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ClientInfoProvider()
{
}

protected override object? GetInfos(Client obj)
protected override object? GetInfo(Client obj)
{
var props = InfoUtility.ToDictionary(obj.Info);
var contents = obj.GetRequiredService<IEnumerable<IClientContent>>();
Expand Down
2 changes: 1 addition & 1 deletion src/console/LibplanetConsole.Console/NodeInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public NodeInfoProvider()
{
}

protected override object? GetInfos(Node obj)
protected override object? GetInfo(Node obj)
{
var props = InfoUtility.ToDictionary(obj.Info);
var contents = obj.GetRequiredService<IEnumerable<INodeContent>>();
Expand Down
62 changes: 0 additions & 62 deletions src/node/LibplanetConsole.Node.Delegation/ActionProvider.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LibplanetConsole.Node.Evidence.Commands;
[CommandSummary("Provides evidence-related commands.")]
[Category("Evidence")]
[method: ImportingConstructor]
internal sealed class EvidenceCommand(INode node, IEvidenceNode evidenceNode)
internal sealed class EvidenceCommand(INode node, IEvidence evidence)
: CommandMethodBase
{
public override bool IsEnabled => node.IsRunning is true;
Expand All @@ -18,15 +18,15 @@ internal sealed class EvidenceCommand(INode node, IEvidenceNode evidenceNode)
[CommandSummary("Adds a new evidence.")]
public async Task NewAsync(CancellationToken cancellationToken)
{
var evidenceInfo = await evidenceNode.AddEvidenceAsync(cancellationToken);
var evidenceInfo = await evidence.AddEvidenceAsync(cancellationToken);
await Out.WriteLineAsJsonAsync(evidenceInfo);
}

[CommandMethod]
[CommandSummary("Raises a infraction.")]
public async Task RaiseAsync(CancellationToken cancellationToken)
{
await evidenceNode.ViolateAsync(cancellationToken);
await evidence.ViolateAsync(cancellationToken);
}

[CommandMethod]
Expand All @@ -37,8 +37,8 @@ public async Task ListAsync(CancellationToken cancellationToken = default)
var height = ListProperties.Height;
var isPending = ListProperties.IsPending;
var evidenceInfos = isPending == true ?
await evidenceNode.GetPendingEvidenceAsync(cancellationToken) :
await evidenceNode.GetEvidenceAsync(height, cancellationToken);
await evidence.GetPendingEvidenceAsync(cancellationToken) :
await evidence.GetEvidenceAsync(height, cancellationToken);
await Out.WriteLineAsJsonAsync(evidenceInfos);
}

Expand All @@ -49,16 +49,16 @@ public async Task GetAsync(string evidenceId, CancellationToken cancellationToke
{
var isPending = GetProperties.IsPending;
var evidenceInfo = isPending == true ?
await evidenceNode.GetPendingEvidenceAsync(evidenceId, cancellationToken) :
await evidenceNode.GetEvidenceAsync(evidenceId, cancellationToken);
await evidence.GetPendingEvidenceAsync(evidenceId, cancellationToken) :
await evidence.GetEvidenceAsync(evidenceId, cancellationToken);
await Out.WriteLineAsJsonAsync(evidenceInfo);
}

#if LIBPLANET_DPOS
[CommandMethod]
public async Task UnjailAsync(CancellationToken cancellationToken)
{
await evidenceNode.UnjailAsync(cancellationToken);
await evidence.UnjailAsync(cancellationToken);
}
#endif // LIBPLANET_DPOS

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

namespace LibplanetConsole.Node.Evidence;

[Export(typeof(IEvidenceNode))]
[Export(typeof(IEvidence))]
[Export]
[method: ImportingConstructor]
internal sealed class EvidenceNode(INode node) : IEvidenceNode, IAsyncDisposable
internal sealed class Evidence(INode node) : IEvidence, IAsyncDisposable
{
private readonly DuplicateVoteViolator _duplicateVotePerpetrator = new(node);

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

namespace LibplanetConsole.Node.Evidence;

public interface IEvidenceNode
public interface IEvidence
{
Task<EvidenceInfo> AddEvidenceAsync(CancellationToken cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ namespace LibplanetConsole.Node.Evidence.Services;

[Export(typeof(ILocalService))]
[method: ImportingConstructor]
internal sealed class EvidenceNodeService(EvidenceNode evidenceNode)
internal sealed class EvidenceService(Evidence evidence)
: LocalService<IEvidenceService>, IEvidenceService
{
public Task<EvidenceInfo> AddEvidenceAsync(CancellationToken cancellationToken)
=> evidenceNode.AddEvidenceAsync(cancellationToken);
=> evidence.AddEvidenceAsync(cancellationToken);

public Task<EvidenceInfo[]> GetEvidenceAsync(long height, CancellationToken cancellationToken)
=> evidenceNode.GetEvidenceAsync(height, cancellationToken);
=> evidence.GetEvidenceAsync(height, cancellationToken);

public Task ViolateAsync(CancellationToken cancellationToken)
=> evidenceNode.ViolateAsync(cancellationToken);
=> evidence.ViolateAsync(cancellationToken);

#if LIBPLANET_DPOS
public async Task UnjailAsync(byte[] signarue, CancellationToken cancellationToken)
{
if (node.Verify(true, signarue) == true)
{
await evidenceNode.UnjailAsync(cancellationToken);
await evidence.UnjailAsync(cancellationToken);
}

throw new ArgumentException("Invalid signature.", nameof(signarue));
Expand Down
Loading