diff --git a/remix-debug/bin/rdb b/remix-debug/bin/rdb index fcee04b8d..e1bc20732 100755 --- a/remix-debug/bin/rdb +++ b/remix-debug/bin/rdb @@ -2,10 +2,13 @@ const program = require('commander') const version = require('../package.json').version +// const solc = require('solc') +// const fs = require('fs') +const repl = require('repl') program .command('version') - .description("outputs version number") + .description('outputs version number') .action(() => { console.log(version) process.exit(0) @@ -13,7 +16,7 @@ program program .command('help') - .description("outputs usage information") + .description('outputs usage information') .action(() => { program.help() process.exit(0) @@ -27,12 +30,6 @@ program const CmdLine = require('../src/cmdline/index.js') -const solc = require('solc') -const fs = require('fs') - -const filename = 'test/sol/simple_storage.sol' -const shortFilename = 'simple_storage.sol' - const inputJson = { language: 'Solidity', sources: { @@ -51,29 +48,29 @@ const inputJson = { } } -inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()} +// inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()} console.log('compiling...') -const compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson))) -const compilation = {} -compilation.data = compilationData -compilation.source = { sources: inputJson.sources } +// const compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson))) +let compilation = {} +compilation.data = {} +compilation.source = { sources: {} } const cmdLine = new CmdLine() -cmdLine.connect('http', 'http://localhost:8545') +cmdLine.connect('http', 'https://remix-goerli.ethdevops.io') cmdLine.loadCompilationResult(compilation) cmdLine.initDebugger() -const tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa' +const tx = '0x033bf7d78260117b6e260c419238896bf61f2ddb343073bd324400c1ff1f1dcb' -cmdLine.startDebug(tx, shortFilename) +cmdLine.startDebug(tx) cmdLine.events.on('source', () => { cmdLine.getSource().forEach(console.dir) }) -const repl = require('repl') +console.log('start') repl.start({ prompt: '> ', @@ -104,6 +101,12 @@ repl.start({ let stepIndex = parseInt(command.split(' ')[1], 10) cmdLine.jumpTo(stepIndex) } + if (command === 'next' || command === 'n') { + cmdLine.stepOverForward(true) + } + if (command === 'current-step' || command === 'cs') { + cmdLine.displayCurrentStep() + } cb(null, '') } }) diff --git a/remix-debug/src/cmdline/contextManager.js b/remix-debug/src/cmdline/contextManager.js deleted file mode 100644 index 8e2ec5a93..000000000 --- a/remix-debug/src/cmdline/contextManager.js +++ /dev/null @@ -1,58 +0,0 @@ -const remixLib = require('remix-lib') - -const EventManager = remixLib.EventManager -const Web3Providers = remixLib.vm.Web3Providers -const DummyProvider = remixLib.vm.DummyProvider -const init = remixLib.init - -class ContextManager { - constructor (executionContext) { - this.executionContext = executionContext - this.web3 = this.executionContext.web3() - this.event = new EventManager() - } - - initProviders () { - this.web3Providers = new Web3Providers() - this.addProvider('DUMMYWEB3', new DummyProvider()) - this.switchProvider('DUMMYWEB3') - - this.addProvider('vm', this.executionContext.vm()) - this.addProvider('injected', this.executionContext.internalWeb3()) - this.addProvider('web3', this.executionContext.internalWeb3()) - this.switchProvider(this.executionContext.getProvider()) - } - - getWeb3 () { - return this.web3 - } - - addProvider (type, obj) { - this.web3Providers.addProvider(type, obj) - this.event.trigger('providerAdded', [type]) - } - - switchProvider (type, cb) { - this.web3Providers.get(type, (error, obj) => { - if (error) { - // console.log('provider ' + type + ' not defined') - } else { - this.web3 = obj - this.executionContext.detectNetwork((error, network) => { - if (error || !network) { - this.web3 = obj - } else { - var webDebugNode = init.web3DebugNode(network.name) - this.web3 = (!webDebugNode ? obj : webDebugNode) - } - this.event.trigger('providerChanged', [type, this.web3]) - if (cb) return cb() - }) - this.event.trigger('providerChanged', [type, this.web3]) - } - }) - } - -} - -module.exports = ContextManager diff --git a/remix-debug/src/cmdline/index.js b/remix-debug/src/cmdline/index.js index c34f5596c..717414da5 100644 --- a/remix-debug/src/cmdline/index.js +++ b/remix-debug/src/cmdline/index.js @@ -1,14 +1,11 @@ const Web3 = require('web3') +const remixLib = require('remix-lib') const Debugger = require('../debugger/debugger.js') -const ContextManager = require('./contextManager.js') const EventManager = require('events') -const remixLib = require('remix-lib') -const executionContext = remixLib.execution.executionContext class CmdLine { constructor () { - this.executionContext = executionContext this.events = new EventManager() this.lineColumnPos = null this.rawLocation = null @@ -17,6 +14,7 @@ class CmdLine { connect (providerType, url) { if (providerType !== 'http') throw new Error('unsupported provider type') this.web3 = new Web3(new Web3.providers.HttpProvider(url)) + remixLib.init.extend(this.web3) } loadCompilationData (inputJson, outputJson) { @@ -32,21 +30,10 @@ class CmdLine { } initDebugger (cb) { - this.contextManager = new ContextManager(this.executionContext) - this.debugger = new Debugger({ - web3: this.contextManager.getWeb3(), + web3: this.web3, compiler: this.compilation }) - - this.contextManager.event.register('providerChanged', () => { - this.debugger.updateWeb3(this.contextManager.getWeb3()) - }) - - this.contextManager.initProviders() - - this.contextManager.addProvider('debugger_web3', this.web3) - this.contextManager.switchProvider('debugger_web3', cb) } getSource () { @@ -115,7 +102,7 @@ class CmdLine { // TODO: this should be an onReady event setTimeout(cb, 1000) } - }) + }).then(console.log).catch(console.error) } getVars () { @@ -208,6 +195,13 @@ class CmdLine { console.dir('= displayGlobals') console.dir(this.solidityState) } + + displayCurrentStep () { + this.debugger.debugger.traceManager.getCurrentStep(this.debugger.step_manager.currentStepIndex, (error, step) => { + if (error) console.error(error) + console.dir(step) + }) + } } module.exports = CmdLine