diff --git a/libs/remix-debug/.eslintrc b/libs/remix-debug/.eslintrc index 8b12a29e3d..d625f686ce 100644 --- a/libs/remix-debug/.eslintrc +++ b/libs/remix-debug/.eslintrc @@ -3,7 +3,8 @@ "rules": { "@typescript-eslint/no-var-requires": "off", "@typescript-eslint/no-unused-vars": "off", - "@typescript-eslint/no-this-alias": "off" + "@typescript-eslint/no-this-alias": "off", + "camelcase": "off" }, "env": { "browser": true, diff --git a/libs/remix-debug/src/Ethdebugger.ts b/libs/remix-debug/src/Ethdebugger.ts index c6a2018ae1..fc508a5bde 100644 --- a/libs/remix-debug/src/Ethdebugger.ts +++ b/libs/remix-debug/src/Ethdebugger.ts @@ -22,7 +22,6 @@ import { SolidityProxy, stateDecoder, localDecoder, InternalCallTree } from './s * @param {Map} opts - { function compilationResult } // */ export class Ethdebugger { - compilationResult web3 opts @@ -42,31 +41,31 @@ export class Ethdebugger { this.opts = opts this.event = new EventManager() - this.traceManager = new TraceManager({web3: this.web3}) + this.traceManager = new TraceManager({ web3: this.web3 }) this.codeManager = new CodeManager(this.traceManager) - this.solidityProxy = new SolidityProxy({getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager)}) + this.solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager) }) this.storageResolver = null const includeLocalVariables = true - this.callTree = new InternalCallTree(this.event, - this.traceManager, - this.solidityProxy, - this.codeManager, - { ...opts, includeLocalVariables}) + this.callTree = new InternalCallTree(this.event, + this.traceManager, + this.solidityProxy, + this.codeManager, + { ...opts, includeLocalVariables }) } setManagers () { - this.traceManager = new TraceManager({web3: this.web3}) + this.traceManager = new TraceManager({ web3: this.web3 }) this.codeManager = new CodeManager(this.traceManager) - this.solidityProxy = new SolidityProxy({getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager)}) + this.solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager) }) this.storageResolver = null const includeLocalVariables = true - this.callTree = new InternalCallTree(this.event, - this.traceManager, - this.solidityProxy, - this.codeManager, - { ...this.opts, includeLocalVariables}) + this.callTree = new InternalCallTree(this.event, + this.traceManager, + this.solidityProxy, + this.codeManager, + { ...this.opts, includeLocalVariables }) this.event.trigger('managersChanged') } @@ -108,8 +107,8 @@ export class Ethdebugger { try { const storageViewer = new StorageViewer({ stepIndex: step, tx: this.tx, address: address }, this.storageResolver, this.traceManager) const locals = await localDecoder.solidityLocals(step, this.callTree, stack, memory, storageViewer, sourceLocation, null) - if (locals['error']) { - return callback(locals['error']) + if (locals.error) { + return callback(locals.error) } return callback(null, locals) } catch (e) { @@ -128,7 +127,7 @@ export class Ethdebugger { async decodeStateAt (step, stateVars, callback) { try { const address = this.traceManager.getCurrentCalledAddressAt(step) - const storageViewer = new StorageViewer({stepIndex: step, tx: this.tx, address: address}, this.storageResolver, this.traceManager) + const storageViewer = new StorageViewer({ stepIndex: step, tx: this.tx, address: address }, this.storageResolver, this.traceManager) const result = await stateDecoder.decodeState(stateVars, storageViewer) return result } catch (error) { @@ -137,7 +136,7 @@ export class Ethdebugger { } storageViewAt (step, address) { - return new StorageViewer({stepIndex: step, tx: this.tx, address: address}, this.storageResolver, this.traceManager) + return new StorageViewer({ stepIndex: step, tx: this.tx, address: address }, this.storageResolver, this.traceManager) } updateWeb3 (web3) { @@ -164,7 +163,7 @@ export class Ethdebugger { if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { this.breakpointManager.jumpNextBreakpoint(false) } - this.storageResolver = new StorageResolver({web3: this.traceManager.web3}) + this.storageResolver = new StorageResolver({ web3: this.traceManager.web3 }) }).catch((error) => { this.statusMessage = error ? error.message : 'Trace not loaded' }) diff --git a/libs/remix-debug/src/cmdline/index.ts b/libs/remix-debug/src/cmdline/index.ts index 109612f88d..be25535f3c 100644 --- a/libs/remix-debug/src/cmdline/index.ts +++ b/libs/remix-debug/src/cmdline/index.ts @@ -3,7 +3,6 @@ import { Debugger } from '../debugger/debugger.js' import { EventEmitter } from 'events' export class CmdLine { - events lineColumnPos rawLocation @@ -28,8 +27,8 @@ export class CmdLine { loadCompilationData (inputJson, outputJson) { const data = {} - data['data'] = outputJson - data['source'] = { sources: inputJson.sources } + data.data = outputJson + data.source = { sources: inputJson.sources } this.loadCompilationResult(data) } diff --git a/libs/remix-debug/src/code/breakpointManager.ts b/libs/remix-debug/src/code/breakpointManager.ts index 5df601ce6f..bf8649d55d 100644 --- a/libs/remix-debug/src/code/breakpointManager.ts +++ b/libs/remix-debug/src/code/breakpointManager.ts @@ -9,7 +9,6 @@ import { isJumpDestInstruction } from '../trace/traceHelper' * Trigger events: breakpointHit, breakpointAdded, breakpointRemoved */ export class BreakpointManager { - event traceManager callTree @@ -24,17 +23,16 @@ export class BreakpointManager { * @param {Object} _debugger - type of EthDebugger * @return {Function} _locationToRowConverter - function implemented by editor which return a column/line position for a char source location */ - constructor ({traceManager, callTree, solidityProxy, locationToRowConverter}) { + constructor ({ traceManager, callTree, solidityProxy, locationToRowConverter }) { this.event = new EventManager() this.traceManager = traceManager this.callTree = callTree this.solidityProxy = solidityProxy this.breakpoints = {} this.locationToRowConverter = locationToRowConverter - this.previousLine } - setManagers({traceManager, callTree, solidityProxy}) { + setManagers ({ traceManager, callTree, solidityProxy }) { this.traceManager = traceManager this.callTree = callTree this.solidityProxy = solidityProxy @@ -68,7 +66,7 @@ export class BreakpointManager { return trace[step].depth !== trace[step - 1].depth } - hitLine(currentStep, sourceLocation, previousSourceLocation, trace) { + hitLine (currentStep, sourceLocation, previousSourceLocation, trace) { // isJumpDestInstruction -> returning from a internal function call // depthChange -> returning from an external call // sourceLocation.start <= previousSourceLocation.start && ... -> previous src is contained in the current one @@ -83,7 +81,7 @@ export class BreakpointManager { return true } - /** + /** * start looking for the previous or next breakpoint * @param {Int} direction - 1 or -1 direction of the search * @param {Bool} defaultToLimit - if true jump to the limit (end if direction is 1, beginning if direction is -1) of the trace if no more breakpoint found @@ -101,7 +99,7 @@ export class BreakpointManager { } catch (e) { return console.log('cannot jump to breakpoint ' + e) } - let lineColumn = await this.locationToRowConverter(sourceLocation) + const lineColumn = await this.locationToRowConverter(sourceLocation) if (this.previousLine !== lineColumn.start.line) { if (direction === -1 && lineHadBreakpoint) { // TODO : improve this when we will build the correct structure before hand lineHadBreakpoint = false @@ -143,7 +141,7 @@ export class BreakpointManager { return false } const sources = this.breakpoints[filename] - for (let k in sources) { + for (const k in sources) { const source = sources[k] if (line === source.row) { return true @@ -157,7 +155,7 @@ export class BreakpointManager { * @return {Bool} true if breapoint registered */ hasBreakpoint () { - for (let k in this.breakpoints) { + for (const k in this.breakpoints) { if (this.breakpoints[k].length) { return true } @@ -188,7 +186,7 @@ export class BreakpointManager { if (!sources) { return } - for (let k in sources) { + for (const k in sources) { const source = sources[k] if (sourceLocation.row === source.row) { sources.splice(k, 1) diff --git a/libs/remix-debug/src/code/codeManager.ts b/libs/remix-debug/src/code/codeManager.ts index a081b0db75..e7e46f4740 100644 --- a/libs/remix-debug/src/code/codeManager.ts +++ b/libs/remix-debug/src/code/codeManager.ts @@ -13,26 +13,27 @@ import { CodeResolver } from './codeResolver' */ export class CodeManager { - event isLoading: boolean traceManager codeResolver - - constructor(_traceManager) { + + constructor (_traceManager) { this.event = new EventManager() this.isLoading = false this.traceManager = _traceManager - this.codeResolver = new CodeResolver({getCode: async (address) => { - return new Promise((resolve, reject) => { - this.traceManager.web3.eth.getCode(address, (error, code) => { - if (error) { - return reject(error) - } - return resolve(code) + this.codeResolver = new CodeResolver({ + getCode: async (address) => { + return new Promise((resolve, reject) => { + this.traceManager.web3.eth.getCode(address, (error, code) => { + if (error) { + return reject(error) + } + return resolve(code) + }) }) - }) - }}) + } + }) } /** @@ -153,6 +154,6 @@ export class CodeManager { codeMananger.event.trigger('changed', [code, address, result]) } catch (e) { console.log('dispatching event failed', e) - } + } } } diff --git a/libs/remix-debug/src/code/codeResolver.ts b/libs/remix-debug/src/code/codeResolver.ts index dc7945b747..308b9c5293 100644 --- a/libs/remix-debug/src/code/codeResolver.ts +++ b/libs/remix-debug/src/code/codeResolver.ts @@ -1,14 +1,13 @@ 'use strict' -import { nameOpCodes } from './codeUtils' +import { nameOpCodes } from './codeUtils' export class CodeResolver { - getCode bytecodeByAddress instructionsByAddress instructionsIndexByBytesOffset - - constructor({getCode}) { + + constructor ({ getCode }) { this.getCode = getCode this.bytecodeByAddress = {} // bytes code by contract addesses this.instructionsByAddress = {} // assembly items instructions list by contract addesses @@ -41,7 +40,7 @@ export class CodeResolver { formatCode (hexCode) { const [code, instructionsIndexByBytesOffset] = nameOpCodes(Buffer.from(hexCode.substring(2), 'hex')) - return {code, instructionsIndexByBytesOffset} + return { code, instructionsIndexByBytesOffset } } getExecutingCodeFromCache (address) { diff --git a/libs/remix-debug/src/code/codeUtils.ts b/libs/remix-debug/src/code/codeUtils.ts index 38c7ff87ff..0e446367b7 100644 --- a/libs/remix-debug/src/code/codeUtils.ts +++ b/libs/remix-debug/src/code/codeUtils.ts @@ -22,7 +22,7 @@ export function nameOpCodes (raw) { code.push(this.pad(pc, this.roundLog(raw.length, 10)) + ' ' + curOpCode + data) pushData = '' } - return [ code, codeMap ] + return [code, codeMap] } /** @@ -35,11 +35,11 @@ export function parseCode (raw) { const opcode = opcodes(raw[i], true) if (opcode.name.slice(0, 4) === 'PUSH') { const length = raw[i] - 0x5f - opcode['pushData'] = raw.slice(i + 1, i + length + 1) + opcode.pushData = raw.slice(i + 1, i + length + 1) // in case pushdata extends beyond code if (i + 1 + length > raw.length) { - for (let j = opcode['pushData'].length; j < length; j++) { - opcode['pushData'].push(0) + for (let j = opcode.pushData.length; j < length; j++) { + opcode.pushData.push(0) } } i += length @@ -62,4 +62,3 @@ export function log (num, base) { export function roundLog (num, base) { return Math.ceil(this.log(num, base)) } - diff --git a/libs/remix-debug/src/code/opcodes.ts b/libs/remix-debug/src/code/opcodes.ts index 4cd17a3a56..c5c1bc6557 100644 --- a/libs/remix-debug/src/code/opcodes.ts +++ b/libs/remix-debug/src/code/opcodes.ts @@ -189,5 +189,5 @@ export default function (op, full) { } } - return {name: opcode, fee: code[1], in: code[2], out: code[3], dynamic: code[4], async: code[5]} + return { name: opcode, fee: code[1], in: code[2], out: code[3], dynamic: code[4], async: code[5] } } diff --git a/libs/remix-debug/src/debugger/VmDebugger.ts b/libs/remix-debug/src/debugger/VmDebugger.ts index f552498a8f..621e3d3bb1 100644 --- a/libs/remix-debug/src/debugger/VmDebugger.ts +++ b/libs/remix-debug/src/debugger/VmDebugger.ts @@ -7,7 +7,6 @@ import { DebuggerSolidityLocals } from './solidityLocals' const { ui } = helpers export class VmDebuggerLogic { - event debugger stepManager @@ -212,7 +211,7 @@ export class VmDebuggerLogic { listenToNewChanges () { this.debugger.event.register('newTraceLoaded', this, () => { - this.storageResolver = new StorageResolver({web3: this.debugger.web3}) + this.storageResolver = new StorageResolver({ web3: this.debugger.web3 }) this.debuggerSolidityState.storageResolver = this.storageResolver this.debuggerSolidityLocals.storageResolver = this.storageResolver this.event.trigger('newTrace', []) @@ -259,5 +258,4 @@ export class VmDebuggerLogic { this.event.trigger('traceReturnValueUpdate', [data, header]) }) } - } diff --git a/libs/remix-debug/src/debugger/debugger.ts b/libs/remix-debug/src/debugger/debugger.ts index 21ee41100f..9117a888bc 100644 --- a/libs/remix-debug/src/debugger/debugger.ts +++ b/libs/remix-debug/src/debugger/debugger.ts @@ -7,7 +7,6 @@ import { DebuggerStepManager } from './stepManager' import { VmDebuggerLogic } from './VmDebugger' export class Debugger { - event offsetToLineColumnConverter compilationResult @@ -15,7 +14,7 @@ export class Debugger { breakPointManager step_manager vmDebuggerLogic - + constructor (options) { this.event = new EventManager() this.offsetToLineColumnConverter = options.offsetToLineColumnConverter @@ -27,19 +26,24 @@ export class Debugger { this.debugger = new Ethdebugger({ web3: options.web3, debugWithGeneratedSources: options.debugWithGeneratedSources, - compilationResult: this.compilationResult, + compilationResult: this.compilationResult }) - const {traceManager, callTree, solidityProxy} = this.debugger - this.breakPointManager = new BreakpointManager({traceManager, callTree, solidityProxy, locationToRowConverter: async (sourceLocation) => { - const compilationResult = await this.compilationResult() - if (!compilationResult) return { start: null, end: null } - return this.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, compilationResult.source.sources, compilationResult.data.sources) - }}) + const { traceManager, callTree, solidityProxy } = this.debugger + this.breakPointManager = new BreakpointManager({ + traceManager, + callTree, + solidityProxy, + locationToRowConverter: async (sourceLocation) => { + const compilationResult = await this.compilationResult() + if (!compilationResult) return { start: null, end: null } + return this.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, compilationResult.source.sources, compilationResult.data.sources) + } + }) this.breakPointManager.event.register('managersChanged', () => { - const {traceManager, callTree, solidityProxy} = this.debugger - this.breakPointManager.setManagers({traceManager, callTree, solidityProxy}) + const { traceManager, callTree, solidityProxy } = this.debugger + this.breakPointManager.setManagers({ traceManager, callTree, solidityProxy }) }) this.breakPointManager.event.register('breakpointStep', (step) => { @@ -115,14 +119,14 @@ export class Debugger { if (txNumber.indexOf('0x') !== -1) { return web3.eth.getTransaction(txNumber, (_error, tx) => { if (_error) return reject(_error) - if (!tx) return reject('cannot find transaction ' + txNumber) + if (!tx) return reject(new Error('cannot find transaction ' + txNumber)) this.debugTx(tx, loadingCb) return resolve() }) } web3.eth.getTransactionFromBlock(blockNumber, txNumber, (_error, tx) => { if (_error) return reject(_error) - if (!tx) return reject('cannot find transaction ' + blockNumber + ' ' + txNumber) + if (!tx) return reject(new Error('cannot find transaction ' + blockNumber + ' ' + txNumber)) this.debugTx(tx, loadingCb) return resolve() }) diff --git a/libs/remix-debug/src/debugger/solidityLocals.ts b/libs/remix-debug/src/debugger/solidityLocals.ts index 938df24cad..f07e21a465 100644 --- a/libs/remix-debug/src/debugger/solidityLocals.ts +++ b/libs/remix-debug/src/debugger/solidityLocals.ts @@ -3,7 +3,6 @@ import { solidityLocals } from '../solidity-decoder/localDecoder' import { StorageViewer } from '../storage/storageViewer' export class DebuggerSolidityLocals { - event stepManager internalTreeCall @@ -75,14 +74,14 @@ export class DebuggerSolidityLocals { var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: result[2].value }, this.storageResolver, this.traceManager) solidityLocals(this.stepManager.currentStepIndex, this.internalTreeCall, stack, memory, storageViewer, sourceLocation, cursor).then((locals) => { if (!cursor) { - if (!locals['error']) { + if (!locals.error) { this.event.trigger('solidityLocals', [locals]) } if (!Object.keys(locals).length) { this.event.trigger('solidityLocalsMessage', ['no locals']) } } else { - if (!locals['error']) { + if (!locals.error) { this.event.trigger('solidityLocalsLoadMoreCompleted', [locals]) } } diff --git a/libs/remix-debug/src/debugger/solidityState.ts b/libs/remix-debug/src/debugger/solidityState.ts index 5f7babb4d5..daa7469840 100644 --- a/libs/remix-debug/src/debugger/solidityState.ts +++ b/libs/remix-debug/src/debugger/solidityState.ts @@ -3,7 +3,6 @@ import { decodeState } from '../solidity-decoder/stateDecoder' import { StorageViewer } from '../storage/storageViewer' export class DebuggerSolidityState { - event storageResolver stepManager @@ -78,8 +77,8 @@ export class DebuggerSolidityState { const storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this.traceManager) decodeState(stateVars, storageViewer).then((result) => { this.event.trigger('solidityStateMessage', ['']) - if (result['error']) { - return this.event.trigger('solidityStateMessage', [result['error']]) + if (result.error) { + return this.event.trigger('solidityStateMessage', [result.error]) } this.event.trigger('solidityState', [result]) }) diff --git a/libs/remix-debug/src/debugger/stepManager.ts b/libs/remix-debug/src/debugger/stepManager.ts index a855235181..2cbcc26879 100644 --- a/libs/remix-debug/src/debugger/stepManager.ts +++ b/libs/remix-debug/src/debugger/stepManager.ts @@ -2,7 +2,6 @@ import { util } from '@remix-project/remix-lib' import { EventManager } from '../eventManager' export class DebuggerStepManager { - event debugger traceManager @@ -52,7 +51,7 @@ export class DebuggerStepManager { this.traceManager.buildCallPath(index).then((callsPath) => { this.currentCall = callsPath[callsPath.length - 1] if (this.currentCall.reverted) { - let revertedReason = this.currentCall.outofgas ? 'outofgas' : '' + const revertedReason = this.currentCall.outofgas ? 'outofgas' : '' this.revertionPoint = this.currentCall.return return this.event.trigger('revertWarning', [revertedReason]) } @@ -82,7 +81,7 @@ export class DebuggerStepManager { stepState = 'end' } - let jumpOutDisabled = (step === this.traceManager.findStepOut(step)) + const jumpOutDisabled = (step === this.traceManager.findStepOut(step)) this.event.trigger('stepChanged', [step, stepState, jumpOutDisabled]) }) @@ -128,7 +127,7 @@ export class DebuggerStepManager { if (!this.traceManager.isLoaded()) return if (this.currentStepIndex >= this.traceLength - 1) return let step = this.currentStepIndex + 1 - let scope = this.debugger.callTree.findScope(step) + const scope = this.debugger.callTree.findScope(step) if (scope && scope.firstStep === step) { step = scope.lastStep + 1 } @@ -168,7 +167,7 @@ export class DebuggerStepManager { } calculateFirstStep () { - let step = this.resolveToReducedTrace(0, 1) + const step = this.resolveToReducedTrace(0, 1) return this.resolveToReducedTrace(step, 1) } @@ -176,7 +175,7 @@ export class DebuggerStepManager { let step = 0 let steps = [] while (step < this.traceLength) { - let _step = this.resolveToReducedTrace(step, 1) + const _step = this.resolveToReducedTrace(step, 1) if (!_step) break steps.push(_step) step += 1 @@ -211,5 +210,4 @@ export class DebuggerStepManager { } return this.debugger.callTree.reducedTrace[nextSource] } - } diff --git a/libs/remix-debug/src/eventManager.ts b/libs/remix-debug/src/eventManager.ts index 812ae55138..60e83b0a78 100644 --- a/libs/remix-debug/src/eventManager.ts +++ b/libs/remix-debug/src/eventManager.ts @@ -1,11 +1,10 @@ 'use strict' export class EventManager { - registered anonymous - constructor() { + constructor () { this.registered = {} this.anonymous = {} } @@ -26,7 +25,7 @@ export class EventManager { func = obj obj = this.anonymous } - for (let reg in this.registered[eventName]) { + for (const reg in this.registered[eventName]) { if (this.registered[eventName][reg].obj === obj && this.registered[eventName][reg].func === func) { this.registered[eventName].splice(reg, 1) } @@ -66,7 +65,7 @@ export class EventManager { if (!this.registered[eventName]) { return } - for (let listener in this.registered[eventName]) { + for (const listener in this.registered[eventName]) { const l = this.registered[eventName][listener] l.func.apply(l.obj === this.anonymous ? {} : l.obj, args) } diff --git a/libs/remix-debug/src/init.ts b/libs/remix-debug/src/init.ts index eb343c33a5..16093be56a 100644 --- a/libs/remix-debug/src/init.ts +++ b/libs/remix-debug/src/init.ts @@ -19,11 +19,11 @@ export function setProvider (web3, url) { export function web3DebugNode (network) { const web3DebugNodes = { - 'Main': 'https://rpc.archivenode.io/e50zmkroshle2e2e50zm0044i7ao04ym', - 'Rinkeby': 'https://remix-rinkeby.ethdevops.io', - 'Ropsten': 'https://remix-ropsten.ethdevops.io', - 'Goerli': 'https://remix-goerli.ethdevops.io', - 'Kovan': 'https://remix-kovan.ethdevops.io' + Main: 'https://rpc.archivenode.io/e50zmkroshle2e2e50zm0044i7ao04ym', + Rinkeby: 'https://remix-rinkeby.ethdevops.io', + Ropsten: 'https://remix-ropsten.ethdevops.io', + Goerli: 'https://remix-goerli.ethdevops.io', + Kovan: 'https://remix-kovan.ethdevops.io' } if (web3DebugNodes[network]) { return loadWeb3(web3DebugNodes[network]) @@ -71,4 +71,3 @@ export function extend (web3) { }) } } - diff --git a/libs/remix-debug/src/solidity-decoder/astHelper.ts b/libs/remix-debug/src/solidity-decoder/astHelper.ts index 72cfc6e5b7..abf2a3c16a 100644 --- a/libs/remix-debug/src/solidity-decoder/astHelper.ts +++ b/libs/remix-debug/src/solidity-decoder/astHelper.ts @@ -14,7 +14,7 @@ export function extractContractDefinitions (sourcesList) { sourcesByContract: {} } const walker = new AstWalker() - for (let k in sourcesList) { + for (const k in sourcesList) { walker.walkFull(sourcesList[k].ast, (node) => { if (node.nodeType === 'ContractDefinition') { ret.contractsById[node.id] = node @@ -58,9 +58,9 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) { const stateVar = [] const baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById) baseContracts.reverse() - for (let k in baseContracts) { + for (const k in baseContracts) { const ctr = baseContracts[k] - for (let i in ctr.nodes) { + for (const i in ctr.nodes) { const item = ctr.nodes[i] stateItems.push(item) if (item.nodeType === 'VariableDeclaration') { @@ -68,7 +68,7 @@ export function extractStateDefinitions (contractName, sourcesList, contracts) { } } } - return {stateDefinitions: stateItems, stateVariables: stateVar} + return { stateDefinitions: stateItems, stateVariables: stateVar } } /** @@ -83,7 +83,7 @@ export function extractStatesDefinitions (sourcesList, contracts) { contracts = extractContractDefinitions(sourcesList) } const ret = {} - for (let contract in contracts.contractsById) { + for (const contract in contracts.contractsById) { const name = contracts.contractsById[contract].name const source = contracts.sourcesByContract[contract] const fullName = source + ':' + name @@ -93,4 +93,3 @@ export function extractStatesDefinitions (sourcesList, contracts) { } return ret } - diff --git a/libs/remix-debug/src/solidity-decoder/decodeInfo.ts b/libs/remix-debug/src/solidity-decoder/decodeInfo.ts index 28f9284255..ec5b31706d 100644 --- a/libs/remix-debug/src/solidity-decoder/decodeInfo.ts +++ b/libs/remix-debug/src/solidity-decoder/decodeInfo.ts @@ -28,8 +28,8 @@ function mapping (type, stateDefinitions, contractName) { const valueType = parseType(valueTypeName, stateDefinitions, contractName, 'storage') var underlyingTypes = { - 'keyType': keyType, - 'valueType': valueType + keyType: keyType, + valueType: valueType } return new MappingType(underlyingTypes, 'location', removeLocation(type)) } @@ -41,7 +41,7 @@ function mapping (type, stateDefinitions, contractName) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName} */ function uint (type) { - type === 'uint' ? 'uint256' : type + type = type === 'uint' ? 'uint256' : type const storageBytes = parseInt(type.replace('uint', '')) / 8 return new UintType(storageBytes) } @@ -53,7 +53,7 @@ function uint (type) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName} */ function int (type) { - type === 'int' ? 'int256' : type + type = type === 'int' ? 'int256' : type const storageBytes = parseInt(type.replace('int', '')) / 8 return new IntType(storageBytes) } @@ -139,7 +139,6 @@ function stringType (type, stateDefinitions, contractName, location) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray} */ function array (type, stateDefinitions, contractName, location) { - let arraySize const match = type.match(/(.*)\[(.*?)\]( storage ref| storage pointer| memory| calldata)?$/) if (!match) { console.log('unable to parse type ' + type) @@ -148,7 +147,7 @@ function array (type, stateDefinitions, contractName, location) { if (!location) { location = match[3].trim() } - arraySize = match[2] === '' ? 'dynamic' : parseInt(match[2]) + const arraySize = match[2] === '' ? 'dynamic' : parseInt(match[2]) const underlyingType = parseType(match[1], stateDefinitions, contractName, location) if (underlyingType === null) { console.log('unable to parse type ' + type) @@ -215,7 +214,7 @@ function getEnum (type, stateDefinitions, contractName) { } const state = stateDefinitions[contractName] if (state) { - for (let dec of state.stateDefinitions) { + for (const dec of state.stateDefinitions) { if (dec && dec.name && type === contractName + '.' + dec.name) { return dec } @@ -242,7 +241,7 @@ function getStructMembers (type, stateDefinitions, contractName, location) { } const state = stateDefinitions[contractName] if (state) { - for (let dec of state.stateDefinitions) { + for (const dec of state.stateDefinitions) { if (dec.nodeType === 'StructDefinition' && type === contractName + '.' + dec.name) { const offsets = computeOffsets(dec.members, stateDefinitions, contractName, location) if (!offsets) { @@ -290,18 +289,18 @@ function typeClass (fullType) { */ function parseType (type, stateDefinitions, contractName, location) { const decodeInfos = { - 'contract': address, - 'address': address, - 'array': array, - 'bool': bool, - 'bytes': dynamicByteArray, - 'bytesX': fixedByteArray, - 'enum': enumType, - 'string': stringType, - 'struct': struct, - 'int': int, - 'uint': uint, - 'mapping': mapping + contract: address, + address: address, + array: array, + bool: bool, + bytes: dynamicByteArray, + bytesX: fixedByteArray, + enum: enumType, + string: stringType, + struct: struct, + int: int, + uint: uint, + mapping: mapping } const currentType = typeClass(type) if (currentType === null) { diff --git a/libs/remix-debug/src/solidity-decoder/internalCallTree.ts b/libs/remix-debug/src/solidity-decoder/internalCallTree.ts index 0c63112626..cc0cddf36b 100644 --- a/libs/remix-debug/src/solidity-decoder/internalCallTree.ts +++ b/libs/remix-debug/src/solidity-decoder/internalCallTree.ts @@ -13,7 +13,6 @@ import { extractLocationFromAstVariable } from './types/util.js' * Triggers `callTreeBuildFailed` event when tree fails to build */ export class InternalCallTree { - includeLocalVariables debugWithGeneratedSources event @@ -121,21 +120,21 @@ export class InternalCallTree { } retrieveFunctionsStack (vmtraceIndex) { - let scope = this.findScope(vmtraceIndex) + const scope = this.findScope(vmtraceIndex) if (!scope) return [] let scopeId = this.scopeStarts[scope.firstStep] - let functions = [] + const functions = [] if (!scopeId) return functions let i = 0 // eslint-disable-next-line no-constant-condition while (true) { i += 1 if (i > 1000) throw new Error('retrieFunctionStack: recursion too deep') - let functionDefinition = this.functionDefinitionsByScope[scopeId] + const functionDefinition = this.functionDefinitionsByScope[scopeId] if (functionDefinition !== undefined) { functions.push(functionDefinition) } - let parent = this.parentScope(scopeId) + const parent = this.parentScope(scopeId) if (!parent) break else scopeId = parent } @@ -294,8 +293,8 @@ async function includeVariableDeclaration (tree, step, sourceLocation, scopeId, const stack = tree.traceManager.getStackAt(step) states = tree.solidityProxy.extractStatesDefinitions() if (functionDefinition.parameters) { - let inputs = functionDefinition.parameters - let outputs = functionDefinition.returnParameters + const inputs = functionDefinition.parameters + const outputs = functionDefinition.returnParameters // for (const element of functionDefinition.parameters) { // if (element.nodeType === 'ParameterList') { // if (!inputs) inputs = element @@ -369,8 +368,8 @@ function extractFunctionDefinitions (ast, astWalker) { } function addParams (parameterList, tree, scopeId, states, contractName, sourceLocation, stackLength, stackPosition, dir) { - let params = [] - for (let inputParam in parameterList.parameters) { + const params = [] + for (const inputParam in parameterList.parameters) { const param = parameterList.parameters[inputParam] const stackDepth = stackLength + (dir * stackPosition) if (stackDepth >= 0) { diff --git a/libs/remix-debug/src/solidity-decoder/localDecoder.ts b/libs/remix-debug/src/solidity-decoder/localDecoder.ts index 8bb4b8ad8b..89aba92a2a 100644 --- a/libs/remix-debug/src/solidity-decoder/localDecoder.ts +++ b/libs/remix-debug/src/solidity-decoder/localDecoder.ts @@ -3,13 +3,13 @@ export async function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, storageResolver, currentSourceLocation, cursor) { const scope = internalTreeCall.findScope(vmtraceIndex) if (!scope) { - const error = { 'message': 'Can\'t display locals. reason: compilation result might not have been provided' } + const error = { message: 'Can\'t display locals. reason: compilation result might not have been provided' } throw error } const locals = {} memory = formatMemory(memory) let anonymousIncr = 1 - for (let local in scope.locals) { + for (const local in scope.locals) { var variable = scope.locals[local] if (variable.stackDepth < stack.length && variable.sourceLocation.start <= currentSourceLocation.start) { let name = variable.name diff --git a/libs/remix-debug/src/solidity-decoder/solidityProxy.ts b/libs/remix-debug/src/solidity-decoder/solidityProxy.ts index 4f87e12d66..b9c27dca82 100644 --- a/libs/remix-debug/src/solidity-decoder/solidityProxy.ts +++ b/libs/remix-debug/src/solidity-decoder/solidityProxy.ts @@ -5,14 +5,13 @@ import { extractStateVariables } from './stateDecoder' import { extractContractDefinitions, extractStatesDefinitions } from './astHelper' export class SolidityProxy { - cache getCurrentCalledAddressAt getCode sources contracts - constructor ({getCurrentCalledAddressAt, getCode}) { + constructor ({ getCurrentCalledAddressAt, getCode }) { this.cache = new Cache() this.reset({}) this.getCurrentCalledAddressAt = getCurrentCalledAddressAt @@ -127,8 +126,8 @@ export class SolidityProxy { function contractObjectFromCode (contracts, code, address) { const isCreation = isContractCreation(address) - for (let file in contracts) { - for (let contract in contracts[file]) { + for (const file in contracts) { + for (const contract in contracts[file]) { const bytecode = isCreation ? contracts[file][contract].evm.bytecode.object : contracts[file][contract].evm.deployedBytecode.object if (util.compareByteCode(code, '0x' + bytecode)) { return { name: contract, contract: contracts[file][contract] } @@ -139,7 +138,6 @@ function contractObjectFromCode (contracts, code, address) { } class Cache { - contractObjectByAddress stateVariablesByContractName contractDeclarations @@ -148,6 +146,7 @@ class Cache { constructor () { this.reset() } + reset () { this.contractObjectByAddress = {} this.stateVariablesByContractName = {} diff --git a/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts b/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts index 9870b57b81..3792579531 100644 --- a/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts @@ -6,7 +6,6 @@ import { RefType } from './RefType' const sha3256 = util.sha3_256 export class ArrayType extends RefType { - underlyingType arraySize @@ -72,7 +71,7 @@ export class ArrayType extends RefType { currentLocation.offset = 0 } } - return {value: ret, length: '0x' + size.toString(16), type: this.typeName} + return { value: ret, length: '0x' + size.toString(16), type: this.typeName } } decodeFromMemoryInternal (offset, memory, skip) { diff --git a/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts b/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts index 2ed55bd630..917855c42a 100644 --- a/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts +++ b/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts @@ -16,7 +16,7 @@ export class DynamicByteArray extends RefType { value = await extractHexValue(location, storageResolver, this.storageBytes) } catch (e) { console.log(e) - return {value: '', type: this.typeName} + return { value: '', type: this.typeName } } const bn = new BN(value, 16) if (bn.testn(0)) { @@ -28,7 +28,7 @@ export class DynamicByteArray extends RefType { currentSlot = await readFromStorage(dataPos, storageResolver) } catch (e) { console.log(e) - return {value: '', type: this.typeName} + return { value: '', type: this.typeName } } while (length.gt(new BN(ret.length)) && ret.length < 32000) { currentSlot = currentSlot.replace('0x', '') @@ -38,13 +38,13 @@ export class DynamicByteArray extends RefType { currentSlot = await readFromStorage(dataPos, storageResolver) } catch (e) { console.log(e) - return {value: '', type: this.typeName} + return { value: '', type: this.typeName } } } - return {value: '0x' + ret.replace(/(00)+$/, ''), length: '0x' + length.toString(16), type: this.typeName} + return { value: '0x' + ret.replace(/(00)+$/, ''), length: '0x' + length.toString(16), type: this.typeName } } else { var size = parseInt(value.substr(value.length - 2, 2), 16) / 2 - return {value: '0x' + value.substr(0, size * 2), length: '0x' + size.toString(16), type: this.typeName} + return { value: '0x' + value.substr(0, size * 2), length: '0x' + size.toString(16), type: this.typeName } } } @@ -52,7 +52,6 @@ export class DynamicByteArray extends RefType { offset = 2 * offset let length = memory.substr(offset, 64) length = 2 * parseInt(length, 16) - return {length: '0x' + length.toString(16), value: '0x' + memory.substr(offset + 64, length), type: this.typeName} + return { length: '0x' + length.toString(16), value: '0x' + memory.substr(offset + 64, length), type: this.typeName } } } - diff --git a/libs/remix-debug/src/solidity-decoder/types/Enum.ts b/libs/remix-debug/src/solidity-decoder/types/Enum.ts index 956b09ecca..412533f17f 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Enum.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Enum.ts @@ -2,7 +2,6 @@ import { ValueType } from './ValueType' export class Enum extends ValueType { - enumDef constructor (enumDef) { diff --git a/libs/remix-debug/src/solidity-decoder/types/Mapping.ts b/libs/remix-debug/src/solidity-decoder/types/Mapping.ts index cf7fc8958e..a6fa6240b6 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Mapping.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Mapping.ts @@ -1,11 +1,10 @@ 'use strict' import { RefType } from './RefType' import { normalizeHex } from './util' -import { toBuffer, setLengthLeft, keccak, BN, bufferToHex} from 'ethereumjs-util' +import { toBuffer, setLengthLeft, keccak, BN, bufferToHex } from 'ethereumjs-util' import { intToBuffer } from 'ethjs-util' export class Mapping extends RefType { - keyType valueType initialDecodedState @@ -34,13 +33,13 @@ export class Mapping extends RefType { const mappingPreimages = await storageResolver.mappingsLocation(corrections) let ret = await this.decodeMappingsLocation(mappingPreimages, location, storageResolver) // fetch mapping storage changes ret = Object.assign({}, this.initialDecodedState, ret) // merge changes - return {value: ret, type: this.typeName} + return { value: ret, type: this.typeName } } decodeFromMemoryInternal (offset, memory) { // mappings can only exist in storage and not in memory // so this should never be called - return {value: '', length: '0x', type: this.typeName} + return { value: '', length: '0x', type: this.typeName } } async decodeMappingsLocation (preimages, location, storageResolver) { @@ -49,7 +48,7 @@ export class Mapping extends RefType { return {} } const ret = {} - for (let i in preimages[mapSlot]) { + for (const i in preimages[mapSlot]) { const mapLocation = getMappingLocation(i, location.slot) const globalLocation = { offset: location.offset, @@ -71,13 +70,13 @@ function getMappingLocation (key, position) { mappingP = setLengthLeft(mappingP, 32) const mappingKeyBuf = concatTypedArrays(mappingK, mappingP) const mappingKeyPreimage: string = '0x' + mappingKeyBuf.toString('hex') - let mappingStorageLocation: Buffer = keccak(mappingKeyPreimage) + const mappingStorageLocation: Buffer = keccak(mappingKeyPreimage) const mappingStorageLocationinBn: BN = new BN(mappingStorageLocation, 16) return mappingStorageLocationinBn } function concatTypedArrays (a, b) { // a, b TypedArray of same type - let c = new (a.constructor)(a.length + b.length) + const c = new (a.constructor)(a.length + b.length) c.set(a, 0) c.set(b, a.length) return c diff --git a/libs/remix-debug/src/solidity-decoder/types/RefType.ts b/libs/remix-debug/src/solidity-decoder/types/RefType.ts index 2ef3c95963..881667f8de 100644 --- a/libs/remix-debug/src/solidity-decoder/types/RefType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/RefType.ts @@ -2,7 +2,6 @@ import { toBN } from './util' export class RefType { - location storageSlots storageBytes @@ -28,7 +27,7 @@ export class RefType { */ async decodeFromStack (stackDepth, stack, memory, storageResolver, cursor) { if (stack.length - 1 < stackDepth) { - return {error: '', type: this.typeName} + return { error: '', type: this.typeName } } let offset = stack[stack.length - 1 - stackDepth] if (this.isInStorage()) { @@ -37,13 +36,13 @@ export class RefType { return await this.decodeFromStorage({ offset: 0, slot: offset }, storageResolver) } catch (e) { console.log(e) - return {error: '', type: this.typeName} + return { error: '', type: this.typeName } } } else if (this.isInMemory()) { offset = parseInt(offset, 16) return this.decodeFromMemoryInternal(offset, memory, cursor) } else { - return {error: '', type: this.typeName} + return { error: '', type: this.typeName } } } diff --git a/libs/remix-debug/src/solidity-decoder/types/StringType.ts b/libs/remix-debug/src/solidity-decoder/types/StringType.ts index 49a37e31cc..29340fd168 100644 --- a/libs/remix-debug/src/solidity-decoder/types/StringType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/StringType.ts @@ -2,7 +2,6 @@ import { DynamicByteArray } from './DynamicByteArray' export class StringType extends DynamicByteArray { - typeName constructor (location) { @@ -42,11 +41,11 @@ function format (decoded) { } let value = decoded.value value = value.replace('0x', '').replace(/(..)/g, '%$1') - const ret = {length: decoded.length, raw: decoded.value, type: 'string'} + const ret = { length: decoded.length, raw: decoded.value, type: 'string' } try { - ret['value'] = decodeURIComponent(value) + ret.value = decodeURIComponent(value) } catch (e) { - ret['error'] = 'Invalid UTF8 encoding' + ret.error = 'Invalid UTF8 encoding' ret.raw = decoded.value } return ret diff --git a/libs/remix-debug/src/solidity-decoder/types/Struct.ts b/libs/remix-debug/src/solidity-decoder/types/Struct.ts index 22883d6b22..d71c43652c 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Struct.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Struct.ts @@ -3,7 +3,6 @@ import { add } from './util' import { RefType } from './RefType' export class Struct extends RefType { - members constructor (memberDetails, location, fullType) { @@ -25,7 +24,7 @@ export class Struct extends RefType { ret[item.name] = '' } } - return {value: ret, type: this.typeName} + return { value: ret, type: this.typeName } } decodeFromMemoryInternal (offset, memory) { @@ -36,6 +35,6 @@ export class Struct extends RefType { ret[item.name] = member offset += 32 }) - return {value: ret, type: this.typeName} + return { value: ret, type: this.typeName } } } diff --git a/libs/remix-debug/src/solidity-decoder/types/ValueType.ts b/libs/remix-debug/src/solidity-decoder/types/ValueType.ts index 9340453d8b..a657a51125 100644 --- a/libs/remix-debug/src/solidity-decoder/types/ValueType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/ValueType.ts @@ -2,7 +2,6 @@ import { extractHexValue } from './util' export class ValueType { - storageSlots storageBytes typeName @@ -25,10 +24,10 @@ export class ValueType { async decodeFromStorage (location, storageResolver) { try { var value = await extractHexValue(location, storageResolver, this.storageBytes) - return {value: this.decodeValue(value), type: this.typeName} + return { value: this.decodeValue(value), type: this.typeName } } catch (e) { console.log(e) - return {value: '', type: this.typeName} + return { value: '', type: this.typeName } } } @@ -47,7 +46,7 @@ export class ValueType { } else { value = this.decodeValue(stack[stack.length - 1 - stackDepth].replace('0x', '')) } - return {value, type: this.typeName} + return { value, type: this.typeName } } /** @@ -58,7 +57,7 @@ export class ValueType { * @return {Object} - decoded value */ decodeFromMemory (offset, memory) { - let value = memory.substr(2 * offset, 64) - return {value: this.decodeValue(value), type: this.typeName} + const value = memory.substr(2 * offset, 64) + return { value: this.decodeValue(value), type: this.typeName } } } diff --git a/libs/remix-debug/src/solidity-decoder/types/util.ts b/libs/remix-debug/src/solidity-decoder/types/util.ts index a13cc8fc86..fed6ea44f8 100644 --- a/libs/remix-debug/src/solidity-decoder/types/util.ts +++ b/libs/remix-debug/src/solidity-decoder/types/util.ts @@ -9,7 +9,7 @@ export function decodeIntFromHex (value, byteLength, signed) { return bigNumber.toString(10) } -export function readFromStorage(slot, storageResolver): Promise { +export function readFromStorage (slot, storageResolver): Promise { const hexSlot = '0x' + normalizeHex(bufferToHex(slot)) return new Promise((resolve, reject) => { storageResolver.storageSlot(hexSlot, (error, slot) => { @@ -78,7 +78,7 @@ export function removeLocation (type) { } export function extractLocation (type) { - let match = type.match(/( storage ref| storage pointer| memory| calldata)?$/) + const match = type.match(/( storage ref| storage pointer| memory| calldata)?$/) if (match[1] !== '') { return match[1].trim() } diff --git a/libs/remix-debug/src/source/offsetToLineColumnConverter.ts b/libs/remix-debug/src/source/offsetToLineColumnConverter.ts index f2089cb71e..298feaa1c6 100644 --- a/libs/remix-debug/src/source/offsetToLineColumnConverter.ts +++ b/libs/remix-debug/src/source/offsetToLineColumnConverter.ts @@ -2,11 +2,10 @@ import { getLinebreakPositions, convertOffsetToLineColumn } from './sourceMappingDecoder' export class OffsetToColumnConverter { - lineBreakPositionsByContent sourceMappingDecoder - constructor(compilerEvent) { + constructor (compilerEvent) { this.lineBreakPositionsByContent = {} if (compilerEvent) { compilerEvent.register('compilationFinished', (success, data, source) => { @@ -17,7 +16,7 @@ export class OffsetToColumnConverter { offsetToLineColumn (rawLocation, file, sources, asts) { if (!this.lineBreakPositionsByContent[file]) { - for (let filename in asts) { + for (const filename in asts) { const source = asts[filename] // source id was string before. in newer versions it has been changed to an integer so we need to check the type here if (typeof source.id === 'string') source.id = parseInt(source.id, 10) diff --git a/libs/remix-debug/src/source/sourceLocationTracker.ts b/libs/remix-debug/src/source/sourceLocationTracker.ts index 006fd6c34b..78f09376f9 100644 --- a/libs/remix-debug/src/source/sourceLocationTracker.ts +++ b/libs/remix-debug/src/source/sourceLocationTracker.ts @@ -8,12 +8,11 @@ import { util } from '@remix-project/remix-lib' * Process the source code location for the current executing bytecode */ export class SourceLocationTracker { - opts codeManager event sourceMapByAddress - + constructor (_codeManager, { debugWithGeneratedSources }) { this.opts = { debugWithGeneratedSources: debugWithGeneratedSources || false @@ -32,7 +31,7 @@ export class SourceLocationTracker { */ async getSourceLocationFromInstructionIndex (address, index, contracts) { const sourceMap = await this.extractSourceMap(this, this.codeManager, address, contracts) - return atIndex(index, sourceMap['map']) + return atIndex(index, sourceMap.map) } /** @@ -42,10 +41,10 @@ export class SourceLocationTracker { * @param {Int} vmtraceStepIndex - index of the current code in the vmtrace * @param {Object} contractDetails - AST of compiled contracts */ - async getSourceLocationFromVMTraceIndex (address, vmtraceStepIndex, contracts) { + async getSourceLocationFromVMTraceIndex (address, vmtraceStepIndex, contracts) { const sourceMap = await this.extractSourceMap(this, this.codeManager, address, contracts) const index = this.codeManager.getInstructionIndex(address, vmtraceStepIndex) - return atIndex(index, sourceMap['map']) + return atIndex(index, sourceMap.map) } /** @@ -68,10 +67,10 @@ export class SourceLocationTracker { * @param {Object} contractDetails - AST of compiled contracts */ async getValidSourceLocationFromVMTraceIndex (address, vmtraceStepIndex, contracts) { - let map: Record = { file: -1} + let map: Record = { file: -1 } while (vmtraceStepIndex >= 0 && map.file === -1) { map = await this.getSourceLocationFromVMTraceIndex(address, vmtraceStepIndex, contracts) - vmtraceStepIndex = vmtraceStepIndex - 1 + vmtraceStepIndex = vmtraceStepIndex - 1 } return map } @@ -83,10 +82,10 @@ export class SourceLocationTracker { private getSourceMap (address, code, contracts) { const isCreation = isContractCreation(address) let bytes - for (let file in contracts) { - for (let contract in contracts[file]) { + for (const file in contracts) { + for (const contract in contracts[file]) { const bytecode = contracts[file][contract].evm.bytecode - const deployedBytecode = contracts[file][contract].evm.deployedBytecode + const deployedBytecode = contracts[file][contract].evm.deployedBytecode if (!deployedBytecode) continue bytes = isCreation ? bytecode.object : deployedBytecode.object @@ -110,7 +109,7 @@ export class SourceLocationTracker { if (!isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap return resolve(sourceMap) } - reject('no sourcemap associated with the code ' + address) + reject(new Error('no sourcemap associated with the code ' + address)) }).catch(reject) }) } diff --git a/libs/remix-debug/src/source/sourceMappingDecoder.ts b/libs/remix-debug/src/source/sourceMappingDecoder.ts index 74d1cf317c..e6df9bce3a 100644 --- a/libs/remix-debug/src/source/sourceMappingDecoder.ts +++ b/libs/remix-debug/src/source/sourceMappingDecoder.ts @@ -33,7 +33,7 @@ export function decode (value) { export function decompressAll (mapping) { const map = mapping.split(';') const ret = [] - for (let k in map) { + for (const k in map) { const compressed = map[k].split(':') const sourceMap = { start: compressed[0] ? parseInt(compressed[0]) : ret[ret.length - 1].start, @@ -74,10 +74,9 @@ export function convertOffsetToLineColumn (sourceLocation, lineBreakPositions) { end: convertFromCharPosition(sourceLocation.start + sourceLocation.length, lineBreakPositions) } } - return {start: null, end: null} + return { start: null, end: null } } - function convertFromCharPosition (pos, lineBreakPositions) { let line = util.findLowerBound(pos, lineBreakPositions) if (lineBreakPositions[line] !== pos) { @@ -85,7 +84,7 @@ function convertFromCharPosition (pos, lineBreakPositions) { } const beginColumn = line === 0 ? 0 : (lineBreakPositions[line - 1] + 1) const column = pos - beginColumn - return {line, column} + return { line, column } } function sourceLocationFromAstNode (astNode) { @@ -173,7 +172,7 @@ export function nodesAtPosition (astNodeType, position, ast) { * @return Object { start, length, file, jump } */ export function atIndex (index, mapping) { - let ret = {} + const ret = {} const map = mapping.split(';') if (index >= map.length) { index = map.length - 1 @@ -184,19 +183,19 @@ export function atIndex (index, mapping) { continue } current = current.split(':') - if (ret['start'] === undefined && current[0] && current[0] !== '-1' && current[0].length) { - ret['start'] = parseInt(current[0]) + if (ret.start === undefined && current[0] && current[0] !== '-1' && current[0].length) { + ret.start = parseInt(current[0]) } - if (ret['length'] === undefined && current[1] && current[1] !== '-1' && current[1].length) { - ret['length'] = parseInt(current[1]) + if (ret.length === undefined && current[1] && current[1] !== '-1' && current[1].length) { + ret.length = parseInt(current[1]) } - if (ret['file'] === undefined && current[2] && current[2].length) { - ret['file'] = parseInt(current[2]) + if (ret.file === undefined && current[2] && current[2].length) { + ret.file = parseInt(current[2]) } - if (ret['jump'] === undefined && current[3] && current[3].length) { - ret['jump'] = current[3] + if (ret.jump === undefined && current[3] && current[3].length) { + ret.jump = current[3] } - if (ret['start'] !== undefined && ret['length'] !== undefined && ret['file'] !== undefined && ret['jump'] !== undefined) { + if (ret.start !== undefined && ret.length !== undefined && ret.file !== undefined && ret.jump !== undefined) { break } } diff --git a/libs/remix-debug/src/storage/mappingPreimages.ts b/libs/remix-debug/src/storage/mappingPreimages.ts index a28e7f9208..a7fb99740b 100644 --- a/libs/remix-debug/src/storage/mappingPreimages.ts +++ b/libs/remix-debug/src/storage/mappingPreimages.ts @@ -11,12 +11,12 @@ import { sub } from '../solidity-decoder/types/util' */ export async function decodeMappingsKeys (web3, storage, corrections) { const ret = {} - if (!corrections.length) corrections.push({offset: 0, slot: 0}) - for (let hashedLoc in storage) { + if (!corrections.length) corrections.push({ offset: 0, slot: 0 }) + for (const hashedLoc in storage) { var preimage try { const key = storage[hashedLoc].key - for (let k in corrections) { + for (const k in corrections) { const corrected = sub(key, corrections[k].slot).toString(16) preimage = await getPreimage(web3, '0x' + corrected) if (preimage) break diff --git a/libs/remix-debug/src/storage/storageResolver.ts b/libs/remix-debug/src/storage/storageResolver.ts index 998eb84b3e..dfe97c5ec5 100644 --- a/libs/remix-debug/src/storage/storageResolver.ts +++ b/libs/remix-debug/src/storage/storageResolver.ts @@ -7,7 +7,6 @@ import { decodeMappingsKeys } from './mappingPreimages' * (TODO: one instance need to be shared over all the components) */ export class StorageResolver { - storageByAddress preimagesMappingByAddress maxSize @@ -93,7 +92,7 @@ export class StorageResolver { const result = await this.storageRangeWeb3Call(tx, address, slotKey, self.maxSize) const [storage, nextKey] = result if (!storage[slotKey] && slotKey !== self.zeroSlot) { // we don't cache the zero slot (could lead to inconsistency) - storage[slotKey] = {key: slotKey, value: self.zeroSlot} + storage[slotKey] = { key: slotKey, value: self.zeroSlot } } self.toCache(self, address, storage) if (slotKey === self.zeroSlot && !nextKey) { // only working if keys are sorted !! @@ -144,7 +143,7 @@ export class StorageResolver { } else if (result.storage) { resolve([result.storage, result.nextKey]) } else { - reject('the storage has not been provided') + reject(new Error('the storage has not been provided')) } }) } diff --git a/libs/remix-debug/src/storage/storageViewer.ts b/libs/remix-debug/src/storage/storageViewer.ts index 502b636cfb..ee174d3123 100644 --- a/libs/remix-debug/src/storage/storageViewer.ts +++ b/libs/remix-debug/src/storage/storageViewer.ts @@ -2,13 +2,12 @@ import { util } from '@remix-project/remix-lib' import { decodeMappingsKeys } from './mappingPreimages' - /** +/** * easier access to the storage resolver * Basically one instance is created foreach execution step and foreach component that need it. * (TODO: one instance need to be shared over all the components) */ export class StorageViewer { - context storageResolver web3 diff --git a/libs/remix-debug/src/trace/traceAnalyser.ts b/libs/remix-debug/src/trace/traceAnalyser.ts index 0612f3d4e5..ae8957b5ac 100644 --- a/libs/remix-debug/src/trace/traceAnalyser.ts +++ b/libs/remix-debug/src/trace/traceAnalyser.ts @@ -2,10 +2,9 @@ import * as traceHelper from './traceHelper' export class TraceAnalyser { - traceCache trace - + constructor (_cache) { this.traceCache = _cache this.trace = null @@ -42,7 +41,7 @@ export class TraceAnalyser { const memory = this.trace[this.traceCache.memoryChanges[this.traceCache.memoryChanges.length - 1]].memory const noOfReturnParams = size / 64 const memoryInString = memory.join('') - let returnParamsObj = [] + const returnParamsObj = [] for (let i = 0; i < noOfReturnParams; i++) { returnParamsObj.push('0x' + memoryInString.substring(offset, offset + 64)) offset += 64 @@ -141,4 +140,3 @@ export class TraceAnalyser { return context } } - diff --git a/libs/remix-debug/src/trace/traceCache.ts b/libs/remix-debug/src/trace/traceCache.ts index e44ac698bc..43e45a0373 100644 --- a/libs/remix-debug/src/trace/traceCache.ts +++ b/libs/remix-debug/src/trace/traceCache.ts @@ -3,7 +3,6 @@ import { util } from '@remix-project/remix-lib' const { sha3_256 } = util export class TraceCache { - returnValues currentCall callsTree @@ -16,11 +15,10 @@ export class TraceCache { storageChanges sstore - constructor() { + constructor () { this.init() } - init () { // ...Changes contains index in the vmtrace of the corresponding changes @@ -53,7 +51,7 @@ export class TraceCache { // outOfGas has been removed because gas left logging is apparently made differently // in the vm/geth/eth. TODO add the error property (with about the error in all clients) pushCall (step, index, address, callStack, reverted) { - let validReturnStep = step.op === 'RETURN' || step.op === 'STOP' + const validReturnStep = step.op === 'RETURN' || step.op === 'STOP' if ((validReturnStep || reverted) && (this.currentCall)) { this.currentCall.call.return = index - 1 if (!validReturnStep) { @@ -63,7 +61,7 @@ export class TraceCache { this.currentCall = parent ? { call: parent.call, parent: parent.parent } : null return } - let call = { + const call = { op: step.op, address: address, callStack: callStack, @@ -102,10 +100,10 @@ export class TraceCache { pushStoreChanges (index, address, key, value) { this.sstore[index] = { - 'address': address, - 'key': key, - 'value': value, - 'hashedKey': sha3_256(key) + address: address, + key: key, + value: value, + hashedKey: sha3_256(key) } this.storageChanges.push(index) } diff --git a/libs/remix-debug/src/trace/traceHelper.ts b/libs/remix-debug/src/trace/traceHelper.ts index cc3d3da253..aefa8a2957 100644 --- a/libs/remix-debug/src/trace/traceHelper.ts +++ b/libs/remix-debug/src/trace/traceHelper.ts @@ -2,7 +2,7 @@ import { helpers } from '@remix-project/remix-lib' const { ui } = helpers - // vmTraceIndex has to point to a CALL, CODECALL, ... +// vmTraceIndex has to point to a CALL, CODECALL, ... export function resolveCalledAddress (vmTraceIndex, trace) { const step = trace[vmTraceIndex] if (isCreateInstruction(step)) { @@ -66,4 +66,3 @@ export function contractCreationToken (index) { export function isContractCreation (address) { return address.indexOf('(Contract Creation - Step') !== -1 } - diff --git a/libs/remix-debug/src/trace/traceManager.ts b/libs/remix-debug/src/trace/traceManager.ts index 8be41a40df..b3f1f567e7 100644 --- a/libs/remix-debug/src/trace/traceManager.ts +++ b/libs/remix-debug/src/trace/traceManager.ts @@ -6,7 +6,6 @@ import { isCreateInstruction } from './traceHelper' import { util } from '@remix-project/remix-lib' export class TraceManager { - web3 isLoading: boolean trace @@ -33,10 +32,10 @@ export class TraceManager { try { const result = await this.getTrace(tx.hash) - if (result['structLogs'].length > 0) { - this.trace = result['structLogs'] + if (result.structLogs.length > 0) { + this.trace = result.structLogs - this.traceAnalyser.analyse(result['structLogs'], tx) + this.traceAnalyser.analyse(result.structLogs, tx) this.isLoading = false return true } @@ -82,7 +81,7 @@ export class TraceManager { getLength (callback) { if (!this.trace) { - callback('no trace available', null) + callback(new Error('no trace available'), null) } else { callback(null, this.trace.length) } @@ -136,7 +135,7 @@ export class TraceManager { getStackAt (stepIndex) { this.checkRequestedStep(stepIndex) if (this.trace[stepIndex] && this.trace[stepIndex].stack) { // there's always a stack - let stack = this.trace[stepIndex].stack.slice(0) + const stack = this.trace[stepIndex].stack.slice(0) stack.reverse() return stack } else { @@ -268,7 +267,7 @@ export class TraceManager { } waterfall (calls, stepindex, cb) { - let ret = [] + const ret = [] let retError = null for (var call in calls) { calls[call].apply(this, [stepindex, function (error, result) { diff --git a/libs/remix-debug/src/trace/traceStepManager.ts b/libs/remix-debug/src/trace/traceStepManager.ts index ee92704234..9890bf57ef 100644 --- a/libs/remix-debug/src/trace/traceStepManager.ts +++ b/libs/remix-debug/src/trace/traceStepManager.ts @@ -4,7 +4,6 @@ import { isCallInstruction, isCallToPrecompiledContract, isReturnInstruction } f import { util } from '@remix-project/remix-lib' export class TraceStepManager { - traceAnalyser constructor (_traceAnalyser) {