Serialization gate requirement passed.
This commit is contained in:
parent
5fa4e0ff9f
commit
df8ab6bcf5
@ -5,32 +5,32 @@ namespace CodexContractsPlugin
|
||||
{
|
||||
public interface ICodexContracts
|
||||
{
|
||||
ICodexContractsDeployment Deployment { get; }
|
||||
CodexContractsDeployment Deployment { get; }
|
||||
|
||||
void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens);
|
||||
void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens);
|
||||
void MintTestTokens(IGethNode gethNode, EthAddress ethAddress, TestToken testTokens);
|
||||
TestToken GetTestTokenBalance(IGethNode gethNode, IHasEthAddress owner);
|
||||
TestToken GetTestTokenBalance(IGethNode gethNode, IEthAddress ethAddress);
|
||||
TestToken GetTestTokenBalance(IGethNode gethNode, EthAddress ethAddress);
|
||||
}
|
||||
|
||||
public class CodexContractsAccess : ICodexContracts
|
||||
{
|
||||
private readonly ILog log;
|
||||
|
||||
public CodexContractsAccess(ILog log, ICodexContractsDeployment deployment)
|
||||
public CodexContractsAccess(ILog log, CodexContractsDeployment deployment)
|
||||
{
|
||||
this.log = log;
|
||||
Deployment = deployment;
|
||||
}
|
||||
|
||||
public ICodexContractsDeployment Deployment { get; }
|
||||
public CodexContractsDeployment Deployment { get; }
|
||||
|
||||
public void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens)
|
||||
{
|
||||
MintTestTokens(gethNode, owner.EthAddress, testTokens);
|
||||
}
|
||||
|
||||
public void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens)
|
||||
public void MintTestTokens(IGethNode gethNode, EthAddress ethAddress, TestToken testTokens)
|
||||
{
|
||||
var interaction = new ContractInteractions(log, gethNode);
|
||||
interaction.MintTestTokens(ethAddress, testTokens.Amount, Deployment.TokenAddress);
|
||||
@ -41,7 +41,7 @@ namespace CodexContractsPlugin
|
||||
return GetTestTokenBalance(gethNode, owner.EthAddress);
|
||||
}
|
||||
|
||||
public TestToken GetTestTokenBalance(IGethNode gethNode, IEthAddress ethAddress)
|
||||
public TestToken GetTestTokenBalance(IGethNode gethNode, EthAddress ethAddress)
|
||||
{
|
||||
var interaction = new ContractInteractions(log, gethNode);
|
||||
var balance = interaction.GetBalance(Deployment.TokenAddress, ethAddress.Address);
|
||||
|
@ -1,13 +1,6 @@
|
||||
namespace CodexContractsPlugin
|
||||
{
|
||||
public interface ICodexContractsDeployment
|
||||
{
|
||||
string MarketplaceAddress { get; }
|
||||
string Abi { get; }
|
||||
string TokenAddress { get; }
|
||||
}
|
||||
|
||||
public class CodexContractsDeployment : ICodexContractsDeployment
|
||||
public class CodexContractsDeployment
|
||||
{
|
||||
public CodexContractsDeployment(string marketplaceAddress, string abi, string tokenAddress)
|
||||
{
|
||||
|
@ -30,14 +30,15 @@ namespace CodexContractsPlugin
|
||||
{
|
||||
}
|
||||
|
||||
public ICodexContractsDeployment DeployContracts(IGethNode gethNode)
|
||||
public CodexContractsDeployment DeployContracts(IGethNode gethNode)
|
||||
{
|
||||
return starter.Deploy(gethNode);
|
||||
}
|
||||
|
||||
public ICodexContracts WrapDeploy(ICodexContractsDeployment deployment)
|
||||
public ICodexContracts WrapDeploy(CodexContractsDeployment deployment)
|
||||
{
|
||||
return starter.Wrap(SerializeGate.Gate(deployment));
|
||||
deployment = SerializeGate.Gate(deployment);
|
||||
return starter.Wrap(deployment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace CodexContractsPlugin
|
||||
this.tools = tools;
|
||||
}
|
||||
|
||||
public ICodexContractsDeployment Deploy(IGethNode gethNode)
|
||||
public CodexContractsDeployment Deploy(IGethNode gethNode)
|
||||
{
|
||||
Log("Deploying Codex SmartContracts...");
|
||||
|
||||
@ -50,7 +50,7 @@ namespace CodexContractsPlugin
|
||||
return new CodexContractsDeployment(marketplaceAddress, abi, tokenAddress);
|
||||
}
|
||||
|
||||
public ICodexContracts Wrap(ICodexContractsDeployment deployment)
|
||||
public ICodexContracts Wrap(CodexContractsDeployment deployment)
|
||||
{
|
||||
return new CodexContractsAccess(tools.GetLog(), deployment);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace CodexContractsPlugin
|
||||
return gethNode.Call<GetTokenFunction, string>(marketplaceAddress, function);
|
||||
}
|
||||
|
||||
public void MintTestTokens(IEthAddress address, decimal amount, string tokenAddress)
|
||||
public void MintTestTokens(EthAddress address, decimal amount, string tokenAddress)
|
||||
{
|
||||
MintTokens(address.Address, amount, tokenAddress);
|
||||
}
|
||||
|
@ -5,12 +5,12 @@ namespace CodexContractsPlugin
|
||||
{
|
||||
public static class CoreInterfaceExtensions
|
||||
{
|
||||
public static ICodexContractsDeployment DeployCodexContracts(this CoreInterface ci, IGethNode gethNode)
|
||||
public static CodexContractsDeployment DeployCodexContracts(this CoreInterface ci, IGethNode gethNode)
|
||||
{
|
||||
return Plugin(ci).DeployContracts(gethNode);
|
||||
}
|
||||
|
||||
public static ICodexContracts WrapCodexContractsDeployment(this CoreInterface ci, ICodexContractsDeployment deployment)
|
||||
public static ICodexContracts WrapCodexContractsDeployment(this CoreInterface ci, CodexContractsDeployment deployment)
|
||||
{
|
||||
return Plugin(ci).WrapDeploy(deployment);
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ namespace CodexPlugin
|
||||
private const string SuccessfullyConnectedMessage = "Successfully connected to peer";
|
||||
private const string UploadFailedMessage = "Unable to store block";
|
||||
private readonly IPluginTools tools;
|
||||
private readonly IEthAddress? ethAddress;
|
||||
private readonly EthAddress? ethAddress;
|
||||
|
||||
public CodexNode(IPluginTools tools, CodexAccess codexAccess, CodexNodeGroup group, IMarketplaceAccess marketplaceAccess, IEthAddress? ethAddress)
|
||||
public CodexNode(IPluginTools tools, CodexAccess codexAccess, CodexNodeGroup group, IMarketplaceAccess marketplaceAccess, EthAddress? ethAddress)
|
||||
{
|
||||
this.tools = tools;
|
||||
this.ethAddress = ethAddress;
|
||||
@ -53,7 +53,7 @@ namespace CodexPlugin
|
||||
return new MetricsScrapeTarget(CodexAccess.Container, port);
|
||||
}
|
||||
}
|
||||
public IEthAddress EthAddress
|
||||
public EthAddress EthAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -24,15 +24,15 @@ namespace CodexPlugin
|
||||
return new CodexNode(tools, access, group, marketplaceAccess, ethAddress);
|
||||
}
|
||||
|
||||
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, IEthAddress? ethAddress)
|
||||
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, EthAddress? ethAddress)
|
||||
{
|
||||
if (ethAddress == null) return new MarketplaceUnavailable();
|
||||
return new MarketplaceAccess(tools.GetLog(), codexAccess);
|
||||
}
|
||||
|
||||
private IEthAddress? GetEthAddress(CodexAccess access)
|
||||
private EthAddress? GetEthAddress(CodexAccess access)
|
||||
{
|
||||
var mStart = access.Container.Recipe.Additionals.SingleOrDefault(a => a is MarketplaceStartResults) as MarketplaceStartResults;
|
||||
var mStart = access.Container.Recipe.Additionals.Get<MarketplaceStartResults>();
|
||||
if (mStart == null) return null;
|
||||
return mStart.EthAddress;
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ namespace CodexPlugin
|
||||
|
||||
public ICodexNodeGroup WrapCodexContainers(CoreInterface coreInterface, RunningContainers[] containers)
|
||||
{
|
||||
var cs = containers.Select(c => SerializeGate.Gate(c)).ToArray();
|
||||
return codexStarter.WrapCodexContainers(coreInterface, cs);
|
||||
containers = containers.Select(c => SerializeGate.Gate(c)).ToArray();
|
||||
return codexStarter.WrapCodexContainers(coreInterface, containers);
|
||||
}
|
||||
|
||||
public void WireUpMarketplace(ICodexNodeGroup result, Action<ICodexSetup> setup)
|
||||
|
@ -5,13 +5,13 @@ namespace CodexPlugin
|
||||
[Serializable]
|
||||
public class MarketplaceStartResults
|
||||
{
|
||||
public MarketplaceStartResults(IEthAddress ethAddress, string privateKey)
|
||||
public MarketplaceStartResults(EthAddress ethAddress, string privateKey)
|
||||
{
|
||||
EthAddress = ethAddress;
|
||||
PrivateKey = privateKey;
|
||||
}
|
||||
|
||||
public IEthAddress EthAddress { get; }
|
||||
public EthAddress EthAddress { get; }
|
||||
public string PrivateKey { get; }
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,13 @@ namespace Core
|
||||
{
|
||||
public static class SerializeGate
|
||||
{
|
||||
/// <summary>
|
||||
/// SerializeGate was added to help ensure deployment objects are serializable
|
||||
/// and remain viable after deserialization.
|
||||
/// Tools can be built on top of the core interface that rely on deployment objects being serializable.
|
||||
/// Insert the serialization gate after deployment but before wrapping to ensure any future changes
|
||||
/// don't break this requirement.
|
||||
/// </summary>
|
||||
public static T Gate<T>(T anything)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(anything);
|
||||
|
@ -4,12 +4,12 @@ namespace GethPlugin
|
||||
{
|
||||
public static class CoreInterfaceExtensions
|
||||
{
|
||||
public static IGethDeployment DeployGeth(this CoreInterface ci, Action<IGethSetup> setup)
|
||||
public static GethDeployment DeployGeth(this CoreInterface ci, Action<IGethSetup> setup)
|
||||
{
|
||||
return Plugin(ci).DeployGeth(setup);
|
||||
}
|
||||
|
||||
public static IGethNode WrapGethDeployment(this CoreInterface ci, IGethDeployment deployment)
|
||||
public static IGethNode WrapGethDeployment(this CoreInterface ci, GethDeployment deployment)
|
||||
{
|
||||
return Plugin(ci).WrapGethDeployment(deployment);
|
||||
}
|
||||
|
@ -1,16 +1,11 @@
|
||||
namespace GethPlugin
|
||||
{
|
||||
public interface IEthAddress
|
||||
{
|
||||
string Address { get; }
|
||||
}
|
||||
|
||||
public interface IHasEthAddress
|
||||
{
|
||||
IEthAddress EthAddress { get; }
|
||||
EthAddress EthAddress { get; }
|
||||
}
|
||||
|
||||
public class EthAddress : IEthAddress
|
||||
public class EthAddress
|
||||
{
|
||||
public EthAddress(string address)
|
||||
{
|
||||
|
@ -2,17 +2,7 @@
|
||||
|
||||
namespace GethPlugin
|
||||
{
|
||||
public interface IGethDeployment
|
||||
{
|
||||
RunningContainer RunningContainer { get; }
|
||||
Port DiscoveryPort { get; }
|
||||
Port HttpPort { get; }
|
||||
Port WsPort { get; }
|
||||
AllGethAccounts AllAccounts { get; }
|
||||
string PubKey { get; }
|
||||
}
|
||||
|
||||
public class GethDeployment : IGethDeployment
|
||||
public class GethDeployment
|
||||
{
|
||||
public GethDeployment(RunningContainer runningContainer, Port discoveryPort, Port httpPort, Port wsPort, AllGethAccounts allAccounts, string pubKey)
|
||||
{
|
||||
|
@ -6,13 +6,13 @@ namespace GethPlugin
|
||||
{
|
||||
public interface IGethNode
|
||||
{
|
||||
IGethDeployment StartResult { get; }
|
||||
GethDeployment StartResult { get; }
|
||||
|
||||
Ether GetEthBalance();
|
||||
Ether GetEthBalance(IHasEthAddress address);
|
||||
Ether GetEthBalance(IEthAddress address);
|
||||
Ether GetEthBalance(EthAddress address);
|
||||
void SendEth(IHasEthAddress account, Ether eth);
|
||||
void SendEth(IEthAddress account, Ether eth);
|
||||
void SendEth(EthAddress account, Ether eth);
|
||||
TResult Call<TFunction, TResult>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new();
|
||||
void SendTransaction<TFunction>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new();
|
||||
decimal? GetSyncedBlockNumber();
|
||||
@ -23,14 +23,14 @@ namespace GethPlugin
|
||||
{
|
||||
private readonly ILog log;
|
||||
|
||||
public GethNode(ILog log, IGethDeployment startResult)
|
||||
public GethNode(ILog log, GethDeployment startResult)
|
||||
{
|
||||
this.log = log;
|
||||
StartResult = startResult;
|
||||
Account = startResult.AllAccounts.Accounts.First();
|
||||
}
|
||||
|
||||
public IGethDeployment StartResult { get; }
|
||||
public GethDeployment StartResult { get; }
|
||||
public GethAccount Account { get; }
|
||||
|
||||
public Ether GetEthBalance()
|
||||
@ -43,7 +43,7 @@ namespace GethPlugin
|
||||
return GetEthBalance(owner.EthAddress);
|
||||
}
|
||||
|
||||
public Ether GetEthBalance(IEthAddress address)
|
||||
public Ether GetEthBalance(EthAddress address)
|
||||
{
|
||||
return StartInteraction().GetEthBalance(address.Address).Eth();
|
||||
}
|
||||
@ -53,7 +53,7 @@ namespace GethPlugin
|
||||
SendEth(owner.EthAddress, eth);
|
||||
}
|
||||
|
||||
public void SendEth(IEthAddress account, Ether eth)
|
||||
public void SendEth(EthAddress account, Ether eth)
|
||||
{
|
||||
StartInteraction().SendEth(account.Address, eth.Eth);
|
||||
}
|
||||
|
@ -29,16 +29,17 @@ namespace GethPlugin
|
||||
{
|
||||
}
|
||||
|
||||
public IGethDeployment DeployGeth(Action<IGethSetup> setup)
|
||||
public GethDeployment DeployGeth(Action<IGethSetup> setup)
|
||||
{
|
||||
var startupConfig = new GethStartupConfig();
|
||||
setup(startupConfig);
|
||||
return starter.StartGeth(startupConfig);
|
||||
}
|
||||
|
||||
public IGethNode WrapGethDeployment(IGethDeployment startResult)
|
||||
public IGethNode WrapGethDeployment(GethDeployment startResult)
|
||||
{
|
||||
return starter.WrapGethContainer(SerializeGate.Gate(startResult));
|
||||
startResult = SerializeGate.Gate(startResult);
|
||||
return starter.WrapGethContainer(startResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace GethPlugin
|
||||
this.tools = tools;
|
||||
}
|
||||
|
||||
public IGethDeployment StartGeth(GethStartupConfig gethStartupConfig)
|
||||
public GethDeployment StartGeth(GethStartupConfig gethStartupConfig)
|
||||
{
|
||||
Log("Starting Geth bootstrap node...");
|
||||
|
||||
@ -41,9 +41,10 @@ namespace GethPlugin
|
||||
return new GethDeployment(container, discoveryPort, httpPort, wsPort, accounts, pubKey);
|
||||
}
|
||||
|
||||
public IGethNode WrapGethContainer(IGethDeployment startResult)
|
||||
public IGethNode WrapGethContainer(GethDeployment startResult)
|
||||
{
|
||||
return new GethNode(tools.GetLog(), SerializeGate.Gate(startResult));
|
||||
startResult = SerializeGate.Gate(startResult);
|
||||
return new GethNode(tools.GetLog(), startResult);
|
||||
}
|
||||
|
||||
private void Log(string msg)
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace KubernetesWorkflow
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace KubernetesWorkflow
|
||||
{
|
||||
public class Configuration
|
||||
{
|
||||
@ -16,6 +18,8 @@
|
||||
public string KubernetesNamespace { get; }
|
||||
public bool AllowNamespaceOverride { get; set; } = true;
|
||||
public bool AddAppPodLabel { get; set; } = true;
|
||||
|
||||
[JsonIgnore]
|
||||
public IK8sHooks Hooks { get; set; } = new DoNothingK8sHooks();
|
||||
}
|
||||
}
|
||||
|
53
KubernetesWorkflow/ContainerAdditionals.cs
Normal file
53
KubernetesWorkflow/ContainerAdditionals.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace KubernetesWorkflow
|
||||
{
|
||||
public class ContainerAdditionals
|
||||
{
|
||||
public ContainerAdditionals(Additional[] additionals)
|
||||
{
|
||||
Additionals = additionals;
|
||||
}
|
||||
|
||||
public static ContainerAdditionals CreateFromUserData(IEnumerable<object> userData)
|
||||
{
|
||||
return new ContainerAdditionals(userData.Select(ConvertToAdditional).ToArray());
|
||||
}
|
||||
|
||||
public Additional[] Additionals { get; }
|
||||
|
||||
public T? Get<T>()
|
||||
{
|
||||
var typeName = GetTypeName(typeof(T));
|
||||
var userData = Additionals.SingleOrDefault(a => a.Type == typeName);
|
||||
if (userData == null) return default(T);
|
||||
var jobject = (JObject)userData.UserData;
|
||||
return jobject.ToObject<T>();
|
||||
}
|
||||
|
||||
private static Additional ConvertToAdditional(object userData)
|
||||
{
|
||||
var typeName = GetTypeName(userData.GetType());
|
||||
return new Additional(typeName, userData);
|
||||
}
|
||||
|
||||
private static string GetTypeName(Type type)
|
||||
{
|
||||
var typeName = type.FullName;
|
||||
if (string.IsNullOrEmpty(typeName)) throw new Exception("Object type fullname is null or empty: " + type);
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
|
||||
public class Additional
|
||||
{
|
||||
public Additional(string type, object userData)
|
||||
{
|
||||
Type = type;
|
||||
UserData = userData;
|
||||
}
|
||||
|
||||
public string Type { get; }
|
||||
public object UserData { get; }
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
public class ContainerRecipe
|
||||
{
|
||||
public ContainerRecipe(int number, string? nameOverride, string image, ContainerResources resources, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, object[] additionals)
|
||||
public ContainerRecipe(int number, string? nameOverride, string image, ContainerResources resources, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, ContainerAdditionals additionals)
|
||||
{
|
||||
Number = number;
|
||||
NameOverride = nameOverride;
|
||||
@ -37,7 +37,7 @@
|
||||
public PodLabels PodLabels { get; }
|
||||
public PodAnnotations PodAnnotations { get; }
|
||||
public VolumeMount[] Volumes { get; }
|
||||
public object[] Additionals { get; }
|
||||
public ContainerAdditionals Additionals { get; }
|
||||
|
||||
public Port? GetPortByTag(string tag)
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ namespace KubernetesWorkflow
|
||||
podLabels.Clone(),
|
||||
podAnnotations.Clone(),
|
||||
volumeMounts.ToArray(),
|
||||
additionals.ToArray());
|
||||
ContainerAdditionals.CreateFromUserData(additionals));
|
||||
|
||||
exposedPorts.Clear();
|
||||
internalPorts.Clear();
|
||||
|
@ -38,7 +38,8 @@ namespace MetricsPlugin
|
||||
|
||||
public IMetricsAccess WrapMetricsCollectorDeployment(RunningContainer runningContainer, IMetricsScrapeTarget target)
|
||||
{
|
||||
return starter.CreateAccessForTarget(SerializeGate.Gate(runningContainer), target);
|
||||
runningContainer = SerializeGate.Gate(runningContainer);
|
||||
return starter.CreateAccessForTarget(runningContainer, target);
|
||||
}
|
||||
|
||||
public LogFile? DownloadAllMetrics(IMetricsAccess metricsAccess, string targetName)
|
||||
|
Loading…
x
Reference in New Issue
Block a user