Skip to content

Commit

Permalink
Can compile contracts using JSON input.
Browse files Browse the repository at this point in the history
  • Loading branch information
allisterb committed Nov 24, 2024
1 parent 2fcaf96 commit 541101f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
26 changes: 21 additions & 5 deletions src/Stratis.VS.SolidityProjectBuildTasks/CompileContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Diagnostics;
using System.IO;
using System.Linq;


using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand Down Expand Up @@ -42,9 +44,19 @@ public override bool Execute()
var i = new SolidityCompilerInput()
{
Language = "Solidity",

Sources = Contracts.ToDictionary(k => k.GetMetadata("Name"), v => new Source() { Urls = new[] { v.ItemSpec } })

Settings = new Settings()
{
EvmVersion = "byzantium",
OutputSelection = new Dictionary<string, Dictionary<string, string[]>>()
{
{"*", new Dictionary<string, string[]>()
{
{"*", new [] {"evm.bytecode" } }
}
}
}
},
Sources = Contracts.ToDictionary(k => k.GetMetadata("Filename"), v => new Source() { Urls = new[] { Path.Combine(v.GetMetadata("RelativeDir"), v.ItemSpec) } })
};

if (!p.Start())
Expand All @@ -56,8 +68,12 @@ public override bool Execute()
ser.Serialize(p.StandardInput, i);
p.StandardInput.WriteLine(Environment.NewLine);
p.StandardInput.Close();
Log.LogMessage(MessageImportance.High, p.StandardOutput.ReadToEnd());
return false;
Log.LogMessage(MessageImportance.High, p.StandardOutput.ReadToEnd());
if (!p.HasExited)
{
p.Kill();
}
return true;
}
}
}
28 changes: 4 additions & 24 deletions src/Stratis.VS.SolidityProjectBuildTasks/SolidityCompilerIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public partial class SolidityCompilerInput
[JsonProperty("sources")]
public Dictionary<string, Source> Sources { get; set; }

[JsonProperty("settings")]
[JsonProperty("settings", NullValueHandling = NullValueHandling.Ignore)]

public Settings Settings { get; set; }
}

[JsonObject(MissingMemberHandling = MissingMemberHandling.Ignore, ItemNullValueHandling = NullValueHandling.Ignore)]
public partial class Settings
{
[JsonProperty("remappings")]
Expand All @@ -37,7 +39,7 @@ public partial class Settings
public Dictionary<string, string> Libraries { get; set; }

[JsonProperty("outputSelection")]
public OutputSelection OutputSelection { get; set; }
public Dictionary<string, Dictionary<string, string[]>> OutputSelection { get; set; }
}

public partial class Metadata
Expand All @@ -55,28 +57,6 @@ public partial class Optimizer
public long Runs { get; set; }
}

public partial class OutputSelection
{
[JsonProperty("*")]
public Empty Empty { get; set; }

[JsonProperty("def")]
public Def Def { get; set; }
}

public partial class Def
{
[JsonProperty("MyContract")]
public string[] MyContract { get; set; }
}

public partial class Empty
{
[JsonProperty("")]
public string[] Purple { get; set; }
}


public partial class Source
{
[JsonProperty("keccak256")]
Expand Down

0 comments on commit 541101f

Please sign in to comment.