cs-codex-dist-tests/GethPlugin/GethNode.cs

68 lines
1.8 KiB
C#
Raw Normal View History

2023-09-19 09:51:59 +00:00
using Logging;
2023-09-15 14:27:08 +00:00
using NethereumWorkflow;
2023-09-15 13:52:02 +00:00
namespace GethPlugin
{
2023-09-19 08:24:43 +00:00
public interface IGethNode
2023-09-15 13:52:02 +00:00
{
2023-09-19 09:51:59 +00:00
IGethStartResult StartResult { get; }
2023-09-15 14:27:08 +00:00
2023-09-19 09:51:59 +00:00
NethereumInteraction StartInteraction();
Ether GetEthBalance();
Ether GetEthBalance(IHasEthAddress address);
Ether GetEthBalance(IEthAddress address);
void SendEth(IHasEthAddress account, Ether eth);
void SendEth(IEthAddress account, Ether eth);
2023-09-15 13:52:02 +00:00
}
2023-09-19 08:24:43 +00:00
public class GethNode : IGethNode
2023-09-15 13:52:02 +00:00
{
2023-09-19 09:51:59 +00:00
private readonly ILog log;
public GethNode(ILog log, IGethStartResult startResult)
2023-09-15 13:52:02 +00:00
{
2023-09-19 09:51:59 +00:00
this.log = log;
StartResult = startResult;
Account = startResult.AllAccounts.Accounts.First();
2023-09-15 13:52:02 +00:00
}
2023-09-19 09:51:59 +00:00
public IGethStartResult StartResult { get; }
2023-09-15 13:52:02 +00:00
public GethAccount Account { get; }
2023-09-19 09:51:59 +00:00
public NethereumInteraction StartInteraction()
2023-09-15 14:27:08 +00:00
{
2023-09-19 09:51:59 +00:00
var address = StartResult.RunningContainer.Address;
2023-09-15 14:27:08 +00:00
var account = Account;
2023-09-15 13:52:02 +00:00
2023-09-15 14:27:08 +00:00
var creator = new NethereumInteractionCreator(log, address.Host, address.Port, account.PrivateKey);
return creator.CreateWorkflow();
}
2023-09-19 09:51:59 +00:00
public Ether GetEthBalance()
{
return StartInteraction().GetEthBalance().Eth();
}
public Ether GetEthBalance(IHasEthAddress owner)
{
return GetEthBalance(owner.EthAddress);
}
public Ether GetEthBalance(IEthAddress address)
{
return StartInteraction().GetEthBalance(address.Address).Eth();
}
public void SendEth(IHasEthAddress owner, Ether eth)
{
SendEth(owner.EthAddress, eth);
}
public void SendEth(IEthAddress account, Ether eth)
{
var i = StartInteraction();
i.SendEth(account.Address, eth.Eth);
}
2023-09-15 13:52:02 +00:00
}
}