analyse method added

pull/1398/head
aniket-engg 4 years ago committed by Aniket
parent 38e95947d8
commit 0672234f5e
  1. 2
      apps/remix-ide/src/app/files/slither-handle.js
  2. 30
      libs/remixd/src/services/slitherClient.ts

@ -5,7 +5,7 @@ const profile = {
name: 'slither',
displayName: 'Slither',
url: 'ws://127.0.0.1:65523',
methods: [],
methods: ['analyse'],
description: 'Using Remixd daemon, run slither static analysis',
kind: 'other',
version: packageJson.version

@ -1,5 +1,6 @@
import * as WS from 'ws' // eslint-disable-line
import { PluginClient } from '@remixproject/plugin'
const { spawn } = require('child_process')
export class SlitherClient extends PluginClient {
methods: Array<string>
@ -8,7 +9,7 @@ export class SlitherClient extends PluginClient {
constructor (private readOnly = false) {
super()
this.methods = []
this.methods = ['analyse']
}
setWebSocket (websocket: WS): void {
@ -18,4 +19,31 @@ export class SlitherClient extends PluginClient {
sharedFolder (currentSharedFolder: string): void {
this.currentSharedFolder = currentSharedFolder
}
analyse (filePath: string) {
return new Promise((resolve, reject) => {
if (this.readOnly) {
const errMsg = '[Slither Analysis]: Cannot analyse in read-only mode'
return reject(new Error(errMsg))
}
const outputFile = 'slither-report.json'
const cmd = `slither ${filePath} --disable-solc-warnings --json ${outputFile}`
const options = { cwd: this.currentSharedFolder, shell: true }
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