You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
2.8 KiB
113 lines
2.8 KiB
6 years ago
|
#!/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')
|
||
6 years ago
|
|
||
6 years ago
|
var solc = require('solc')
|
||
|
var fs = require('fs')
|
||
|
|
||
|
var filename = 'test/sol/simple_storage.sol'
|
||
6 years ago
|
var shortFilename = 'simple_storage.sol'
|
||
6 years ago
|
|
||
6 years ago
|
var inputJson = {
|
||
6 years ago
|
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' ]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()}
|
||
6 years ago
|
|
||
6 years ago
|
console.log('compiling...')
|
||
6 years ago
|
|
||
6 years ago
|
let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson)))
|
||
6 years ago
|
var compilation = {}
|
||
|
compilation.data = compilationData
|
||
6 years ago
|
compilation.source = { sources: inputJson.sources }
|
||
6 years ago
|
|
||
6 years ago
|
var cmdLine = new CmdLine()
|
||
|
cmdLine.connect('http', 'http://localhost:8545')
|
||
|
cmdLine.loadCompilationResult(compilation)
|
||
|
cmdLine.initDebugger()
|
||
|
|
||
|
var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
|
||
6 years ago
|
|
||
6 years ago
|
cmdLine.startDebug(tx, shortFilename)
|
||
6 years ago
|
|
||
6 years ago
|
cmdLine.events.on('source', () => {
|
||
|
cmdLine.getSource().forEach(console.dir)
|
||
6 years ago
|
})
|
||
6 years ago
|
|
||
|
const repl = require('repl')
|
||
|
|
||
6 years ago
|
repl.start({
|
||
6 years ago
|
prompt: '> ',
|
||
|
eval: (cmd, context, filename, cb) => {
|
||
|
let command = cmd.trim()
|
||
|
if (command === 'next' || command === 'n') {
|
||
6 years ago
|
cmdLine.stepOverForward(true)
|
||
6 years ago
|
}
|
||
|
if (command === 'previous' || command === 'p' || command === 'prev') {
|
||
6 years ago
|
cmdLine.stepOverBack(true)
|
||
6 years ago
|
}
|
||
|
if (command === 'step' || command === 's') {
|
||
6 years ago
|
cmdLine.stepIntoForward(true)
|
||
6 years ago
|
}
|
||
|
if (command === 'stepback' || command === 'sb') {
|
||
6 years ago
|
cmdLine.stepIntoBack(true)
|
||
6 years ago
|
}
|
||
|
if (command === 'exit' || command === 'quit') {
|
||
|
process.exit(0)
|
||
|
}
|
||
|
if (command === 'var local' || command === 'v l' || command === 'vl') {
|
||
6 years ago
|
cmdLine.displayLocals()
|
||
6 years ago
|
}
|
||
|
if (command === 'var global' || command === 'v g' || command === 'vg') {
|
||
6 years ago
|
cmdLine.displayGlobals()
|
||
6 years ago
|
}
|
||
|
if (command.split(' ')[0] === 'jump') {
|
||
|
let stepIndex = parseInt(command.split(' ')[1], 10)
|
||
6 years ago
|
cmdLine.jumpTo(stepIndex)
|
||
6 years ago
|
}
|
||
6 years ago
|
cb(null, '')
|
||
6 years ago
|
}
|
||
6 years ago
|
})
|
||
6 years ago
|
|
||
6 years ago
|
module.exports = cmdLine
|
||
6 years ago
|
|