2024-07-26 06:39:27 +00:00
|
|
|
using CodexPlugin.Hooks;
|
2024-03-25 12:48:20 +00:00
|
|
|
using Core;
|
2023-11-12 09:07:23 +00:00
|
|
|
using KubernetesWorkflow.Types;
|
2023-09-11 14:57:57 +00:00
|
|
|
|
|
|
|
namespace CodexPlugin
|
|
|
|
{
|
2023-09-13 14:06:05 +00:00
|
|
|
public class CodexPlugin : IProjectPlugin, IHasLogPrefix, IHasMetadata
|
2023-09-11 14:57:57 +00:00
|
|
|
{
|
2023-09-13 08:03:11 +00:00
|
|
|
private readonly CodexStarter codexStarter;
|
|
|
|
private readonly IPluginTools tools;
|
2023-09-13 12:37:53 +00:00
|
|
|
private readonly CodexLogLevel defaultLogLevel = CodexLogLevel.Trace;
|
2023-09-11 14:57:57 +00:00
|
|
|
|
2023-09-13 08:03:11 +00:00
|
|
|
public CodexPlugin(IPluginTools tools)
|
2023-09-11 14:57:57 +00:00
|
|
|
{
|
2023-09-13 08:03:11 +00:00
|
|
|
codexStarter = new CodexStarter(tools);
|
|
|
|
this.tools = tools;
|
2023-09-12 08:31:55 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 08:23:05 +00:00
|
|
|
public string LogPrefix => "(Codex) ";
|
2023-09-13 08:03:11 +00:00
|
|
|
|
|
|
|
public void Announce()
|
2023-09-12 08:31:55 +00:00
|
|
|
{
|
2023-11-13 08:37:45 +00:00
|
|
|
tools.GetLog().Log($"Loaded with Codex ID: '{codexStarter.GetCodexId()}' - Revision: {codexStarter.GetCodexRevision()}");
|
2023-09-13 14:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddMetadata(IAddMetadata metadata)
|
|
|
|
{
|
|
|
|
metadata.Add("codexid", codexStarter.GetCodexId());
|
2023-11-13 08:37:45 +00:00
|
|
|
metadata.Add("codexrevision", codexStarter.GetCodexRevision());
|
2023-09-11 14:57:57 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 08:03:11 +00:00
|
|
|
public void Decommission()
|
2023-09-12 08:31:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-04-13 14:09:17 +00:00
|
|
|
public RunningPod[] DeployCodexNodes(int numberOfNodes, Action<ICodexSetup> setup)
|
2023-09-11 14:57:57 +00:00
|
|
|
{
|
2023-09-20 06:45:55 +00:00
|
|
|
var codexSetup = GetSetup(numberOfNodes, setup);
|
2023-09-11 14:57:57 +00:00
|
|
|
return codexStarter.BringOnline(codexSetup);
|
|
|
|
}
|
|
|
|
|
2024-04-13 14:09:17 +00:00
|
|
|
public ICodexNodeGroup WrapCodexContainers(CoreInterface coreInterface, RunningPod[] containers)
|
2023-09-11 14:57:57 +00:00
|
|
|
{
|
2023-09-20 08:13:29 +00:00
|
|
|
containers = containers.Select(c => SerializeGate.Gate(c)).ToArray();
|
|
|
|
return codexStarter.WrapCodexContainers(coreInterface, containers);
|
2023-09-11 14:57:57 +00:00
|
|
|
}
|
2023-09-20 06:45:55 +00: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)
|
|
|
|
{
|
2024-03-26 14:35:26 +00:00
|
|
|
mconfig.GethNode.SendEth(node, mconfig.MarketplaceSetup.InitialEth);
|
|
|
|
mconfig.CodexContracts.MintTestTokens(node, mconfig.MarketplaceSetup.InitialTestTokens);
|
2023-09-20 06:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-26 06:39:27 +00:00
|
|
|
public void SetCodexHooksProvider(ICodexHooksProvider hooksProvider)
|
|
|
|
{
|
|
|
|
codexStarter.HooksFactory.Provider = hooksProvider;
|
|
|
|
}
|
|
|
|
|
2023-09-20 06:45:55 +00:00
|
|
|
private CodexSetup GetSetup(int numberOfNodes, Action<ICodexSetup> setup)
|
|
|
|
{
|
|
|
|
var codexSetup = new CodexSetup(numberOfNodes);
|
|
|
|
codexSetup.LogLevel = defaultLogLevel;
|
|
|
|
setup(codexSetup);
|
|
|
|
return codexSetup;
|
|
|
|
}
|
2023-09-11 14:57:57 +00:00
|
|
|
}
|
|
|
|
}
|