Skip to content

Commit c188076

Browse files
committed
Add InstallSlitherAnalyzerAsync method.
1 parent 3f8e491 commit c188076

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

src/Stratis.VS.StratisEVM/StratisEVMPackage.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
148148

149149
await TaskScheduler.Default;
150150
await InstallBuildSystemAsync();
151-
151+
await InstallSlitherAnalyzerAsync();
152+
152153
await JoinableTaskFactory.SwitchToMainThreadAsync();
153154
ApplicationThemeManager.Apply(UI.VSTheme.ApplicationThemeGuess);
154155
await SolidityProjectMenuCommands.InitializeAsync(this);
@@ -161,7 +162,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
161162
#endregion
162163

163164
#region Static Methods
164-
public static async Task InstallBuildSystemAsync()
165+
private static async Task InstallBuildSystemAsync()
165166
{
166167
#if DEBUG
167168
await Runtime.CopyDirectoryAsync(Runtime.AssemblyLocation.CombinePath("BuildSystem"), Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity"), true);
@@ -194,6 +195,22 @@ public static async Task InstallBuildSystemAsync()
194195
await File.WriteAllTextAsync(Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "extdir.txt"), Runtime.AssemblyLocation);
195196
}
196197

198+
private static async Task InstallSlitherAnalyzerAsync()
199+
{
200+
if (!File.Exists(Runtime.AssemblyLocation.CombinePath(SlitherExe)))
201+
{
202+
if (!await Runtime.DownloadFileAsync("slither", new Uri("https://ajb.nyc3.cdn.digitaloceanspaces.com/stratisdevex/slither-0.10.3.exe"), Runtime.AssemblyLocation.CombinePath(SlitherExe)))
203+
{
204+
Runtime.Error("Could not download Slither executable.");
205+
return;
206+
}
207+
}
208+
if (!File.Exists(Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools", SlitherExe)))
209+
{
210+
await Runtime.CopyFileAsync(Runtime.AssemblyLocation.CombinePath(SlitherExe), Runtime.LocalAppDataDir.CombinePath("CustomProjectSystems", "Solidity", "Tools", SlitherExe));
211+
}
212+
}
213+
197214
private void InstallSolidityProjectDataFlowSinks(UnconfiguredProject unconfiguredProject)
198215
{
199216
var subscriptionService = unconfiguredProject.Services.ActiveConfiguredProjectSubscription;
@@ -222,6 +239,8 @@ private void InstallSolidityProjectDataFlowSinks(UnconfiguredProject unconfigure
222239
public const string SolidityProjectFileUIContextRule = "9d4c64d4-52eb-4ebe-aa01-1d975eb3a9d7";
223240

224241
public const string NPMFileUIContextRule = "9A7CA75A-FA6E-45B2-B6E9-4BFF0AB7BB88";
242+
243+
public const string SlitherExe = "slither-0.10.3.exe";
225244
#endregion
226245

227246
}

src/Stratis.VS.StratisEVM/UI/BlockchainExplorer/BlockchainExplorerToolWindowControl.xaml.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Windows.Documents;
34
using System.IO;
45
using System.Security.Cryptography;
56
using System.Linq;
@@ -18,11 +19,11 @@
1819
using Wpc = Wpf.Ui.Controls;
1920
using Nethereum.Util;
2021

21-
using static Stratis.DevEx.Result;
22+
using Stratis.DevEx;
2223
using Stratis.DevEx.Ethereum;
2324
using Stratis.VS.StratisEVM.UI.ViewModel;
24-
using Stratis.DevEx;
25-
using System.Windows.Documents;
25+
using static Stratis.DevEx.Result;
26+
using Nethereum.Hex.HexTypes;
2627

2728
namespace Stratis.VS.StratisEVM.UI
2829
{
@@ -923,7 +924,7 @@ private async void RunContractCmd_Executed(object sender, ExecutedRoutedEventArg
923924
};
924925
var formPanel = (StackPanel)(_sp).Children[2];
925926
var statusPanel = ((StackPanel)(_sp).Children[3]);
926-
await CreateRunContractFormAsync(formPanel, statusPanel, item.Data, transactCheckBox, fromAddressTextBox);
927+
await CreateRunContractFormAsync(formPanel, statusPanel, item.Data, transactCheckBox, fromAddressTextBox, () => (estimateGasRadioButton.IsChecked ?? false) ? null : new HexBigInteger((long) customGasNumberBox.Value));
927928
dw.ButtonClicked += (cd, args) => { };
928929
dw.Closing += (d, args) => { };
929930
await dw.ShowAsync();
@@ -987,7 +988,7 @@ private void ShowValidationSuccess(StackPanel successPanel, Wpc.TextBlock succes
987988

988989
private void HideValidationSuccess(StackPanel successPanel) => successPanel.Visibility = Visibility.Hidden;
989990

990-
private async Task CreateRunContractFormAsync(StackPanel form, StackPanel statusPanel, Dictionary<string, object> contractData, CheckBox transactCheckBox, Wpc.TextBox fromAddress)
991+
private async Task CreateRunContractFormAsync(StackPanel form, StackPanel statusPanel, Dictionary<string, object> contractData, CheckBox transactCheckBox, Wpc.TextBox fromAddress, Func<HexBigInteger> gas)
991992
{
992993
form.Children.Clear();
993994
var errors = (Wpc.TextBlock)((Grid)statusPanel.Children[0]).Children[0];
@@ -1027,9 +1028,7 @@ private async Task CreateRunContractFormAsync(StackPanel form, StackPanel status
10271028
ShowValidationErrors(errors, $"Could not retrieve balance for contract. {balr.FailureMessage}");
10281029
return;
10291030
}
1030-
1031-
1032-
1031+
10331032
foreach (var function in _abi.Functions)
10341033
{
10351034
var vsp = new StackPanel()
@@ -1078,8 +1077,14 @@ private async Task CreateRunContractFormAsync(StackPanel form, StackPanel status
10781077

10791078
button.Click += (s, e) =>
10801079
{
1081-
var paramVals = GetContractFunctionParams(vsp, function.InputParameters.ToDictionary(ip => ip.Name, ip => ip.Type));
1082-
if (paramVals.Length != function.InputParameters.Count())
1080+
var paramVals = GetContractFunctionParams(vsp, function.InputParameters.ToDictionary(ip => ip.Name, ip => ip.Type), out string paramError);
1081+
if (!string.IsNullOrEmpty(paramError))
1082+
{
1083+
ShowValidationErrors(errors, $"Error parsing function parameters: \n{paramError}");
1084+
VSUtil.LogToStratisEVMWindow($"\n========== Call contract {address} at {rpcurl} failed.==========\nError parsing function parameters: {paramError}");
1085+
return;
1086+
}
1087+
else if (paramVals.Length != function.InputParameters.Count())
10831088
{
10841089
ShowValidationErrors(errors, $"The {function.Name} function requires {function.InputParameters.Count()} parameters.");
10851090
VSUtil.LogToStratisEVMWindow($"\n========== Call contract {address} at {rpcurl} failed.==========\nThe {function.Name} function requires {function.InputParameters.Count()} parameters.");
@@ -1098,7 +1103,7 @@ private async Task CreateRunContractFormAsync(StackPanel form, StackPanel status
10981103
ShowValidationErrors(errors, "Enter a valid from address to send the transaction from.");
10991104
return;
11001105
}
1101-
r = ThreadHelper.JoinableTaskFactory.Run(() => ExecuteAsync(Network.SendContractTransactionAsync(rpcurl, address, abi, function.Name, fromAddress.Text, functionInput: paramVals)));
1106+
r = ThreadHelper.JoinableTaskFactory.Run(() => ExecuteAsync(Network.SendContractTransactionAsync(rpcurl, address, abi, function.Name, fromAddress.Text, gas:gas(), functionInput: paramVals)));
11021107
}
11031108
else
11041109
{
@@ -1134,7 +1139,7 @@ private async Task CreateRunContractFormAsync(StackPanel form, StackPanel status
11341139
ShowValidationErrors(errors, "Enter a valid from address to send the transaction from.");
11351140
return;
11361141
}
1137-
r = ThreadHelper.JoinableTaskFactory.Run(() => ExecuteAsync(Network.SendContractTransactionAsync(rpcurl, address, abi, function.Name, fromAddress.Text)));
1142+
r = ThreadHelper.JoinableTaskFactory.Run(() => ExecuteAsync(Network.SendContractTransactionAsync(rpcurl, address, abi, function.Name, fromAddress.Text, gas:gas())));
11381143
}
11391144
else
11401145
{
@@ -1162,8 +1167,9 @@ private async Task CreateRunContractFormAsync(StackPanel form, StackPanel status
11621167
}
11631168
}
11641169

1165-
private object[] GetContractFunctionParams(StackPanel form, Dictionary<string, string> paramTypes)
1170+
private object[] GetContractFunctionParams(StackPanel form, Dictionary<string, string> paramTypes, out string error)
11661171
{
1172+
error = null;
11671173
Dictionary<string, (string, string)> paramValues = new Dictionary<string, (string, string)>();
11681174
foreach (var child in form.Children)
11691175
{
@@ -1176,7 +1182,15 @@ private object[] GetContractFunctionParams(StackPanel form, Dictionary<string, s
11761182
}
11771183
}
11781184
}
1179-
return Contract.ParseFunctionParameterValues(paramValues);
1185+
try
1186+
{
1187+
return Contract.ParseFunctionParameterValues(paramValues);
1188+
}
1189+
catch (Exception ex)
1190+
{
1191+
error = ex.Message;
1192+
return Array.Empty<object>();
1193+
}
11801194
}
11811195
#endregion
11821196

0 commit comments

Comments
 (0)