working out marketplace details

This commit is contained in:
benbierens 2023-09-19 10:24:43 +02:00
parent 825200b386
commit a20fc6864b
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
19 changed files with 148 additions and 70 deletions

View File

@ -0,0 +1,21 @@
namespace CodexContractsPlugin
{
public interface ICodexContracts
{
string MarketplaceAddress { get; }
}
public class CodexContractsAccess : ICodexContracts
{
public CodexContractsAccess(string marketplaceAddress, string abi, string tokenAddress)
{
MarketplaceAddress = marketplaceAddress;
Abi = abi;
TokenAddress = tokenAddress;
}
public string MarketplaceAddress { get; }
public string Abi { get; }
public string TokenAddress { get; }
}
}

View File

@ -5,11 +5,11 @@ namespace CodexContractsPlugin
{ {
public class CodexContractsContainerConfig public class CodexContractsContainerConfig
{ {
public CodexContractsContainerConfig(IGethNodeInfo gethNode) public CodexContractsContainerConfig(IGethNode gethNode)
{ {
GethNode = gethNode; GethNode = gethNode;
} }
public IGethNodeInfo GethNode { get; } public IGethNode GethNode { get; }
} }
} }

View File

@ -30,7 +30,7 @@ namespace CodexContractsPlugin
{ {
} }
public IMarketplaceInfo DeployContracts(IGethNodeInfo gethNode) public ICodexContracts DeployContracts(IGethNode gethNode)
{ {
return starter.Start(gethNode); return starter.Start(gethNode);
} }

View File

@ -15,7 +15,7 @@ namespace CodexContractsPlugin
this.tools = tools; this.tools = tools;
} }
public IMarketplaceInfo Start(IGethNodeInfo gethNode) public ICodexContracts Start(IGethNode gethNode)
{ {
Log("Deploying Codex Marketplace..."); Log("Deploying Codex Marketplace...");
@ -43,7 +43,7 @@ namespace CodexContractsPlugin
Log("Extract completed. Marketplace deployed."); Log("Extract completed. Marketplace deployed.");
return new MarketplaceInfo(marketplaceAddress, abi, tokenAddress); return new CodexContractsAccess(marketplaceAddress, abi, tokenAddress);
} }
private void Log(string msg) private void Log(string msg)
@ -56,7 +56,7 @@ namespace CodexContractsPlugin
Time.WaitUntil(predicate, TimeSpan.FromMinutes(3), TimeSpan.FromSeconds(2)); Time.WaitUntil(predicate, TimeSpan.FromMinutes(3), TimeSpan.FromSeconds(2));
} }
private StartupConfig CreateStartupConfig(IGethNodeInfo gethNode) private StartupConfig CreateStartupConfig(IGethNode gethNode)
{ {
var startupConfig = new StartupConfig(); var startupConfig = new StartupConfig();
var contractsConfig = new CodexContractsContainerConfig(gethNode); var contractsConfig = new CodexContractsContainerConfig(gethNode);

View File

@ -5,7 +5,7 @@ namespace CodexContractsPlugin
{ {
public static class CoreInterfaceExtensions public static class CoreInterfaceExtensions
{ {
public static IMarketplaceInfo DeployCodexContracts(this CoreInterface ci, IGethNodeInfo gethNode) public static ICodexContracts DeployCodexContracts(this CoreInterface ci, IGethNode gethNode)
{ {
return Plugin(ci).DeployContracts(gethNode); return Plugin(ci).DeployContracts(gethNode);
} }

View File

@ -1,20 +0,0 @@
namespace CodexContractsPlugin
{
public interface IMarketplaceInfo
{
}
public class MarketplaceInfo : IMarketplaceInfo
{
public MarketplaceInfo(string address, string abi, string tokenAddress)
{
Address = address;
Abi = abi;
TokenAddress = tokenAddress;
}
public string Address { get; }
public string Abi { get; }
public string TokenAddress { get; }
}
}

View File

@ -1,17 +0,0 @@
//namespace DistTestCore.Marketplace
//{
// public class MarketplaceInitialConfig
// {
// public MarketplaceInitialConfig(Ether initialEth, TestToken initialTestTokens, bool isValidator)
// {
// InitialEth = initialEth;
// InitialTestTokens = initialTestTokens;
// IsValidator = isValidator;
// }
// public Ether InitialEth { get; }
// public TestToken InitialTestTokens { get; }
// public bool IsValidator { get; }
// public int? AccountIndexOverride { get; set; }
// }
//}

View File

@ -5,6 +5,8 @@ namespace CodexPlugin
{ {
public class CodexContainerRecipe : ContainerRecipeFactory public class CodexContainerRecipe : ContainerRecipeFactory
{ {
private readonly MarketplaceStarter marketplaceStarter = new MarketplaceStarter();
private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests"; private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests";
public const string MetricsPortTag = "metrics_port"; public const string MetricsPortTag = "metrics_port";
@ -75,26 +77,28 @@ namespace CodexPlugin
AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString()); AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString());
} }
//if (config.MarketplaceConfig != null) if (config.MarketplaceConfig != null)
//{ {
// var gethConfig = startupConfig.Get<GethStartResult>(); var mconfig = config.MarketplaceConfig;
// var companionNode = gethConfig.CompanionNode; var ip = mconfig.GethNode.RunningContainer.Pod.PodInfo.Ip;
// var companionNodeAccount = companionNode.Accounts[GetAccountIndex(config.MarketplaceConfig)]; var port = mconfig.GethNode.WsPort.Number;
// Additional(companionNodeAccount); var marketplaceAddress = mconfig.CodexContracts.MarketplaceAddress;
// var ip = companionNode.RunningContainer.Pod.PodInfo.Ip; AddEnvVar("CODEX_ETH_PROVIDER", $"ws://{ip}:{port}");
// var port = companionNode.RunningContainer.Recipe.GetPortByTag(GethContainerRecipe.HttpPortTag).Number; AddEnvVar("CODEX_MARKETPLACE_ADDRESS", marketplaceAddress);
AddEnvVar("CODEX_PERSISTENCE", "true");
// AddEnvVar("CODEX_ETH_PROVIDER", $"ws://{ip}:{port}"); // Custom scripting in the Codex test image will write this variable to a private-key file,
// AddEnvVar("CODEX_ETH_ACCOUNT", companionNodeAccount.Account); // and pass the correct filename to Codex.
// AddEnvVar("CODEX_MARKETPLACE_ADDRESS", gethConfig.MarketplaceNetwork.Marketplace.Address); var mStart = marketplaceStarter.Start();
// AddEnvVar("CODEX_PERSISTENCE", "true"); AddEnvVar("PRIV_KEY", mStart.PrivateKey);
Additional(mStart);
// if (config.MarketplaceConfig.IsValidator) if (config.MarketplaceConfig.IsValidator)
// { {
// AddEnvVar("CODEX_VALIDATOR", "true"); AddEnvVar("CODEX_VALIDATOR", "true");
// } }
//} }
AddPodLabel("codexid", Image); AddPodLabel("codexid", Image);
} }

View File

@ -11,7 +11,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CodexContractsPlugin\CodexContractsPlugin.csproj" />
<ProjectReference Include="..\Core\Core.csproj" /> <ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\GethPlugin\GethPlugin.csproj" />
<ProjectReference Include="..\KubernetesWorkflow\KubernetesWorkflow.csproj" /> <ProjectReference Include="..\KubernetesWorkflow\KubernetesWorkflow.csproj" />
<ProjectReference Include="..\MetricsPlugin\MetricsPlugin.csproj" /> <ProjectReference Include="..\MetricsPlugin\MetricsPlugin.csproj" />
<ProjectReference Include="..\Nethereum\NethereumWorkflow.csproj" /> <ProjectReference Include="..\Nethereum\NethereumWorkflow.csproj" />

View File

@ -1,4 +1,6 @@
using KubernetesWorkflow; using CodexContractsPlugin;
using GethPlugin;
using KubernetesWorkflow;
using Utils; using Utils;
namespace CodexPlugin namespace CodexPlugin
@ -14,6 +16,8 @@ namespace CodexPlugin
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration); ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks); ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
ICodexSetup EnableMetrics(); ICodexSetup EnableMetrics();
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, bool isValidator = false);
//ICodexSetup EnableMarketplace(TestToken initialBalance); //ICodexSetup EnableMarketplace(TestToken initialBalance);
//ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther); //ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther);
//ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator); //ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator);
@ -82,6 +86,12 @@ namespace CodexPlugin
return this; return this;
} }
public ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, bool isValidator = false)
{
MarketplaceConfig = new MarketplaceInitialConfig(gethNode, codexContracts, isValidator);
return this;
}
//public ICodexSetup EnableMarketplace(TestToken initialBalance) //public ICodexSetup EnableMarketplace(TestToken initialBalance)
//{ //{
// return EnableMarketplace(initialBalance, 1000.Eth()); // return EnableMarketplace(initialBalance, 1000.Eth());

View File

@ -10,7 +10,7 @@ namespace CodexPlugin
public CodexLogLevel LogLevel { get; set; } public CodexLogLevel LogLevel { get; set; }
public ByteSize? StorageQuota { get; set; } public ByteSize? StorageQuota { get; set; }
public bool MetricsEnabled { get; set; } public bool MetricsEnabled { get; set; }
//public MarketplaceInitialConfig? MarketplaceConfig { get; set; } public MarketplaceInitialConfig? MarketplaceConfig { get; set; }
public string? BootstrapSpr { get; set; } public string? BootstrapSpr { get; set; }
public int? BlockTTL { get; set; } public int? BlockTTL { get; set; }
public TimeSpan? BlockMaintenanceInterval { get; set; } public TimeSpan? BlockMaintenanceInterval { get; set; }

View File

@ -0,0 +1,31 @@
using CodexContractsPlugin;
using GethPlugin;
namespace CodexPlugin
{
public class MarketplaceInitialConfig
{
public MarketplaceInitialConfig(IGethNode gethNode, ICodexContracts codexContracts, bool isValidator)
{
GethNode = gethNode;
CodexContracts = codexContracts;
IsValidator = isValidator;
}
public IGethNode GethNode { get; }
public ICodexContracts CodexContracts { get; }
public bool IsValidator { get; }
//public MarketplaceInitialConfig(Ether initialEth, TestToken initialTestTokens, bool isValidator)
//{
// InitialEth = initialEth;
// InitialTestTokens = initialTestTokens;
// IsValidator = isValidator;
//}
//public Ether InitialEth { get; }
//public TestToken InitialTestTokens { get; }
//public bool IsValidator { get; }
//public int? AccountIndexOverride { get; set; }
}
}

View File

@ -0,0 +1,15 @@
namespace CodexPlugin
{
[Serializable]
public class MarketplaceStartResults
{
public MarketplaceStartResults(string ethAddress, string privateKey)
{
EthAddress = ethAddress;
PrivateKey = privateKey;
}
public string EthAddress { get; }
public string PrivateKey { get; }
}
}

View File

@ -0,0 +1,17 @@
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.Web3.Accounts;
namespace CodexPlugin
{
public class MarketplaceStarter
{
public MarketplaceStartResults Start()
{
var ecKey = Nethereum.Signer.EthECKey.GenerateKey();
var privateKey = ecKey.GetPrivateKeyAsBytes().ToHex();
var account = new Account(privateKey);
return new MarketplaceStartResults(account.Address, account.PrivateKey);
}
}
}

View File

@ -4,7 +4,7 @@ namespace GethPlugin
{ {
public static class CoreInterfaceExtensions public static class CoreInterfaceExtensions
{ {
public static IGethNodeInfo StartGethNode(this CoreInterface ci, Action<IGethSetup> setup) public static IGethNode StartGethNode(this CoreInterface ci, Action<IGethSetup> setup)
{ {
return Plugin(ci).StartGeth(setup); return Plugin(ci).StartGeth(setup);
} }

View File

@ -4,7 +4,7 @@ using NethereumWorkflow;
namespace GethPlugin namespace GethPlugin
{ {
public interface IGethNodeInfo public interface IGethNode
{ {
RunningContainer RunningContainer { get; } RunningContainer RunningContainer { get; }
Port DiscoveryPort { get; } Port DiscoveryPort { get; }
@ -14,9 +14,9 @@ namespace GethPlugin
NethereumInteraction StartInteraction(ILog log); NethereumInteraction StartInteraction(ILog log);
} }
public class GethNodeInfo : IGethNodeInfo public class GethNode : IGethNode
{ {
public GethNodeInfo(RunningContainer runningContainer, AllGethAccounts allAccounts, string pubKey, Port discoveryPort, Port httpPort, Port wsPort) public GethNode(RunningContainer runningContainer, AllGethAccounts allAccounts, string pubKey, Port discoveryPort, Port httpPort, Port wsPort)
{ {
RunningContainer = runningContainer; RunningContainer = runningContainer;
AllAccounts = allAccounts; AllAccounts = allAccounts;

View File

@ -30,7 +30,7 @@ namespace GethPlugin
{ {
} }
public IGethNodeInfo StartGeth(Action<IGethSetup> setup) public IGethNode StartGeth(Action<IGethSetup> setup)
{ {
var startupConfig = new GethStartupConfig(); var startupConfig = new GethStartupConfig();
setup(startupConfig); setup(startupConfig);

View File

@ -12,7 +12,7 @@ namespace GethPlugin
this.tools = tools; this.tools = tools;
} }
public IGethNodeInfo StartGeth(GethStartupConfig gethStartupConfig) public IGethNode StartGeth(GethStartupConfig gethStartupConfig)
{ {
Log("Starting Geth bootstrap node..."); Log("Starting Geth bootstrap node...");
@ -36,7 +36,7 @@ namespace GethPlugin
var wsPort = container.Recipe.GetPortByTag(GethContainerRecipe.wsPortTag); var wsPort = container.Recipe.GetPortByTag(GethContainerRecipe.wsPortTag);
if (wsPort == null) throw new Exception("Expected ws port to be created."); if (wsPort == null) throw new Exception("Expected ws port to be created.");
var result = new GethNodeInfo(container, accounts, pubKey, discoveryPort, httpPort, wsPort); var result = new GethNode(container, accounts, pubKey, discoveryPort, httpPort, wsPort);
Log($"Geth bootstrap node started with account '{result.Account.Account}'"); Log($"Geth bootstrap node started with account '{result.Account.Account}'");

View File

@ -52,6 +52,21 @@ namespace Tests.BasicTests
var contracts = Ci.DeployCodexContracts(geth); var contracts = Ci.DeployCodexContracts(geth);
var node = Ci.SetupCodexNode(s => s.EnableMarketplace(geth, contracts));
var i = 0;
//geth.SendEth(node.EthAddress, 10.Eth());
//contracts.MintTestTokens(geth, node.EthAddress, 100.TestTokens());
//geth.GetEthBalance(node.EthAddress);
//contracts.GetTestTokenBalance(geth, node.EthAddress);
//var sellerInitialBalance = 234.TestTokens(); //var sellerInitialBalance = 234.TestTokens();
//var buyerInitialBalance = 1000.TestTokens(); //var buyerInitialBalance = 1000.TestTokens();
//var fileSize = 10.MB(); //var fileSize = 10.MB();