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

Commit

Permalink
update remix-debug syntax to use const, let and this
Browse files Browse the repository at this point in the history
  • Loading branch information
iurimatias committed Dec 18, 2019
1 parent 99cb284 commit 60e291b
Show file tree
Hide file tree
Showing 34 changed files with 498 additions and 527 deletions.
20 changes: 10 additions & 10 deletions remix-debug/bin/rdb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ program
.option('--node [url]', 'node to connect to')
.parse(process.argv)

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

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

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

var inputJson = {
const inputJson = {
language: 'Solidity',
sources: {
},
Expand All @@ -55,17 +55,17 @@ inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString(

console.log('compiling...')

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

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

var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
const tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'

cmdLine.startDebug(tx, shortFilename)

Expand Down
16 changes: 8 additions & 8 deletions remix-debug/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'
var EthDebugger = require('./src/Ethdebugger')
var TransactionDebugger = require('./src/debugger/debugger')
var CmdLine = require('./src/cmdline')
const EthDebugger = require('./src/Ethdebugger')
const TransactionDebugger = require('./src/debugger/debugger')
const CmdLine = require('./src/cmdline')

var StorageViewer = require('./src/storage/storageViewer')
var StorageResolver = require('./src/storage/storageResolver')
const StorageViewer = require('./src/storage/storageViewer')
const StorageResolver = require('./src/storage/storageResolver')

var SolidityDecoder = require('./src/solidity-decoder')
const SolidityDecoder = require('./src/solidity-decoder')

var remixLib = require('remix-lib')
var BreakpointManager = remixLib.code.BreakpointManager
const remixLib = require('remix-lib')
const BreakpointManager = remixLib.code.BreakpointManager

/*
Use of breakPointManager :
Expand Down
49 changes: 24 additions & 25 deletions remix-debug/src/Ethdebugger.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict'

var StorageViewer = require('./storage/storageViewer')
var StorageResolver = require('./storage/storageResolver')
const StorageViewer = require('./storage/storageViewer')
const StorageResolver = require('./storage/storageResolver')

var SolidityDecoder = require('./solidity-decoder')
var SolidityProxy = SolidityDecoder.SolidityProxy
var stateDecoder = SolidityDecoder.stateDecoder
var localDecoder = SolidityDecoder.localDecoder
var InternalCallTree = SolidityDecoder.InternalCallTree
const SolidityDecoder = require('./solidity-decoder')
const SolidityProxy = SolidityDecoder.SolidityProxy
const stateDecoder = SolidityDecoder.stateDecoder
const localDecoder = SolidityDecoder.localDecoder
const InternalCallTree = SolidityDecoder.InternalCallTree

var remixLib = require('remix-lib')
var TraceManager = remixLib.trace.TraceManager
var CodeManager = remixLib.code.CodeManager
var traceHelper = remixLib.helpers.trace
var EventManager = remixLib.EventManager
const remixLib = require('remix-lib')
const TraceManager = remixLib.trace.TraceManager
const CodeManager = remixLib.code.CodeManager
const traceHelper = remixLib.helpers.trace
const EventManager = remixLib.EventManager

/**
* Ethdebugger is a wrapper around a few classes that helps debugging a transaction
Expand Down Expand Up @@ -75,7 +75,7 @@ Ethdebugger.prototype.sourceLocationFromVMTraceIndex = function (address, stepIn
}

Ethdebugger.prototype.sourceLocationFromInstructionIndex = function (address, instIndex, callback) {
this.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, instIndex, this.solidityProxy.contracts, function (error, rawLocation) {
this.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, instIndex, this.solidityProxy.contracts, (error, rawLocation) => {
callback(error, rawLocation)
})
}
Expand All @@ -98,10 +98,10 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback)
step,
(error, result) => {
if (!error) {
var stack = result[0].value
var memory = result[1].value
const stack = result[0].value
const memory = result[1].value
try {
var storageViewer = new StorageViewer({
const storageViewer = new StorageViewer({
stepIndex: step,
tx: this.tx,
address: result[2].value
Expand All @@ -124,15 +124,15 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback)

/* decode state */
Ethdebugger.prototype.extractStateAt = function (step, callback) {
this.solidityProxy.extractStateVariablesAt(step, function (error, stateVars) {
this.solidityProxy.extractStateVariablesAt(step, (error, stateVars) => {
callback(error, stateVars)
})
}

Ethdebugger.prototype.decodeStateAt = function (step, stateVars, callback) {
this.traceManager.getCurrentCalledAddressAt(step, (error, address) => {
if (error) return callback(error)
var storageViewer = new StorageViewer({
const storageViewer = new StorageViewer({
stepIndex: step,
tx: this.tx,
address: address
Expand Down Expand Up @@ -175,16 +175,15 @@ Ethdebugger.prototype.debug = function (tx) {
}
this.setCompilationResult(this.opts.compilationResult())
this.tx = tx
var self = this
this.traceManager.resolveTrace(tx, function (error, result) {
this.traceManager.resolveTrace(tx, (error, result) => {
if (result) {
self.event.trigger('newTraceLoaded', [self.traceManager.trace])
if (self.breakpointManager && self.breakpointManager.hasBreakpoint()) {
self.breakpointManager.jumpNextBreakpoint(false)
this.event.trigger('newTraceLoaded', [this.traceManager.trace])
if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) {
this.breakpointManager.jumpNextBreakpoint(false)
}
self.storageResolver = new StorageResolver({web3: self.traceManager.web3})
this.storageResolver = new StorageResolver({web3: this.traceManager.web3})
} else {
self.statusMessage = error ? error.message : 'Trace not loaded'
this.statusMessage = error ? error.message : 'Trace not loaded'
}
})
}
Expand Down
25 changes: 12 additions & 13 deletions remix-debug/src/cmdline/contextManager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var remixLib = require('remix-lib')
const remixLib = require('remix-lib')

var EventManager = remixLib.EventManager
var Web3Providers = remixLib.vm.Web3Providers
var DummyProvider = remixLib.vm.DummyProvider
var init = remixLib.init
const EventManager = remixLib.EventManager
const Web3Providers = remixLib.vm.Web3Providers
const DummyProvider = remixLib.vm.DummyProvider
const init = remixLib.init

class ContextManager {
constructor (executionContext) {
Expand Down Expand Up @@ -33,23 +33,22 @@ class ContextManager {
}

switchProvider (type, cb) {
var self = this
this.web3Providers.get(type, function (error, obj) {
this.web3Providers.get(type, (error, obj) => {
if (error) {
// console.log('provider ' + type + ' not defined')
} else {
self.web3 = obj
self.executionContext.detectNetwork((error, network) => {
this.web3 = obj
this.executionContext.detectNetwork((error, network) => {
if (error || !network) {
self.web3 = obj
this.web3 = obj
} else {
var webDebugNode = init.web3DebugNode(network.name)
self.web3 = (!webDebugNode ? obj : webDebugNode)
this.web3 = (!webDebugNode ? obj : webDebugNode)
}
self.event.trigger('providerChanged', [type, self.web3])
this.event.trigger('providerChanged', [type, this.web3])
if (cb) return cb()
})
self.event.trigger('providerChanged', [type, self.web3])
this.event.trigger('providerChanged', [type, this.web3])
}
})
}
Expand Down
61 changes: 28 additions & 33 deletions remix-debug/src/cmdline/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var Web3 = require('web3')
var Debugger = require('../debugger/debugger.js')
var ContextManager = require('./contextManager.js')
var EventManager = require('events')
var remixLib = require('remix-lib')
var executionContext = remixLib.execution.executionContext
const Web3 = require('web3')
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 {

Expand All @@ -20,7 +20,7 @@ class CmdLine {
}

loadCompilationData (inputJson, outputJson) {
let data = {}
const data = {}
data.data = outputJson
data.source = { sources: inputJson.sources }
this.loadCompilationResult(data)
Expand All @@ -32,7 +32,6 @@ class CmdLine {
}

initDebugger (cb) {
const self = this
this.contextManager = new ContextManager(this.executionContext)

this.debugger = new Debugger({
Expand All @@ -41,7 +40,7 @@ class CmdLine {
})

this.contextManager.event.register('providerChanged', () => {
self.debugger.updateWeb3(self.contextManager.getWeb3())
this.debugger.updateWeb3(this.contextManager.getWeb3())
})

this.contextManager.initProviders()
Expand All @@ -51,15 +50,13 @@ class CmdLine {
}

getSource () {
const self = this

let lineColumnPos = this.lineColumnPos
const lineColumnPos = this.lineColumnPos

if (!lineColumnPos || !lineColumnPos.start) return []

let content = self.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n')
const content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n')

let source = []
const source = []

let line
line = content[lineColumnPos.start.line - 2]
Expand All @@ -71,48 +68,47 @@ class CmdLine {
source.push(' ' + lineColumnPos.start.line + ': ' + line)
}

let currentLineNumber = lineColumnPos.start.line
let currentLine = content[currentLineNumber]
const currentLineNumber = lineColumnPos.start.line
const currentLine = content[currentLineNumber]
source.push('=> ' + (currentLineNumber + 1) + ': ' + currentLine)

let startLine = lineColumnPos.start.line
const startLine = lineColumnPos.start.line
for (var i = 1; i < 4; i++) {
let line = content[startLine + i]
const line = content[startLine + i]
source.push(' ' + (startLine + i + 1) + ': ' + line)
}

return source
}

getCurrentLine () {
let lineColumnPos = this.lineColumnPos
const lineColumnPos = this.lineColumnPos
if (!lineColumnPos) return ''
let currentLineNumber = lineColumnPos.start.line
let content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n')
const currentLineNumber = lineColumnPos.start.line
const content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n')
return content[currentLineNumber]
}

startDebug (txNumber, filename, cb) {
const self = this
this.filename = filename
this.txHash = txNumber
this.debugger.debug(null, txNumber, null, () => {
self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) {
self.lineColumnPos = lineColumnPos
self.rawLocation = rawLocation
self.events.emit('source', [lineColumnPos, rawLocation])
this.debugger.event.register('newSourceLocation', (lineColumnPos, rawLocation) => {
this.lineColumnPos = lineColumnPos
this.rawLocation = rawLocation
this.events.emit('source', [lineColumnPos, rawLocation])
})

self.debugger.vmDebuggerLogic.event.register('solidityState', (data) => {
self.solidityState = data
self.events.emit('globals', data)
this.debugger.vmDebuggerLogic.event.register('solidityState', (data) => {
this.solidityState = data
this.events.emit('globals', data)
})

// TODO: this doesnt work too well, it should request the data instead...
self.debugger.vmDebuggerLogic.event.register('solidityLocals', (data) => {
this.debugger.vmDebuggerLogic.event.register('solidityLocals', (data) => {
if (JSON.stringify(data) === '{}') return
self.solidityLocals = data
self.events.emit('locals', data)
this.solidityLocals = data
this.events.emit('locals', data)
})

if (cb) {
Expand Down Expand Up @@ -215,4 +211,3 @@ class CmdLine {
}

module.exports = CmdLine

Loading

0 comments on commit 60e291b

Please sign in to comment.