2
0
mirror of synced 2025-01-13 18:14:14 +00:00

49 lines
1.5 KiB
C#
Raw Normal View History

2023-09-12 13:32:06 +02:00
using Core;
2023-09-19 11:51:59 +02:00
using GethPlugin;
2023-09-20 12:55:09 +02:00
using KubernetesWorkflow;
using KubernetesWorkflow.Types;
2023-09-12 11:43:46 +02:00
namespace CodexPlugin
{
public interface ICodexNodeFactory
{
2023-09-19 11:51:59 +02:00
CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group);
2023-09-20 12:55:09 +02:00
CrashWatcher CreateCrashWatcher(RunningContainer c);
}
public class CodexNodeFactory : ICodexNodeFactory
{
2023-09-12 11:43:46 +02:00
private readonly IPluginTools tools;
public CodexNodeFactory(IPluginTools tools)
{
this.tools = tools;
}
2023-09-19 11:51:59 +02:00
public CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group)
2023-09-11 16:57:57 +02:00
{
2023-09-19 11:51:59 +02:00
var ethAddress = GetEthAddress(access);
2023-09-20 08:45:55 +02:00
var marketplaceAccess = GetMarketplaceAccess(access, ethAddress);
return new CodexNode(tools, access, group, marketplaceAccess, ethAddress);
}
2023-09-20 10:13:29 +02:00
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, EthAddress? ethAddress)
2023-09-20 08:45:55 +02:00
{
if (ethAddress == null) return new MarketplaceUnavailable();
return new MarketplaceAccess(tools.GetLog(), codexAccess);
2023-09-19 11:51:59 +02:00
}
2023-09-20 10:13:29 +02:00
private EthAddress? GetEthAddress(CodexAccess access)
2023-09-19 11:51:59 +02:00
{
var ethAccount = access.Container.Recipe.Additionals.Get<EthAccount>();
if (ethAccount == null) return null;
return ethAccount.EthAddress;
2023-09-11 16:57:57 +02:00
}
2023-09-20 12:55:09 +02:00
public CrashWatcher CreateCrashWatcher(RunningContainer c)
{
return tools.CreateWorkflow().CreateCrashWatcher(c);
}
}
}