2
0
mirror of synced 2025-01-16 19:44:17 +00:00

68 lines
2.2 KiB
C#
Raw Normal View History

2023-09-12 13:32:06 +02:00
using Core;
2023-09-11 16:57:57 +02:00
using KubernetesWorkflow;
namespace CodexPlugin
{
2023-09-13 16:06:05 +02:00
public class CodexPlugin : IProjectPlugin, IHasLogPrefix, IHasMetadata
2023-09-11 16:57:57 +02:00
{
2023-09-13 10:03:11 +02:00
private readonly CodexStarter codexStarter;
private readonly IPluginTools tools;
private readonly CodexLogLevel defaultLogLevel = CodexLogLevel.Trace;
2023-09-11 16:57:57 +02:00
2023-09-13 10:03:11 +02:00
public CodexPlugin(IPluginTools tools)
2023-09-11 16:57:57 +02:00
{
2023-09-13 10:03:11 +02:00
codexStarter = new CodexStarter(tools);
this.tools = tools;
2023-09-12 10:31:55 +02:00
}
public string LogPrefix => "(Codex) ";
2023-09-13 10:03:11 +02:00
public void Announce()
2023-09-12 10:31:55 +02:00
{
2023-09-13 16:06:05 +02:00
tools.GetLog().Log($"Loaded with Codex ID: '{codexStarter.GetCodexId()}'");
}
public void AddMetadata(IAddMetadata metadata)
{
metadata.Add("codexid", codexStarter.GetCodexId());
2023-09-11 16:57:57 +02:00
}
2023-09-13 10:03:11 +02:00
public void Decommission()
2023-09-12 10:31:55 +02:00
{
}
2023-09-20 12:02:32 +02:00
public RunningContainers[] DeployCodexNodes(int numberOfNodes, Action<ICodexSetup> setup)
2023-09-11 16:57:57 +02:00
{
2023-09-20 08:45:55 +02:00
var codexSetup = GetSetup(numberOfNodes, setup);
2023-09-11 16:57:57 +02:00
return codexStarter.BringOnline(codexSetup);
}
2023-09-19 13:58:45 +02:00
public ICodexNodeGroup WrapCodexContainers(CoreInterface coreInterface, RunningContainers[] containers)
2023-09-11 16:57:57 +02:00
{
2023-09-20 10:13:29 +02:00
containers = containers.Select(c => SerializeGate.Gate(c)).ToArray();
return codexStarter.WrapCodexContainers(coreInterface, containers);
2023-09-11 16:57:57 +02:00
}
2023-09-20 08:45:55 +02:00
public void WireUpMarketplace(ICodexNodeGroup result, Action<ICodexSetup> setup)
{
var codexSetup = GetSetup(1, setup);
if (codexSetup.MarketplaceConfig == null) return;
var mconfig = codexSetup.MarketplaceConfig;
foreach (var node in result)
{
mconfig.GethNode.SendEth(node, mconfig.InitialEth);
mconfig.CodexContracts.MintTestTokens(mconfig.GethNode, node, mconfig.InitialTokens);
}
}
private CodexSetup GetSetup(int numberOfNodes, Action<ICodexSetup> setup)
{
var codexSetup = new CodexSetup(numberOfNodes);
codexSetup.LogLevel = defaultLogLevel;
setup(codexSetup);
return codexSetup;
}
2023-09-11 16:57:57 +02:00
}
}