Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request company-projects/Meadow!60
  • Loading branch information
zone117x committed Oct 30, 2018
2 parents f6ccdb5 + ac4c74d commit 689fd21
Show file tree
Hide file tree
Showing 45 changed files with 1,351 additions and 315 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,5 @@ src/coverage/
src/report/
src/reportgenerator/
src/Meadow.VSCode.Debugger/solidity-debugger*.vsix
**/*/.meadow-generated/
**/*.debugSolSourcesTool/
2 changes: 1 addition & 1 deletion src/Meadow.Cli/Meadow.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="ExposedObject" Version="1.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.1.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.1.0" />
<PackageReference Include="Secp256k1.Native" Version="0.1.18" />
<PackageReference Include="Secp256k1.Native" Version="0.1.18" ExcludeAssets="native" />
<PackageReference Include="Secp256k1.Net" Version="0.1.48" />
</ItemGroup>

Expand Down
26 changes: 20 additions & 6 deletions src/Meadow.Contract/BaseContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,26 @@ public interface IContractInstanceSetup

string ContractSolFilePath { get; }
string ContractName { get; }
string ContractBytecodeHash { get; }
string ContractBytecodeDeployedHash { get; }
}

public class ContractInstance : BaseContract
{
protected override string ContractSolFilePath { get; }

protected override string ContractName { get; }

public ContractInstance(
string contractSolFilePath, string contractName,
IJsonRpcClient rpcClient, Address contractAddress, Address defaultFromAccount)
: base(rpcClient, contractAddress, defaultFromAccount)
{
ContractAddress = contractAddress;
DefaultFromAccount = defaultFromAccount;
JsonRpcClient = rpcClient;

ContractSolFilePath = contractSolFilePath;
ContractName = contractName;
}
}

public abstract class BaseContract : IContractInstanceSetup
Expand All @@ -46,13 +64,9 @@ public abstract class BaseContract : IContractInstanceSetup

protected abstract string ContractSolFilePath { get; }
protected abstract string ContractName { get; }
protected abstract string ContractBytecodeHash { get; }
protected abstract string ContractBytecodeDeployedHash { get; }

string IContractInstanceSetup.ContractSolFilePath => ContractSolFilePath;
string IContractInstanceSetup.ContractName => ContractName;
string IContractInstanceSetup.ContractBytecodeHash => ContractBytecodeHash;
string IContractInstanceSetup.ContractBytecodeDeployedHash => ContractBytecodeDeployedHash;

public BaseContract(IJsonRpcClient rpcClient, Address contractAddress, Address defaultFromAccount) : this()
{
Expand Down
6 changes: 2 additions & 4 deletions src/Meadow.Contract/ContractDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Meadow.Contract
{
public class ContractDeployer<TContract> where TContract : IContractInstanceSetup, new()
{
readonly SolidityContractAttribute _contractAttribute;
readonly IJsonRpcClient _rpcClient;
readonly byte[] _bytecode;
readonly TransactionParams _transactionParams;
Expand All @@ -25,7 +24,6 @@ public class ContractDeployer<TContract> where TContract : IContractInstanceSetu
Address? defaultFromAccount,
ReadOnlyMemory<byte> abiEncodedConstructorArgs = default)
{
_contractAttribute = TypeAttributeCache<TContract, SolidityContractAttribute>.Attribute;
_rpcClient = rpcClient;
_bytecode = bytecode;
_transactionParams = transactionParams;
Expand All @@ -49,7 +47,7 @@ async Task<TransactionParams> GetTransactionParams()
public async Task<TContract> Deploy()
{
var txParams = await GetTransactionParams();
var contractAddr = await ContractFactory.Deploy(_contractAttribute, _rpcClient, _bytecode, txParams, _abiEncodedConstructorArgs);
var contractAddr = await ContractFactory.Deploy(_rpcClient, _bytecode, txParams, _abiEncodedConstructorArgs);
var contractInstance = new TContract();
contractInstance.Setup(_rpcClient, contractAddr, _defaultFromAccount ?? txParams.From.Value);
return contractInstance;
Expand All @@ -62,7 +60,7 @@ public async Task<TContract> Deploy()
public async Task ExpectRevert()
{
var txParams = await GetTransactionParams();
(JsonRpcError error, Hash transactionHash) = await ContractFactory.TryDeploy(expectException: true, _contractAttribute, _rpcClient, _bytecode, txParams, _abiEncodedConstructorArgs);
(JsonRpcError error, Hash transactionHash) = await ContractFactory.TryDeploy(expectException: true, _rpcClient, _bytecode, txParams, _abiEncodedConstructorArgs);

if (error == null)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Meadow.Contract/ContractFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ public static class ContractFactory
/// </summary>
/// <param name="abiEncodedConstructorArgs">ABI encoded function selector and constructor parameters</param>
public static async Task<Address> Deploy(
SolidityContractAttribute contractAttribute,
IJsonRpcClient rpcClient,
byte[] bytecode,
TransactionParams sendParams,
ReadOnlyMemory<byte> abiEncodedConstructorArgs = default)
{
(JsonRpcError error, Hash transactionHash) = await TryDeploy(expectException: false, contractAttribute, rpcClient, bytecode, sendParams, abiEncodedConstructorArgs);
(JsonRpcError error, Hash transactionHash) = await TryDeploy(expectException: false, rpcClient, bytecode, sendParams, abiEncodedConstructorArgs);
if (error != null)
{
if (rpcClient.ErrorFormatter != null)
Expand Down Expand Up @@ -63,7 +62,6 @@ public static class ContractFactory

public static async Task<(JsonRpcError Error, Hash TransactionHash)> TryDeploy(
bool expectException,
SolidityContractAttribute contractAttribute,
IJsonRpcClient rpcClient,
byte[] bytecode,
TransactionParams sendParams,
Expand Down
33 changes: 26 additions & 7 deletions src/Meadow.Contract/GeneratedSolcData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Meadow.Core.Utils;
using Meadow.JsonRpc.Types.Debugging;
using Newtonsoft.Json;
using SolcNet.DataDescription.Output;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -37,7 +38,7 @@ public class GeneratedSolcData
readonly Lazy<SolcBytecodeInfo[]> _solcBytecodeInfo;
readonly Lazy<SolcSourceInfo[]> _solcSourceInfo;
readonly Lazy<string> _solidityCompilerVersion;
readonly Lazy<Dictionary<string, SolcNet.DataDescription.Output.Abi[]>> _contractAbis;
readonly Lazy<Dictionary<(string FilePath, string ContractName), SolcNet.DataDescription.Output.Abi[]>> _contractAbis;

public SolcBytecodeInfo[] SolcBytecodeInfo => _solcBytecodeInfo.Value;
public SolcSourceInfo[] SolcSourceInfo => _solcSourceInfo.Value;
Expand Down Expand Up @@ -94,7 +95,7 @@ private GeneratedSolcData(Assembly assembly = null)
_solcBytecodeInfo = new Lazy<SolcBytecodeInfo[]>(GetSolcBytecodeInfo);
_solcSourceInfo = new Lazy<SolcSourceInfo[]>(GetSolcSourceInfo);
_solidityCompilerVersion = new Lazy<string>(GetSolidityCompilerVersion);
_contractAbis = new Lazy<Dictionary<string, SolcNet.DataDescription.Output.Abi[]>>(GetContractAbiJson);
_contractAbis = new Lazy<Dictionary<(string FilePath, string ContractName), SolcNet.DataDescription.Output.Abi[]>>(GetContractAbiJson);
}

public ResourceManager GetResourceManager()
Expand Down Expand Up @@ -138,20 +139,38 @@ string GetSolidityCompilerVersion()
return ver;
}

Dictionary<string, SolcNet.DataDescription.Output.Abi[]> GetContractAbiJson()
Dictionary<(string FilePath, string ContractName), SolcNet.DataDescription.Output.Abi[]> GetContractAbiJson()
{
var resourceManager = _resourceManager.Value;
var ver = resourceManager.GetString("ContractAbiJson", CultureInfo.InvariantCulture);
var json = JsonConvert.DeserializeObject<Dictionary<string, SolcNet.DataDescription.Output.Abi[]>>(ver);
return json;
var dict = JsonConvert.DeserializeObject<Dictionary<string, SolcNet.DataDescription.Output.Abi[]>>(ver);
var formatted = dict.ToDictionary(
k =>
{
// Parse full contract path format "{relative file path}/{contract name}"
// Example: "SomeDir/SomeFile.sol/SomeContract"
var pathIndex = k.Key.LastIndexOf('/');
var filePath = k.Key.Substring(0, pathIndex);
var contractName = k.Key.Substring(pathIndex + 1);
return (filePath, contractName);
}, k => k.Value);
return formatted;
}

public SolcNet.DataDescription.Output.Abi[] GetContractJsonAbi(string solFile, string contractName)
public Abi[] GetContractJsonAbi(string solFile, string contractName)
{
var abi = _contractAbis.Value[solFile + "/" + contractName];
var abi = _contractAbis.Value[(solFile, contractName)];
return abi;
}

public Abi[] GetContractJsonAbi<TContract>() where TContract : BaseContract
{
var contractAttr = TypeAttributeCache<TContract, SolidityContractAttribute>.Attribute;
return GetContractJsonAbi(contractAttr.FilePath, contractAttr.ContractName);
}

public IReadOnlyDictionary<(string FilePath, string ContractName), SolcNet.DataDescription.Output.Abi[]> ContractAbis => _contractAbis.Value;

ConcurrentDictionary<(string CodeHex, bool IsDeployed), SolcBytecodeInfo> _codeHexCache = new ConcurrentDictionary<(string CodeHex, bool IsDeployed), SolcBytecodeInfo>();

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/Meadow.Contract/GeneratedSolcDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ namespace Meadow.Contract
[AttributeUsage(AttributeTargets.Assembly)]
public class GeneratedSolcDataAttribute : Attribute
{
public GeneratedSolcDataAttribute()
public readonly string SolCodeBaseHash;

public GeneratedSolcDataAttribute(string solCodeBaseHash)
{
SolCodeBaseHash = solCodeBaseHash;
}


}

}
6 changes: 0 additions & 6 deletions src/Meadow.Contract/SolcBytecodeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ public class SolcBytecodeInfo
[JsonProperty("bytecodeDeployed")]
public string BytecodeDeployed { get; set; }

[JsonProperty("bytecodeHash")]
public string BytecodeHash { get; set; }

[JsonProperty("bytecodeDeployedHash")]
public string BytecodeDeployedHash { get; set; }

public SolcBytecodeInfo()
{

Expand Down
6 changes: 1 addition & 5 deletions src/Meadow.Contract/SolidityContractAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ public class SolidityContractAttribute : Attribute
public readonly Type ContractType;
public readonly string FilePath;
public readonly string ContractName;
public readonly string BytecodeHash;
public readonly string BytecodeDeployedHash;

public SolidityContractAttribute(Type contractType, string filePath, string contractName, string bytecodeHash, string bytecodeDeployedHash)
public SolidityContractAttribute(Type contractType, string filePath, string contractName)
{
ContractType = contractType;
FilePath = filePath;
ContractName = contractName;
BytecodeHash = bytecodeHash;
BytecodeDeployedHash = bytecodeDeployedHash;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public SourceFileLine[] GetSourceLines(SourceMapEntry sourceMapEntry)
}

// Find the solc output for this contract address
var bytecodeInfo = _solcData.SolcBytecodeInfo.Single(s => s.FilePath == info.FilePath && s.ContractName == info.ContractName && s.BytecodeDeployedHash == info.BytecodeDeployedHash);
var bytecodeInfo = _solcData.SolcBytecodeInfo.Single(s => s.FilePath == info.FilePath && s.ContractName == info.ContractName && s.BytecodeDeployed.Equals(info.BytecodeDeployed, StringComparison.Ordinal));

// Parse the opcode string to do offset to index number lookups
var opcodes = tracepoint.ContractDeployed ? bytecodeInfo.OpcodesDeployed : bytecodeInfo.Opcodes;
Expand Down
4 changes: 2 additions & 2 deletions src/Meadow.CoverageReport/ReportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public static class ReportGenerator
foreach (var (coverageMap, contractInst) in coverageMaps)
{
// Find the sourcemap matching this contract file name and contract name.
var sourceMapNonDeployed = analysis.SourceMaps[(contractInst.FilePath, contractInst.ContractName, contractInst.BytecodeHash)].NonDeployed;
var sourceMapNonDeployed = analysis.SourceMaps[(contractInst.FilePath, contractInst.ContractName, contractInst.Bytecode)].NonDeployed;

// Find the sourcemap matching this contract file name and contract name.
var sourceMapDeployed = analysis.SourceMaps[(contractInst.FilePath, contractInst.ContractName, contractInst.BytecodeHash)].Deployed;
var sourceMapDeployed = analysis.SourceMaps[(contractInst.FilePath, contractInst.ContractName, contractInst.Bytecode)].Deployed;

// Find the SourceFileMap (viewmodel used by the html templating) matching this contract file name.
var (sourceIndex, sourceFileMap) = sourceFileMaps.FirstOrDefault(s => s.Value.SourceFilePath == contractInst.FilePath);
Expand Down
2 changes: 1 addition & 1 deletion src/Meadow.CoverageReport/SourceAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static class SourceAnalysis
continue;
}

sourceMaps.Add((entry.FilePath, entry.ContractName, entry.BytecodeHash), (sourceMapEntriesNonDeployed.ToArray(), sourceMapEntriesDeployed.ToArray()));
sourceMaps.Add((entry.FilePath, entry.ContractName, entry.Bytecode), (sourceMapEntriesNonDeployed.ToArray(), sourceMapEntriesDeployed.ToArray()));
}

// Get nodes with duplicates filtered out, and the useless/harmful node types fitlered out
Expand Down
4 changes: 0 additions & 4 deletions src/Meadow.DebugAdapterProxy/Meadow.DebugAdapterProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="SourceLink.Embed.AllSourceFiles" Version="2.8.3" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.2.5" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
Expand Down
47 changes: 0 additions & 47 deletions src/Meadow.DebugAdapterProxy/NamedPipes.cs

This file was deleted.

33 changes: 29 additions & 4 deletions src/Meadow.DebugAdapterProxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Buffers.Text;
using McMaster.Extensions.CommandLineUtils.Abstractions;
using System.Collections.Generic;
using System.IO.Pipes;

namespace Meadow.DebugAdapterProxy
{
Expand Down Expand Up @@ -91,10 +92,34 @@ static async Task Main(string[] args)
_cancellationTokenSource.Cancel();
}

static async Task ConnectStream(Stream from, Stream to, Stream copy = null, CancellationToken cancellationToken = default)
{
try
{
var buffer = new byte[1024];
int read;
while (from.CanRead && to.CanWrite)
{
read = await from.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
if (copy != null)
{
await copy.WriteAsync(buffer, 0, read, cancellationToken);
await copy.FlushAsync(cancellationToken);
}

await to.WriteAsync(buffer, 0, read, cancellationToken);
await to.FlushAsync(cancellationToken);
}
}
catch (NotSupportedException) { }
catch (OperationCanceledException) { }
catch (IOException) { }
}

static async Task StartIpcProxyClient(string pipeName, CancellationToken cancellationToken)
{
// forward stdin/stdout from this process to a named pipe server
using (var pipeClient = NamedPipes.CreatePipeClient(pipeName))
using (var pipeClient = new NamedPipeClientStream(".", pipeName, System.IO.Pipes.PipeDirection.InOut, System.IO.Pipes.PipeOptions.Asynchronous))
{
_logger?.Log("Connecting to debug server pipe...");
await pipeClient.ConnectAsync(cancellationToken);
Expand Down Expand Up @@ -122,10 +147,10 @@ static async Task StartIpcProxyClient(string pipeName, CancellationToken cancell
streamTasks.Add(verboseProxyLogTask);
}

var pipeInputTask = NamedPipes.ConnectStream(stdIn, pipeClient, proxyStreamInput, cancellationToken);
var pipeOutputTask = NamedPipes.ConnectStream(pipeClient, stdOut, proxyStreamOutput, cancellationToken);
var pipeInputTask = ConnectStream(stdIn, pipeClient, proxyStreamInput, cancellationToken);
var pipeOutputTask = ConnectStream(pipeClient, stdOut, proxyStreamOutput, cancellationToken);

var checkClosedTask = Task.Run(() =>
var checkClosedTask = Task.Run(() =>
{
while (pipeClient.IsConnected)
{
Expand Down

0 comments on commit 689fd21

Please sign in to comment.