cs-codex-dist-tests/Tools/BiblioTech/BaseNetCommand.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2023-10-24 13:25:45 +00:00
using BiblioTech.Options;
using CodexContractsPlugin;
2023-10-20 08:14:56 +00:00
using Core;
using GethPlugin;
2023-10-20 07:49:23 +00:00
namespace BiblioTech
{
public abstract class BaseNetCommand : BaseCommand
{
private readonly DeploymentsFilesMonitor monitor;
2023-10-20 08:14:56 +00:00
private readonly CoreInterface ci;
2023-10-20 07:49:23 +00:00
2023-10-20 08:14:56 +00:00
public BaseNetCommand(DeploymentsFilesMonitor monitor, CoreInterface ci)
2023-10-20 07:49:23 +00:00
{
this.monitor = monitor;
2023-10-20 08:14:56 +00:00
this.ci = ci;
2023-10-20 07:49:23 +00:00
}
2023-10-24 13:25:45 +00:00
protected override async Task Invoke(CommandContext context)
2023-10-20 07:49:23 +00:00
{
var deployments = monitor.GetDeployments();
if (deployments.Length == 0)
{
2023-10-24 13:25:45 +00:00
await context.Command.FollowupAsync("No deployments are currently available.");
2023-10-20 07:49:23 +00:00
return;
}
if (deployments.Length > 1)
{
2023-10-24 13:25:45 +00:00
await context.Command.FollowupAsync("Multiple deployments are online. I don't know which one to pick!");
2023-10-20 07:49:23 +00:00
return;
}
2023-10-20 08:14:56 +00:00
var codexDeployment = deployments.Single();
var gethDeployment = codexDeployment.GethDeployment;
var contractsDeployment = codexDeployment.CodexContractsDeployment;
var gethNode = ci.WrapGethDeployment(gethDeployment);
var contracts = ci.WrapCodexContractsDeployment(contractsDeployment);
2023-10-24 13:25:45 +00:00
await Execute(context, gethNode, contracts);
2023-10-20 07:49:23 +00:00
}
2023-10-24 13:25:45 +00:00
protected abstract Task Execute(CommandContext context, IGethNode gethNode, ICodexContracts contracts);
2023-10-20 07:49:23 +00:00
}
}