2023-09-15 13:52:02 +00:00
|
|
|
|
using Core;
|
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
|
|
|
|
|
namespace GethPlugin
|
2023-09-15 10:36:35 +00:00
|
|
|
|
{
|
|
|
|
|
public class GethStarter
|
|
|
|
|
{
|
2023-09-15 13:52:02 +00:00
|
|
|
|
private readonly IPluginTools tools;
|
|
|
|
|
|
|
|
|
|
public GethStarter(IPluginTools tools)
|
2023-09-15 10:36:35 +00:00
|
|
|
|
{
|
2023-09-15 13:52:02 +00:00
|
|
|
|
this.tools = tools;
|
2023-09-15 10:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 07:16:57 +00:00
|
|
|
|
public IGethDeployment StartGeth(GethStartupConfig gethStartupConfig)
|
2023-09-15 10:36:35 +00:00
|
|
|
|
{
|
2023-09-15 13:52:02 +00:00
|
|
|
|
Log("Starting Geth bootstrap node...");
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
2023-09-15 13:52:02 +00:00
|
|
|
|
var startupConfig = new StartupConfig();
|
|
|
|
|
startupConfig.Add(gethStartupConfig);
|
|
|
|
|
startupConfig.NameOverride = gethStartupConfig.NameOverride;
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
2023-09-15 13:52:02 +00:00
|
|
|
|
var workflow = tools.CreateWorkflow();
|
|
|
|
|
var containers = workflow.Start(1, Location.Unspecified, new GethContainerRecipe(), startupConfig);
|
|
|
|
|
if (containers.Containers.Length != 1) throw new InvalidOperationException("Expected 1 Geth bootstrap node to be created. Test infra failure.");
|
|
|
|
|
var container = containers.Containers[0];
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
2023-09-15 14:27:08 +00:00
|
|
|
|
var extractor = new GethContainerInfoExtractor(tools.GetLog(), workflow, container);
|
2023-09-15 13:52:02 +00:00
|
|
|
|
var accounts = extractor.ExtractAccounts();
|
|
|
|
|
var pubKey = extractor.ExtractPubKey();
|
2023-09-19 09:51:59 +00:00
|
|
|
|
|
2023-09-15 13:52:02 +00:00
|
|
|
|
var discoveryPort = container.Recipe.GetPortByTag(GethContainerRecipe.DiscoveryPortTag);
|
|
|
|
|
if (discoveryPort == null) throw new Exception("Expected discovery port to be created.");
|
2023-09-15 14:27:08 +00:00
|
|
|
|
var httpPort = container.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag);
|
|
|
|
|
if (httpPort == null) throw new Exception("Expected http port to be created.");
|
|
|
|
|
var wsPort = container.Recipe.GetPortByTag(GethContainerRecipe.wsPortTag);
|
|
|
|
|
if (wsPort == null) throw new Exception("Expected ws port to be created.");
|
|
|
|
|
|
2023-09-19 09:51:59 +00:00
|
|
|
|
Log($"Geth node started.");
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
2023-09-20 07:16:57 +00:00
|
|
|
|
return new GethDeployment(container, discoveryPort, httpPort, wsPort, accounts, pubKey);
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
2023-09-15 10:36:35 +00:00
|
|
|
|
|
2023-09-20 07:16:57 +00:00
|
|
|
|
public IGethNode WrapGethContainer(IGethDeployment startResult)
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
2023-09-20 07:16:57 +00:00
|
|
|
|
return new GethNode(tools.GetLog(), SerializeGate.Gate(startResult));
|
2023-09-15 10:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 13:52:02 +00:00
|
|
|
|
private void Log(string msg)
|
2023-09-15 10:36:35 +00:00
|
|
|
|
{
|
2023-09-15 13:52:02 +00:00
|
|
|
|
tools.GetLog().Log(msg);
|
2023-09-15 10:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|