2023-09-19 10:24:43 +02:00
|
|
|
|
using CodexContractsPlugin;
|
|
|
|
|
|
using GethPlugin;
|
|
|
|
|
|
using KubernetesWorkflow;
|
2023-09-08 10:21:40 +02:00
|
|
|
|
using Utils;
|
2023-04-12 16:06:04 +02:00
|
|
|
|
|
2023-09-11 11:59:33 +02:00
|
|
|
|
namespace CodexPlugin
|
2023-04-12 16:06:04 +02:00
|
|
|
|
{
|
2023-04-13 09:33:10 +02:00
|
|
|
|
public interface ICodexSetup
|
2023-04-12 16:06:04 +02:00
|
|
|
|
{
|
2023-09-13 14:37:53 +02:00
|
|
|
|
ICodexSetup WithLogLevel(CodexLogLevel logLevel);
|
2023-04-30 10:56:19 +02:00
|
|
|
|
ICodexSetup WithName(string name);
|
2023-04-13 09:33:10 +02:00
|
|
|
|
ICodexSetup At(Location location);
|
2023-09-19 11:51:59 +02:00
|
|
|
|
ICodexSetup WithBootstrapNode(ICodexNode node);
|
2023-04-13 09:33:10 +02:00
|
|
|
|
ICodexSetup WithStorageQuota(ByteSize storageQuota);
|
2023-08-10 09:44:23 +02:00
|
|
|
|
ICodexSetup WithBlockTTL(TimeSpan duration);
|
2023-08-14 15:51:03 +02:00
|
|
|
|
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
2023-08-14 16:37:31 +02:00
|
|
|
|
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
2023-09-13 11:59:21 +02:00
|
|
|
|
ICodexSetup EnableMetrics();
|
2023-09-20 08:45:55 +02:00
|
|
|
|
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens, bool isValidator = false);
|
2023-04-12 16:06:04 +02:00
|
|
|
|
}
|
2023-04-12 16:12:04 +02:00
|
|
|
|
|
2023-04-13 09:33:10 +02:00
|
|
|
|
public class CodexSetup : CodexStartupConfig, ICodexSetup
|
2023-04-12 16:06:04 +02:00
|
|
|
|
{
|
|
|
|
|
|
public int NumberOfNodes { get; }
|
|
|
|
|
|
|
2023-09-13 14:37:53 +02:00
|
|
|
|
public CodexSetup(int numberOfNodes)
|
2023-04-12 16:06:04 +02:00
|
|
|
|
{
|
|
|
|
|
|
NumberOfNodes = numberOfNodes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-13 14:37:53 +02:00
|
|
|
|
public ICodexSetup WithLogLevel(CodexLogLevel logLevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogLevel = logLevel;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-30 10:56:19 +02:00
|
|
|
|
public ICodexSetup WithName(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
NameOverride = name;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-13 09:33:10 +02:00
|
|
|
|
public ICodexSetup At(Location location)
|
2023-04-12 16:06:04 +02:00
|
|
|
|
{
|
|
|
|
|
|
Location = location;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-19 11:51:59 +02:00
|
|
|
|
public ICodexSetup WithBootstrapNode(ICodexNode node)
|
2023-04-19 14:57:00 +02:00
|
|
|
|
{
|
2023-04-24 14:09:23 +02:00
|
|
|
|
BootstrapSpr = node.GetDebugInfo().spr;
|
2023-04-19 14:57:00 +02:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-04-12 16:06:04 +02:00
|
|
|
|
|
2023-04-13 09:33:10 +02:00
|
|
|
|
public ICodexSetup WithStorageQuota(ByteSize storageQuota)
|
2023-04-12 16:06:04 +02:00
|
|
|
|
{
|
|
|
|
|
|
StorageQuota = storageQuota;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-10 09:44:23 +02:00
|
|
|
|
public ICodexSetup WithBlockTTL(TimeSpan duration)
|
|
|
|
|
|
{
|
|
|
|
|
|
BlockTTL = Convert.ToInt32(duration.TotalSeconds);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-14 15:51:03 +02:00
|
|
|
|
public ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration)
|
|
|
|
|
|
{
|
|
|
|
|
|
BlockMaintenanceInterval = duration;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-14 16:37:31 +02:00
|
|
|
|
public ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks)
|
|
|
|
|
|
{
|
|
|
|
|
|
BlockMaintenanceNumber = numberOfBlocks;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-13 11:59:21 +02:00
|
|
|
|
public ICodexSetup EnableMetrics()
|
|
|
|
|
|
{
|
|
|
|
|
|
MetricsEnabled = true;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2023-04-12 16:06:04 +02:00
|
|
|
|
|
2023-09-20 08:45:55 +02:00
|
|
|
|
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens, bool isValidator = false)
|
2023-09-19 10:24:43 +02:00
|
|
|
|
{
|
2023-09-20 08:45:55 +02:00
|
|
|
|
MarketplaceConfig = new MarketplaceInitialConfig(gethNode, codexContracts, initialEth, initialTokens, isValidator);
|
2023-09-19 10:24:43 +02:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-12 16:06:04 +02:00
|
|
|
|
public string Describe()
|
|
|
|
|
|
{
|
|
|
|
|
|
var args = string.Join(',', DescribeArgs());
|
2023-04-19 14:57:00 +02:00
|
|
|
|
return $"({NumberOfNodes} CodexNodes with args:[{args}])";
|
2023-04-12 16:06:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> DescribeArgs()
|
|
|
|
|
|
{
|
2023-05-31 13:34:12 +02:00
|
|
|
|
yield return $"LogLevel={LogLevel}";
|
2023-04-24 14:09:23 +02:00
|
|
|
|
if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}";
|
2023-04-19 09:57:37 +02:00
|
|
|
|
if (StorageQuota != null) yield return $"StorageQuote={StorageQuota}";
|
2023-04-12 16:06:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|