diff --git a/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs b/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs index d2b5c3f0..ed54f173 100644 --- a/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs +++ b/ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs @@ -1,4 +1,5 @@ -using Core; +using CodexContractsPlugin.Marketplace; +using Core; using GethPlugin; using KubernetesWorkflow; using KubernetesWorkflow.Types; @@ -64,7 +65,8 @@ namespace CodexContractsPlugin var extractor = new ContractsContainerInfoExtractor(tools.GetLog(), workflow, container); var marketplaceAddress = extractor.ExtractMarketplaceAddress(); - var abi = extractor.ExtractMarketplaceAbi(); + var (abi, bytecode) = extractor.ExtractMarketplaceAbiAndByteCode(); + EnsureCompatbility(abi, bytecode); var interaction = new ContractInteractions(tools.GetLog(), gethNode); var tokenAddress = interaction.GetTokenAddress(marketplaceAddress); @@ -78,6 +80,18 @@ namespace CodexContractsPlugin return new CodexContractsDeployment(marketplaceAddress, abi, tokenAddress); } + private void EnsureCompatbility(string abi, string bytecode) + { + var expectedByteCode = MarketplaceDeploymentBase.BYTECODE.ToLowerInvariant(); + + if (bytecode != expectedByteCode) + { + Log("Deployed contract is incompatible with current build of CodexContracts plugin. Running self-updater..."); + var selfUpdater = new SelfUpdater(); + selfUpdater.Update(abi, bytecode); + } + } + private void Log(string msg) { tools.GetLog().Log(msg); diff --git a/ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs b/ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs index 68a789cf..0cf31528 100644 --- a/ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs +++ b/ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs @@ -31,14 +31,14 @@ namespace CodexContractsPlugin return marketplaceAddress; } - public string ExtractMarketplaceAbi() + public (string, string) ExtractMarketplaceAbiAndByteCode() { log.Debug(); - var marketplaceAbi = Retry(FetchMarketplaceAbi); - if (string.IsNullOrEmpty(marketplaceAbi)) throw new InvalidOperationException("Unable to fetch marketplace artifacts from codex-contracts node. Test infra failure."); + var (abi, bytecode) = Retry(FetchMarketplaceAbiAndByteCode); + if (string.IsNullOrEmpty(abi)) throw new InvalidOperationException("Unable to fetch marketplace artifacts from codex-contracts node. Test infra failure."); - log.Debug("Got Marketplace ABI: " + marketplaceAbi); - return marketplaceAbi; + log.Debug("Got Marketplace ABI: " + abi); + return (abi, bytecode); } private string FetchMarketplaceAddress() @@ -48,7 +48,7 @@ namespace CodexContractsPlugin return marketplace!.address; } - private string FetchMarketplaceAbi() + private (string, string) FetchMarketplaceAbiAndByteCode() { var json = workflow.ExecuteCommand(container, "cat", CodexContractsContainerRecipe.MarketplaceArtifactFilename); @@ -57,20 +57,11 @@ namespace CodexContractsPlugin var byteCode = artifact["bytecode"]; var abiResult = abi!.ToString(Formatting.None); var byteCodeResult = byteCode!.ToString(Formatting.None).ToLowerInvariant().Replace("\"", ""); - var expectedByteCode = MarketplaceDeploymentBase.BYTECODE.ToLowerInvariant(); - - if (byteCodeResult != expectedByteCode) - { - //throw new Exception("BYTECODE in CodexContractsPlugin does not match BYTECODE deployed by container. Update Marketplace.cs generated code?"); - - var selfUpdater = new SelfUpdater(); - selfUpdater.Update(abiResult, byteCodeResult); - } - - return abiResult; + + return (abiResult, byteCodeResult); } - private static string Retry(Func fetch) + private static T Retry(Func fetch) { return Time.Retry(fetch, nameof(ContractsContainerInfoExtractor)); }