2023-09-15 15:52:02 +02:00
|
|
|
|
using Core;
|
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
|
|
|
|
|
namespace GethPlugin
|
2023-09-15 12:36:35 +02:00
|
|
|
|
{
|
|
|
|
|
public class GethStarter
|
|
|
|
|
{
|
2023-09-15 15:52:02 +02:00
|
|
|
|
private readonly IPluginTools tools;
|
|
|
|
|
|
|
|
|
|
public GethStarter(IPluginTools tools)
|
2023-09-15 12:36:35 +02:00
|
|
|
|
{
|
2023-09-15 15:52:02 +02:00
|
|
|
|
this.tools = tools;
|
2023-09-15 12:36:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 10:13:29 +02:00
|
|
|
|
public GethDeployment StartGeth(GethStartupConfig gethStartupConfig)
|
2023-09-15 12:36:35 +02:00
|
|
|
|
{
|
2023-09-22 07:43:46 +02:00
|
|
|
|
Log("Starting Geth node...");
|
2023-09-15 12:36:35 +02:00
|
|
|
|
|
2023-09-15 15:52:02 +02:00
|
|
|
|
var startupConfig = new StartupConfig();
|
|
|
|
|
startupConfig.Add(gethStartupConfig);
|
|
|
|
|
startupConfig.NameOverride = gethStartupConfig.NameOverride;
|
2023-09-15 12:36:35 +02:00
|
|
|
|
|
2023-09-15 15:52:02 +02:00
|
|
|
|
var workflow = tools.CreateWorkflow();
|
2024-04-09 10:23:07 +02:00
|
|
|
|
var containers = workflow.Start(1, new GethContainerRecipe(), startupConfig).WaitForOnline();
|
2023-09-15 15:52:02 +02:00
|
|
|
|
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 12:36:35 +02:00
|
|
|
|
|
2023-09-15 16:27:08 +02:00
|
|
|
|
var extractor = new GethContainerInfoExtractor(tools.GetLog(), workflow, container);
|
2023-10-23 13:36:20 +02:00
|
|
|
|
var account = extractor.ExtractAccounts().Accounts.First();
|
2023-09-15 15:52:02 +02:00
|
|
|
|
var pubKey = extractor.ExtractPubKey();
|
2023-09-19 11:51:59 +02:00
|
|
|
|
|
2023-09-15 15:52:02 +02:00
|
|
|
|
var discoveryPort = container.Recipe.GetPortByTag(GethContainerRecipe.DiscoveryPortTag);
|
|
|
|
|
if (discoveryPort == null) throw new Exception("Expected discovery port to be created.");
|
2023-09-15 16:27:08 +02:00
|
|
|
|
var httpPort = container.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag);
|
|
|
|
|
if (httpPort == null) throw new Exception("Expected http port to be created.");
|
2023-09-22 09:52:30 +02:00
|
|
|
|
var wsPort = container.Recipe.GetPortByTag(GethContainerRecipe.WsPortTag);
|
2023-09-15 16:27:08 +02:00
|
|
|
|
if (wsPort == null) throw new Exception("Expected ws port to be created.");
|
|
|
|
|
|
2023-09-19 11:51:59 +02:00
|
|
|
|
Log($"Geth node started.");
|
2023-09-15 12:36:35 +02:00
|
|
|
|
|
2023-11-06 16:10:19 +01:00
|
|
|
|
return new GethDeployment(containers, discoveryPort, httpPort, wsPort, account, pubKey);
|
2023-09-19 11:51:59 +02:00
|
|
|
|
}
|
2023-09-15 12:36:35 +02:00
|
|
|
|
|
2023-09-20 10:13:29 +02:00
|
|
|
|
public IGethNode WrapGethContainer(GethDeployment startResult)
|
2023-09-19 11:51:59 +02:00
|
|
|
|
{
|
2023-09-20 10:13:29 +02:00
|
|
|
|
startResult = SerializeGate.Gate(startResult);
|
2023-12-11 11:01:12 +01:00
|
|
|
|
return new DeploymentGethNode(tools.GetLog(), startResult);
|
2023-09-15 12:36:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 15:52:02 +02:00
|
|
|
|
private void Log(string msg)
|
2023-09-15 12:36:35 +02:00
|
|
|
|
{
|
2023-09-15 15:52:02 +02:00
|
|
|
|
tools.GetLog().Log(msg);
|
2023-09-15 12:36:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|