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

rdb CLI #1451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

rdb CLI #1451

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
37 changes: 20 additions & 17 deletions remix-debug/bin/rdb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

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)
})

program
.command('help')
.description("outputs usage information")
.description('outputs usage information')
.action(() => {
program.help()
process.exit(0)
Expand All @@ -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: {
Expand All @@ -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: '> ',
Expand Down Expand Up @@ -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, '')
}
})
Expand Down
58 changes: 0 additions & 58 deletions remix-debug/src/cmdline/contextManager.js

This file was deleted.

28 changes: 11 additions & 17 deletions remix-debug/src/cmdline/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand All @@ -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 () {
Expand Down Expand Up @@ -115,7 +102,7 @@ class CmdLine {
// TODO: this should be an onReady event
setTimeout(cb, 1000)
}
})
}).then(console.log).catch(console.error)
}

getVars () {
Expand Down Expand Up @@ -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