cs-codex-dist-tests/CodexPlugin/CodexNodeFactory.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2023-09-12 11:32:06 +00:00
using Core;
2023-09-19 09:51:59 +00:00
using GethPlugin;
2023-09-12 09:43:46 +00:00
namespace CodexPlugin
{
public interface ICodexNodeFactory
{
2023-09-19 09:51:59 +00:00
CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group);
}
public class CodexNodeFactory : ICodexNodeFactory
{
2023-09-12 09:43:46 +00:00
private readonly IPluginTools tools;
public CodexNodeFactory(IPluginTools tools)
{
this.tools = tools;
}
2023-09-19 09:51:59 +00:00
public CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group)
2023-09-11 14:57:57 +00:00
{
2023-09-19 09:51:59 +00:00
var ethAddress = GetEthAddress(access);
2023-09-20 06:45:55 +00:00
var marketplaceAccess = GetMarketplaceAccess(access, ethAddress);
return new CodexNode(tools, access, group, marketplaceAccess, ethAddress);
}
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, IEthAddress? ethAddress)
{
if (ethAddress == null) return new MarketplaceUnavailable();
return new MarketplaceAccess(tools.GetLog(), codexAccess);
2023-09-19 09:51:59 +00:00
}
private IEthAddress? GetEthAddress(CodexAccess access)
{
var mStart = access.Container.Recipe.Additionals.SingleOrDefault(a => a is MarketplaceStartResults) as MarketplaceStartResults;
if (mStart == null) return null;
return mStart.EthAddress;
2023-09-11 14:57:57 +00:00
}
}
}