Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

add bins & command line params for simulator and debugger #1109

Merged
merged 4 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions remix-debug/bin/rdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env node

const program = require('commander')
const version = require('../package.json').version

program
.command('version')
.description("outputs version number")
.action(() => {
console.log(version)
process.exit(0)
})

program
.command('help')
.description("outputs usage information")
.action(() => {
program.help()
process.exit(0)
})

program
.option('-f, --file [filename]', 'solidity filename to debug')
.option('--tx [txHash]', 'transaction hash to debug')
.option('--node [url]', 'node to connect to')
.parse(process.argv)

var CmdLine = require('../src/cmdline/index.js')

var solc = require('solc')
var fs = require('fs')

var filename = 'test/sol/simple_storage.sol'
var shortFilename = 'simple_storage.sol'

var inputJson = {
language: 'Solidity',
sources: {
},
settings: {
optimizer: {
enabled: true,
runs: 200
},
outputSelection: {
'*': {
'': [ 'legacyAST' ],
'*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
}
}
}
}

inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()}

console.log('compiling...')

let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson)))
var compilation = {}
compilation.data = compilationData
compilation.source = { sources: inputJson.sources }

var cmdLine = new CmdLine()
cmdLine.connect('http', 'http://localhost:8545')
cmdLine.loadCompilationResult(compilation)
cmdLine.initDebugger()

var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'

cmdLine.startDebug(tx, shortFilename)

cmdLine.events.on('source', () => {
cmdLine.getSource().forEach(console.dir)
})

const repl = require('repl')

repl.start({
prompt: '> ',
eval: (cmd, context, filename, cb) => {
let command = cmd.trim()
if (command === 'next' || command === 'n') {
cmdLine.stepOverForward(true)
}
if (command === 'previous' || command === 'p' || command === 'prev') {
cmdLine.stepOverBack(true)
}
if (command === 'step' || command === 's') {
cmdLine.stepIntoForward(true)
}
if (command === 'stepback' || command === 'sb') {
cmdLine.stepIntoBack(true)
}
if (command === 'exit' || command === 'quit') {
process.exit(0)
}
if (command === 'var local' || command === 'v l' || command === 'vl') {
cmdLine.displayLocals()
}
if (command === 'var global' || command === 'v g' || command === 'vg') {
cmdLine.displayGlobals()
}
if (command.split(' ')[0] === 'jump') {
let stepIndex = parseInt(command.split(' ')[1], 10)
cmdLine.jumpTo(stepIndex)
}
cb(null, '')
}
})

module.exports = cmdLine

1 change: 1 addition & 0 deletions remix-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"main": "./index.js",
"dependencies": {
"commander": "^2.19.0",
"ethereumjs-util": "^4.5.0",
"ethereumjs-vm": "2.4.0",
"fast-async": "^6.1.2",
Expand Down
1 change: 1 addition & 0 deletions remix-debug/rdb.js → remix-debug/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: this file shoudl be removed at some point
var CmdLine = require('./src/cmdline/index.js')
// var compilation = require('./compilation.json')

Expand Down
27 changes: 26 additions & 1 deletion remix-simulator/bin/ethsim
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
#!/usr/bin/env node

require('../src/server');
const program = require('commander')
const version = require('../package.json').version

program
.command('version')
.description("outputs version number")
.action(() => {
console.log(version)
process.exit(0)
})

program
.command('help')
.description("outputs usage information")
.action(() => {
program.help()
process.exit(0)
})

program
.option('-p, --port [port]', 'specify port')
.parse(process.argv)

const Server = require('../src/server')
const server = new Server()
server.start(program.port || 8545)

1 change: 1 addition & 0 deletions remix-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"ansi-gray": "^0.1.1",
"body-parser": "^1.18.2",
"color-support": "^1.1.3",
"commander": "^2.19.0",
"express": "^4.16.3",
"express-ws": "^4.0.0",
"fast-async": "^6.3.7",
Expand Down
68 changes: 38 additions & 30 deletions remix-simulator/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,43 @@ const expressWs = require('express-ws')
const Provider = require('./provider')
const log = require('./utils/logs.js')

expressWs(app)

var provider = new Provider()

app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())

app.get('/', (req, res) => {
res.send('Welcome to remix-simulator')
})

app.use((req, res) => {
provider.sendAsync(req.body, (err, jsonResponse) => {
if (err) {
return res.send(JSON.stringify({error: err}))
}
res.send(jsonResponse)
})
})

app.ws('/', (ws, req) => {
ws.on('message', function (msg) {
provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => {
if (err) {
return ws.send(JSON.stringify({error: err}))
}
ws.send(JSON.stringify(jsonResponse))
class Server {
constructor () {
this.provider = new Provider()
}

start (port) {
expressWs(app)

app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())

app.get('/', (req, res) => {
res.send('Welcome to remix-simulator')
})

app.use((req, res) => {
this.provider.sendAsync(req.body, (err, jsonResponse) => {
if (err) {
return res.send(JSON.stringify({error: err}))
}
res.send(jsonResponse)
})
})

app.ws('/', (ws, req) => {
ws.on('message', function (msg) {
this.provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => {
if (err) {
return ws.send(JSON.stringify({error: err}))
}
ws.send(JSON.stringify(jsonResponse))
})
})
})
})
})

app.listen(8545, () => log('Remix Simulator listening on port 8545!'))
app.listen(port, () => log('Remix Simulator listening on port ' + port))
}
}

module.exports = Server