switch solc to remic compiler version

pull/1398/head
aniket-engg 3 years ago committed by Aniket
parent 7432082164
commit 5d69e68263
  1. 6
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx
  2. 51
      libs/remixd/src/services/slitherClient.ts

@ -108,8 +108,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
if (lastCompilationResult && categoryIndex.length > 0) { if (lastCompilationResult && categoryIndex.length > 0) {
let warningCount = 0 let warningCount = 0
const warningMessage = [] const warningMessage = []
props.analysisModule.call('solidity-logic', 'getCompilerState').then(console.log) props.analysisModule.call('solidity-logic', 'getCompilerState').then((compilerState) => {
// props.analysisModule.call('slither', 'analyse', state.file).then(console.log) const { currentVersion, optimize, evmVersion } = compilerState
props.analysisModule.call('slither', 'analyse', state.file, { currentVersion, optimize, evmVersion }).then(console.log)
})
runner.run(lastCompilationResult, categoryIndex, results => { runner.run(lastCompilationResult, categoryIndex, results => {
results.map((result) => { results.map((result) => {
let moduleName let moduleName

@ -1,6 +1,6 @@
import * as WS from 'ws' // eslint-disable-line import * as WS from 'ws' // eslint-disable-line
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
const { spawn } = require('child_process') const { spawn, execSync } = require('child_process')
export class SlitherClient extends PluginClient { export class SlitherClient extends PluginClient {
methods: Array<string> methods: Array<string>
@ -20,30 +20,43 @@ export class SlitherClient extends PluginClient {
this.currentSharedFolder = currentSharedFolder this.currentSharedFolder = currentSharedFolder
} }
analyse (filePath: string) { analyse (filePath: string, compilerConfig) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this.readOnly) { if (this.readOnly) {
const errMsg = '[Slither Analysis]: Cannot analyse in read-only mode' const errMsg = '[Slither Analysis]: Cannot analyse in read-only mode'
return reject(new Error(errMsg)) return reject(new Error(errMsg))
} }
const outputFile = 'remix-slitherReport_' + Date.now() + '.json'
const cmd = `slither ${filePath} --json ${outputFile}`
const options = { cwd: this.currentSharedFolder, shell: true } const options = { cwd: this.currentSharedFolder, shell: true }
const child = spawn(cmd, options) const { currentVersion, optimize, evmVersion } = compilerConfig
let result = '' if(currentVersion) {
let error = '' const versionString = currentVersion.substring(0, currentVersion.indexOf('+commit') + 16)
child.stdout.on('data', (data) => { const solcOutput = execSync('solc --version', options)
const msg = `[Slither Analysis]: ${data.toString()}` if (!solcOutput.toString().includes(versionString)) {
console.log('\x1b[32m%s\x1b[0m', msg) const version = versionString.substring(0, versionString.indexOf('+commit'))
result += msg + '\n' const solcSelectInstalledVersions = execSync('solc-select versions', options)
}) if (!solcSelectInstalledVersions.toString().includes(version)) {
child.stderr.on('data', (err) => { execSync(`solc-select install ${version}`, options)
error += `[Slither Analysis]: ${err.toString()}` }
}) execSync(`solc-select use ${version}`, options)
child.on('close', () => { }
if (error) reject(error) }
else resolve(result) // const outputFile = 'remix-slitherReport_' + Date.now() + '.json'
}) // const cmd = `slither ${filePath} --json ${outputFile}`
// const child = spawn(cmd, options)
// let result = ''
// let error = ''
// child.stdout.on('data', (data) => {
// const msg = `[Slither Analysis]: ${data.toString()}`
// console.log('\x1b[32m%s\x1b[0m', msg)
// result += msg + '\n'
// })
// child.stderr.on('data', (err) => {
// error += `[Slither Analysis]: ${err.toString()}`
// })
// child.on('close', () => {
// if (error) reject(error)
// else resolve(result)
// })
}) })
} }
} }

Loading…
Cancel
Save