Skip to content

Commit 13dd0a6

Browse files
committed
Moves self-updater call to starter class.
1 parent bf5bd8d commit 13dd0a6

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

ProjectPlugins/CodexContractsPlugin/CodexContractsStarter.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Core;
1+
using CodexContractsPlugin.Marketplace;
2+
using Core;
23
using GethPlugin;
34
using KubernetesWorkflow;
45
using KubernetesWorkflow.Types;
@@ -64,7 +65,8 @@ private CodexContractsDeployment DeployContract(RunningContainer container, ISta
6465

6566
var extractor = new ContractsContainerInfoExtractor(tools.GetLog(), workflow, container);
6667
var marketplaceAddress = extractor.ExtractMarketplaceAddress();
67-
var abi = extractor.ExtractMarketplaceAbi();
68+
var (abi, bytecode) = extractor.ExtractMarketplaceAbiAndByteCode();
69+
EnsureCompatbility(abi, bytecode);
6870

6971
var interaction = new ContractInteractions(tools.GetLog(), gethNode);
7072
var tokenAddress = interaction.GetTokenAddress(marketplaceAddress);
@@ -78,6 +80,18 @@ private CodexContractsDeployment DeployContract(RunningContainer container, ISta
7880
return new CodexContractsDeployment(marketplaceAddress, abi, tokenAddress);
7981
}
8082

83+
private void EnsureCompatbility(string abi, string bytecode)
84+
{
85+
var expectedByteCode = MarketplaceDeploymentBase.BYTECODE.ToLowerInvariant();
86+
87+
if (bytecode != expectedByteCode)
88+
{
89+
Log("Deployed contract is incompatible with current build of CodexContracts plugin. Running self-updater...");
90+
var selfUpdater = new SelfUpdater();
91+
selfUpdater.Update(abi, bytecode);
92+
}
93+
}
94+
8195
private void Log(string msg)
8296
{
8397
tools.GetLog().Log(msg);

ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public string ExtractMarketplaceAddress()
3131
return marketplaceAddress;
3232
}
3333

34-
public string ExtractMarketplaceAbi()
34+
public (string, string) ExtractMarketplaceAbiAndByteCode()
3535
{
3636
log.Debug();
37-
var marketplaceAbi = Retry(FetchMarketplaceAbi);
38-
if (string.IsNullOrEmpty(marketplaceAbi)) throw new InvalidOperationException("Unable to fetch marketplace artifacts from codex-contracts node. Test infra failure.");
37+
var (abi, bytecode) = Retry(FetchMarketplaceAbiAndByteCode);
38+
if (string.IsNullOrEmpty(abi)) throw new InvalidOperationException("Unable to fetch marketplace artifacts from codex-contracts node. Test infra failure.");
3939

40-
log.Debug("Got Marketplace ABI: " + marketplaceAbi);
41-
return marketplaceAbi;
40+
log.Debug("Got Marketplace ABI: " + abi);
41+
return (abi, bytecode);
4242
}
4343

4444
private string FetchMarketplaceAddress()
@@ -48,7 +48,7 @@ private string FetchMarketplaceAddress()
4848
return marketplace!.address;
4949
}
5050

51-
private string FetchMarketplaceAbi()
51+
private (string, string) FetchMarketplaceAbiAndByteCode()
5252
{
5353
var json = workflow.ExecuteCommand(container, "cat", CodexContractsContainerRecipe.MarketplaceArtifactFilename);
5454

@@ -57,20 +57,11 @@ private string FetchMarketplaceAbi()
5757
var byteCode = artifact["bytecode"];
5858
var abiResult = abi!.ToString(Formatting.None);
5959
var byteCodeResult = byteCode!.ToString(Formatting.None).ToLowerInvariant().Replace("\"", "");
60-
var expectedByteCode = MarketplaceDeploymentBase.BYTECODE.ToLowerInvariant();
61-
62-
if (byteCodeResult != expectedByteCode)
63-
{
64-
//throw new Exception("BYTECODE in CodexContractsPlugin does not match BYTECODE deployed by container. Update Marketplace.cs generated code?");
65-
66-
var selfUpdater = new SelfUpdater();
67-
selfUpdater.Update(abiResult, byteCodeResult);
68-
}
69-
70-
return abiResult;
60+
61+
return (abiResult, byteCodeResult);
7162
}
7263

73-
private static string Retry(Func<string> fetch)
64+
private static T Retry<T>(Func<T> fetch)
7465
{
7566
return Time.Retry(fetch, nameof(ContractsContainerInfoExtractor));
7667
}

0 commit comments

Comments
 (0)