Skip to content
Merged
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
25 changes: 15 additions & 10 deletions apps/remix-ide/src/app/udapp/make-udapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var registry = require('../../global/registry')
var remixLib = require('@remix-project/remix-lib')
var yo = require('yo-yo')
var EventsDecoder = remixLib.execution.EventsDecoder
var TransactionReceiptResolver = require('../../lib/transactionReceiptResolver')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactionReceiptResolver.js the file seems not removed, do you still need it?


const transactionDetailsLinks = {
'Main': 'https://www.etherscan.io/tx/',
Expand All @@ -27,29 +26,35 @@ export function makeUdapp (blockchain, compilersArtefacts, logHtmlCallback) {
})

// ----------------- Tx listener -----------------
const transactionReceiptResolver = new TransactionReceiptResolver(blockchain)
let _transactionReceipts = {}
const transactionReceiptResolver = (tx, cb) => {
if (_transactionReceipts[tx.hash]) {
return cb(null, _transactionReceipts[tx.hash])
}
blockchain.web3().eth.getTransactionReceipt(tx.hash, (error, receipt) => {
if (error) {
return cb(error)
}
_transactionReceipts[tx.hash] = receipt
cb(null, receipt)
})
}

const txlistener = blockchain.getTxListener({
api: {
contracts: function () {
if (compilersArtefacts['__last']) return compilersArtefacts.getAllContractDatas()
return null
},
resolveReceipt: function (tx, cb) {
transactionReceiptResolver.resolve(tx, cb)
}
resolveReceipt: transactionReceiptResolver
}
})

registry.put({api: txlistener, name: 'txlistener'})
blockchain.startListening(txlistener)

const eventsDecoder = new EventsDecoder({
api: {
resolveReceipt: function (tx, cb) {
transactionReceiptResolver.resolve(tx, cb)
}
}
resolveReceipt: transactionReceiptResolver
})
txlistener.startListening()
registry.put({api: eventsDecoder, name: 'eventsDecoder'})
Expand Down
23 changes: 0 additions & 23 deletions apps/remix-ide/src/lib/transactionReceiptResolver.js

This file was deleted.

5 changes: 3 additions & 2 deletions libs/remix-debug/src/Ethdebugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Ethdebugger (opts) {

this.traceManager = new TraceManager({web3: this.web3})
this.codeManager = new CodeManager(this.traceManager)
this.solidityProxy = new SolidityProxy(this.traceManager, this.codeManager)
this.solidityProxy = new SolidityProxy({getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager)})
this.storageResolver = null

this.callTree = new InternalCallTree(this.event, this.traceManager, this.solidityProxy, this.codeManager, { includeLocalVariables: true })
Expand All @@ -42,10 +42,11 @@ function Ethdebugger (opts) {
Ethdebugger.prototype.setManagers = function () {
this.traceManager = new TraceManager({web3: this.web3})
this.codeManager = new CodeManager(this.traceManager)
this.solidityProxy = new SolidityProxy(this.traceManager, this.codeManager)
this.solidityProxy = new SolidityProxy({getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager)})
this.storageResolver = null

this.callTree = new InternalCallTree(this.event, this.traceManager, this.solidityProxy, this.codeManager, { includeLocalVariables: true })
this.event.trigger('managersChanged')
}

Ethdebugger.prototype.resolveStep = function (index) {
Expand Down
87 changes: 47 additions & 40 deletions libs/remix-debug/src/code/breakpointManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ 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 (_debugger, _locationToRowConverter, _jumpToCallback) {
constructor ({traceManager, callTree, solidityProxy, locationToRowConverter}) {
this.event = new EventManager()
this.debugger = _debugger
this.traceManager = traceManager
this.callTree = callTree
this.solidityProxy = solidityProxy
this.breakpoints = {}
this.locationToRowConverter = _locationToRowConverter
this.locationToRowConverter = locationToRowConverter
this.previousLine
this.jumpToCallback = _jumpToCallback || (() => {}) // eslint-disable-line
}

setManagers({traceManager, callTree, solidityProxy}) {
this.traceManager = traceManager
this.callTree = callTree
this.solidityProxy = solidityProxy
}

/**
Expand All @@ -30,7 +37,10 @@ class BreakpointManager {
*
*/
async jumpNextBreakpoint (fromStep, defaultToLimit) {
this.jump(fromStep || 0, 1, defaultToLimit)
if (!this.locationToRowConverter) {
return console.log('row converter not provided')
}
this.jump(fromStep || 0, 1, defaultToLimit, this.traceManager.trace)
}

/**
Expand All @@ -39,7 +49,29 @@ class BreakpointManager {
*
*/
async jumpPreviousBreakpoint (fromStep, defaultToLimit) {
this.jump(fromStep || 0, -1, defaultToLimit)
if (!this.locationToRowConverter) {
return console.log('row converter not provided')
}
this.jump(fromStep || 0, -1, defaultToLimit, this.traceManager.trace)
}

depthChange (step, trace) {
return trace[step].depth !== trace[step - 1].depth
}

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
if ((helper.isJumpDestInstruction(trace[currentStep]) && previousSourceLocation.jump === 'o') ||
this.depthChange(currentStep, trace) ||
(sourceLocation.start <= previousSourceLocation.start &&
sourceLocation.start + sourceLocation.length >= previousSourceLocation.start + previousSourceLocation.length)) {
return false
}
this.event.trigger('breakpointStep', [currentStep])
this.event.trigger('breakpointHit', [sourceLocation, currentStep])
return true
}

/**
Expand All @@ -48,55 +80,30 @@ class BreakpointManager {
* @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
*
*/
async jump (fromStep, direction, defaultToLimit) {
if (!this.locationToRowConverter) {
console.log('row converter not provided')
return
}

function depthChange (step, trace) {
return trace[step].depth !== trace[step - 1].depth
}

function hitLine (currentStep, sourceLocation, previousSourceLocation, self) {
// 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
if ((helper.isJumpDestInstruction(self.debugger.traceManager.trace[currentStep]) && previousSourceLocation.jump === 'o') ||
depthChange(currentStep, self.debugger.traceManager.trace) ||
(sourceLocation.start <= previousSourceLocation.start &&
sourceLocation.start + sourceLocation.length >= previousSourceLocation.start + previousSourceLocation.length)) {
return false
}
self.jumpToCallback(currentStep)
self.event.trigger('breakpointHit', [sourceLocation, currentStep])
return true
}

async jump (fromStep, direction, defaultToLimit, trace) {
let sourceLocation
let previousSourceLocation
let currentStep = fromStep + direction
let lineHadBreakpoint = false
while (currentStep > 0 && currentStep < this.debugger.traceManager.trace.length) {
while (currentStep > 0 && currentStep < trace.length) {
try {
previousSourceLocation = sourceLocation
sourceLocation = await this.debugger.callTree.extractValidSourceLocation(currentStep)
sourceLocation = await this.callTree.extractValidSourceLocation(currentStep)
} catch (e) {
console.log('cannot jump to breakpoint ' + e)
return
return console.log('cannot jump to breakpoint ' + e)
}
let 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
if (hitLine(currentStep + 1, previousSourceLocation, sourceLocation, this)) {
if (this.hitLine(currentStep + 1, previousSourceLocation, sourceLocation, trace)) {
return
}
}
this.previousLine = lineColumn.start.line
if (this.hasBreakpointAtLine(sourceLocation.file, lineColumn.start.line)) {
lineHadBreakpoint = true
if (direction === 1 && hitLine(currentStep, sourceLocation, previousSourceLocation, this)) {
if (direction === 1 && this.hitLine(currentStep, sourceLocation, previousSourceLocation, trace)) {
return
}
}
Expand All @@ -108,9 +115,9 @@ class BreakpointManager {
return
}
if (direction === -1) {
this.jumpToCallback(0)
this.event.trigger('breakpointStep', [0])
} else if (direction === 1) {
this.jumpToCallback(this.debugger.traceManager.trace.length - 1)
this.event.trigger('breakpointStep', [trace.length - 1])
}
}

Expand All @@ -122,7 +129,7 @@ class BreakpointManager {
* @return {Bool} return true if the given @arg fileIndex @arg line refers to a breakpoint
*/
hasBreakpointAtLine (fileIndex, line) {
const filename = this.debugger.solidityProxy.fileNameFromIndex(fileIndex)
const filename = this.solidityProxy.fileNameFromIndex(fileIndex)
if (!(filename && this.breakpoints[filename])) {
return false
}
Expand Down
11 changes: 10 additions & 1 deletion libs/remix-debug/src/code/codeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ function CodeManager (_traceManager) {
this.event = new EventManager()
this.isLoading = false
this.traceManager = _traceManager
this.codeResolver = new CodeResolver({web3: this.traceManager.web3})
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)
})
})
}})
}

/**
Expand Down
30 changes: 10 additions & 20 deletions libs/remix-debug/src/code/codeResolver.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
const codeUtils = require('./codeUtils')

function CodeResolver (options) {
this.web3 = options.web3
function CodeResolver ({getCode}) {
this.getCode = getCode

this.bytecodeByAddress = {} // bytes code by contract addesses
this.instructionsByAddress = {} // assembly items instructions list by contract addesses
Expand All @@ -16,20 +16,13 @@ CodeResolver.prototype.clear = function () {
}

CodeResolver.prototype.resolveCode = async function (address) {
return new Promise((resolve, reject) => {
const cache = this.getExecutingCodeFromCache(address)
if (cache) {
return resolve(cache)
}
const cache = this.getExecutingCodeFromCache(address)
if (cache) {
return cache
}

this.web3.eth.getCode(address, (error, code) => {
if (error) {
// return console.log(error)
return reject(error)
}
return resolve(this.cacheExecutingCode(address, code))
})
})
const code = await this.getCode(address)
return this.cacheExecutingCode(address, code)
}

CodeResolver.prototype.cacheExecutingCode = function (address, hexCode) {
Expand All @@ -41,11 +34,8 @@ CodeResolver.prototype.cacheExecutingCode = function (address, hexCode) {
}

CodeResolver.prototype.formatCode = function (hexCode) {
const code = codeUtils.nameOpCodes(Buffer.from(hexCode.substring(2), 'hex'))
return {
code: code[0],
instructionsIndexByBytesOffset: code[1]
}
const [code, instructionsIndexByBytesOffset] = codeUtils.nameOpCodes(Buffer.from(hexCode.substring(2), 'hex'))
return {code, instructionsIndexByBytesOffset}
}

CodeResolver.prototype.getExecutingCodeFromCache = function (address) {
Expand Down
18 changes: 11 additions & 7 deletions libs/remix-debug/src/debugger/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ function Debugger (options) {
compilationResult: this.compilationResult
})

this.breakPointManager = new BreakpointManager(this.debugger, async (sourceLocation) => {
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)
}, (step) => {
this.event.trigger('breakpointStep', [step])
}})

this.breakPointManager.event.register('managersChanged', () => {
const {traceManager, callTree, solidityProxy} = this.debugger
this.breakPointManager.setManagers({traceManager, callTree, solidityProxy})
})

this.breakPointManager.event.register('breakpointStep', (step) => {
this.step_manager.jumpTo(step)
})

this.debugger.setBreakpointManager(this.breakPointManager)
Expand All @@ -38,10 +46,6 @@ function Debugger (options) {
this.debugger.event.register('traceUnloaded', this, () => {
this.event.trigger('debuggerStatus', [false])
})

this.event.register('breakpointStep', (step) => {
this.step_manager.jumpTo(step)
})
}

Debugger.prototype.registerAndHighlightCodeItem = async function (index) {
Expand Down
4 changes: 2 additions & 2 deletions libs/remix-debug/src/solidity-decoder/decodeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ function computeOffsets (types, stateDefinitions, contractName, location) {
}

module.exports = {
parseType: parseType,
computeOffsets: computeOffsets,
parseType,
computeOffsets,
Uint: uint,
Address: address,
Bool: bool,
Expand Down
7 changes: 1 addition & 6 deletions libs/remix-debug/src/solidity-decoder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@ const stateDecoder = require('./stateDecoder')
const localDecoder = require('./localDecoder')
const InternalCallTree = require('./internalCallTree')

module.exports = {
SolidityProxy: SolidityProxy,
stateDecoder: stateDecoder,
localDecoder: localDecoder,
InternalCallTree: InternalCallTree
}
module.exports = {SolidityProxy, stateDecoder, localDecoder, InternalCallTree}
4 changes: 1 addition & 3 deletions libs/remix-debug/src/solidity-decoder/localDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ function formatMemory (memory) {
return memory
}

module.exports = {
solidityLocals: solidityLocals
}
module.exports = {solidityLocals}
Loading