GethNode interface exposes EthAddress

This commit is contained in:
thatben 2025-07-31 09:27:02 +02:00
parent a80c5c0d08
commit 9499e53bcf
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
3 changed files with 22 additions and 3 deletions

View File

@ -1,6 +1,7 @@
using BlockchainUtils;
using Logging;
using Nethereum.Web3;
using Utils;
namespace NethereumWorkflow
{
@ -27,6 +28,12 @@ namespace NethereumWorkflow
return new NethereumInteraction(log, CreateWeb3(), blockCache);
}
public EthAddress GetEthAddress()
{
var account = new Nethereum.Web3.Accounts.Account(privateKey);
return new EthAddress(account.Address);
}
private Web3 CreateWeb3()
{
var account = new Nethereum.Web3.Accounts.Account(privateKey);

View File

@ -13,6 +13,7 @@ namespace GethPlugin
public interface IGethNode : IHasContainer
{
GethDeployment StartResult { get; }
EthAddress CurrentAddress { get; }
Ether GetEthBalance();
Ether GetEthBalance(IHasEthAddress address);
@ -46,10 +47,12 @@ namespace GethPlugin
this.log = log;
this.blockCache = blockCache;
StartResult = startResult;
CurrentAddress = new EthAddress(startResult.Account.Account);
}
public GethDeployment StartResult { get; }
public RunningContainer Container => StartResult.Container;
public EthAddress CurrentAddress { get; }
public GethBootstrapNode GetBootstrapRecord()
{
@ -97,6 +100,7 @@ namespace GethPlugin
public GethDeployment StartResult => throw new NotImplementedException();
public RunningContainer Container => throw new NotImplementedException();
public EthAddress CurrentAddress { get; }
public CustomGethNode(ILog log, BlockCache blockCache, string gethHost, int gethPort, string privateKey)
{
@ -105,6 +109,9 @@ namespace GethPlugin
this.gethHost = gethHost;
this.gethPort = gethPort;
this.privateKey = privateKey;
var creator = new NethereumInteractionCreator(log, blockCache, gethHost, gethPort, privateKey);
CurrentAddress = creator.GetEthAddress();
}
public GethBootstrapNode GetBootstrapRecord()

View File

@ -1,16 +1,19 @@
using BlockchainUtils;
using Core;
using KubernetesWorkflow;
using Logging;
namespace GethPlugin
{
public class GethStarter
{
private readonly IPluginTools tools;
private readonly ILog log;
public GethStarter(IPluginTools tools)
{
this.tools = tools;
log = new LogPrefixer(tools.GetLog(), $"({nameof(GethStarter)}) ");
}
public GethDeployment StartGeth(GethStartupConfig gethStartupConfig)
@ -26,7 +29,7 @@ namespace GethPlugin
if (containers.Containers.Length != 1) throw new InvalidOperationException("Expected 1 Geth bootstrap node to be created. Test infra failure.");
var container = containers.Containers[0];
var extractor = new GethContainerInfoExtractor(tools.GetLog(), workflow, container);
var extractor = new GethContainerInfoExtractor(log, workflow, container);
var account = extractor.ExtractAccounts().Accounts.First();
var pubKey = extractor.ExtractPubKey();
@ -45,12 +48,14 @@ namespace GethPlugin
public IGethNode WrapGethContainer(GethDeployment startResult, BlockCache blockCache)
{
startResult = SerializeGate.Gate(startResult);
return new DeploymentGethNode(tools.GetLog(), blockCache, startResult);
var node = new DeploymentGethNode(tools.GetLog(), blockCache, startResult);
Log($"EthAddress: {node.CurrentAddress}");
return node;
}
private void Log(string msg)
{
tools.GetLog().Log(msg);
log.Log(msg);
}
}
}