Merge pull request #865 from ethereum/remove_global

remove global web3 object
pull/3094/head
yann300 6 years ago committed by GitHub
commit f4ef3c5863
  1. 3
      remix-core/index.js
  2. 16
      remix-core/src/code/codeManager.js
  3. 120
      remix-core/src/code/codeResolver.js
  4. 10
      remix-core/src/storage/mappingPreimages.js
  5. 204
      remix-core/src/storage/storageResolver.js
  6. 3
      remix-core/src/storage/storageViewer.js
  7. 8
      remix-core/src/trace/traceManager.js
  8. 7
      remix-core/src/trace/traceRetriever.js
  9. 13
      remix-core/test/codeManager.js
  10. 10
      remix-core/test/traceManager.js
  11. 29
      remix-debug/src/Ethdebugger.js
  12. 3
      remix-debug/test/vmCall.js
  13. 2
      remix-lib/README.md
  14. 2
      remix-lib/index.js
  15. 4
      remix-lib/src/global.js
  16. 5
      remix-solidity/test/decoder/localsTests/int.js
  17. 5
      remix-solidity/test/decoder/localsTests/misc.js
  18. 5
      remix-solidity/test/decoder/localsTests/misc2.js
  19. 5
      remix-solidity/test/decoder/localsTests/structArray.js
  20. 8
      remix-solidity/test/decoder/stateTests/mapping.js
  21. 3
      remix-solidity/test/decoder/vmCall.js

@ -5,9 +5,6 @@ var StorageResolver = require('./src/storage/storageResolver')
var TraceManager = require('./src/trace/traceManager') var TraceManager = require('./src/trace/traceManager')
module.exports = { module.exports = {
global: {
web3: null
},
code: { code: {
CodeManager: CodeManager, CodeManager: CodeManager,
BreakpointManager: BreakpointManager BreakpointManager: BreakpointManager

@ -3,7 +3,7 @@ var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var SourceMappingDecoder = remixLib.SourceMappingDecoder var SourceMappingDecoder = remixLib.SourceMappingDecoder
var codeResolver = require('./codeResolver') var CodeResolver = require('./codeResolver')
/* /*
resolve contract code referenced by vmtrace in order to be used by asm listview. resolve contract code referenced by vmtrace in order to be used by asm listview.
@ -16,7 +16,7 @@ function CodeManager (_traceManager) {
this.event = new EventManager() this.event = new EventManager()
this.isLoading = false this.isLoading = false
this.traceManager = _traceManager this.traceManager = _traceManager
this.codeResolver = codeResolver this.codeResolver = new CodeResolver({web3: this.traceManager.web3})
} }
/** /**
@ -57,12 +57,13 @@ CodeManager.prototype.resolveStep = function (stepIndex, tx) {
* @param {Function} cb - callback function, return the bytecode * @param {Function} cb - callback function, return the bytecode
*/ */
CodeManager.prototype.getCode = function (address, cb) { CodeManager.prototype.getCode = function (address, cb) {
const self = this
if (traceHelper.isContractCreation(address)) { if (traceHelper.isContractCreation(address)) {
var codes = codeResolver.getExecutingCodeFromCache(address) var codes = this.codeResolver.getExecutingCodeFromCache(address)
if (!codes) { if (!codes) {
this.traceManager.getContractCreationCode(address, function (error, hexCode) { this.traceManager.getContractCreationCode(address, function (error, hexCode) {
if (!error) { if (!error) {
codes = codeResolver.cacheExecutingCode(address, hexCode) codes = self.codeResolver.cacheExecutingCode(address, hexCode)
cb(null, codes) cb(null, codes)
} }
}) })
@ -70,7 +71,7 @@ CodeManager.prototype.getCode = function (address, cb) {
cb(null, codes) cb(null, codes)
} }
} else { } else {
codeResolver.resolveCode(address, function (address, code) { this.codeResolver.resolveCode(address, function (address, code) {
cb(null, code) cb(null, code)
}) })
} }
@ -111,12 +112,13 @@ CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast)
* @param {Function} callback - instruction index * @param {Function} callback - instruction index
*/ */
CodeManager.prototype.getInstructionIndex = function (address, step, callback) { CodeManager.prototype.getInstructionIndex = function (address, step, callback) {
const self = this
this.traceManager.getCurrentPC(step, function (error, pc) { this.traceManager.getCurrentPC(step, function (error, pc) {
if (error) { if (error) {
console.log(error) console.log(error)
callback('Cannot retrieve current PC for ' + step, null) callback('Cannot retrieve current PC for ' + step, null)
} else { } else {
var itemIndex = codeResolver.getInstructionIndex(address, pc) var itemIndex = self.codeResolver.getInstructionIndex(address, pc)
callback(null, itemIndex) callback(null, itemIndex)
} }
}) })
@ -132,7 +134,7 @@ CodeManager.prototype.getInstructionIndex = function (address, step, callback) {
* @return {Object} return the ast node of the function * @return {Object} return the ast node of the function
*/ */
CodeManager.prototype.getFunctionFromPC = function (address, pc, sourceMap, ast) { CodeManager.prototype.getFunctionFromPC = function (address, pc, sourceMap, ast) {
var instIndex = codeResolver.getInstructionIndex(address, pc) var instIndex = this.codeResolver.getInstructionIndex(address, pc)
return SourceMappingDecoder.findNodeAtInstructionIndex('FunctionDefinition', instIndex, sourceMap, ast) return SourceMappingDecoder.findNodeAtInstructionIndex('FunctionDefinition', instIndex, sourceMap, ast)
} }

@ -1,72 +1,74 @@
'use strict' 'use strict'
var codeUtils = require('./codeUtils') var codeUtils = require('./codeUtils')
var remixLib = require('remix-lib')
var global = remixLib.global
module.exports = { function CodeResolver (options) {
bytecodeByAddress: {}, // bytes code by contract addesses this.web3 = options.web3
instructionsByAddress: {}, // assembly items instructions list by contract addesses
instructionsIndexByBytesOffset: {}, // mapping between bytes offset and instructions index.
clear: function () { this.bytecodeByAddress = {} // bytes code by contract addesses
this.bytecodeByAddress = {} this.instructionsByAddress = {} // assembly items instructions list by contract addesses
this.instructionsByAddress = {} this.instructionsIndexByBytesOffset = {} // mapping between bytes offset and instructions index.
this.instructionsIndexByBytesOffset = {} }
},
resolveCode: function (address, callBack) {
var cache = this.getExecutingCodeFromCache(address)
if (cache) {
callBack(address, cache)
return
}
var self = this
this.loadCode(address, function (code) {
callBack(address, self.cacheExecutingCode(address, code))
})
},
loadCode: function (address, callback) { CodeResolver.prototype.clear = function () {
console.log('loading new code from web3 ' + address) this.bytecodeByAddress = {}
global.web3.eth.getCode(address, function (error, result) { this.instructionsByAddress = {}
if (error) { this.instructionsIndexByBytesOffset = {}
console.log(error) }
} else {
callback(result)
}
})
},
cacheExecutingCode: function (address, hexCode) { CodeResolver.prototype.resolveCode = function (address, callBack) {
var codes = this.formatCode(hexCode) var cache = this.getExecutingCodeFromCache(address)
this.bytecodeByAddress[address] = hexCode if (cache) {
this.instructionsByAddress[address] = codes.code callBack(address, cache)
this.instructionsIndexByBytesOffset[address] = codes.instructionsIndexByBytesOffset return
return this.getExecutingCodeFromCache(address) }
},
formatCode: function (hexCode) { var self = this
var code = codeUtils.nameOpCodes(new Buffer(hexCode.substring(2), 'hex')) this.loadCode(address, function (code) {
return { callBack(address, self.cacheExecutingCode(address, code))
code: code[0], })
instructionsIndexByBytesOffset: code[1] }
}
},
getExecutingCodeFromCache: function (address) { CodeResolver.prototype.loadCode = function (address, callback) {
if (this.instructionsByAddress[address]) { console.log('loading new code from web3 ' + address)
return { this.web3.eth.getCode(address, function (error, result) {
instructions: this.instructionsByAddress[address], if (error) {
instructionsIndexByBytesOffset: this.instructionsIndexByBytesOffset[address], console.log(error)
bytecode: this.bytecodeByAddress[address]
}
} else { } else {
return null callback(result)
} }
}, })
}
getInstructionIndex: function (address, pc) { CodeResolver.prototype.cacheExecutingCode = function (address, hexCode) {
return this.getExecutingCodeFromCache(address).instructionsIndexByBytesOffset[pc] var codes = this.formatCode(hexCode)
this.bytecodeByAddress[address] = hexCode
this.instructionsByAddress[address] = codes.code
this.instructionsIndexByBytesOffset[address] = codes.instructionsIndexByBytesOffset
return this.getExecutingCodeFromCache(address)
}
CodeResolver.prototype.formatCode = function (hexCode) {
var code = codeUtils.nameOpCodes(new Buffer(hexCode.substring(2), 'hex'))
return {
code: code[0],
instructionsIndexByBytesOffset: code[1]
}
}
CodeResolver.prototype.getExecutingCodeFromCache = function (address) {
if (this.instructionsByAddress[address]) {
return {
instructions: this.instructionsByAddress[address],
instructionsIndexByBytesOffset: this.instructionsIndexByBytesOffset[address],
bytecode: this.bytecodeByAddress[address]
}
} else {
return null
} }
} }
CodeResolver.prototype.getInstructionIndex = function (address, pc) {
return this.getExecutingCodeFromCache(address).instructionsIndexByBytesOffset[pc]
}
module.exports = CodeResolver

@ -1,5 +1,3 @@
var remixLib = require('remix-lib')
var global = remixLib.global
module.exports = { module.exports = {
decodeMappingsKeys: decodeMappingsKeys decodeMappingsKeys: decodeMappingsKeys
@ -13,12 +11,12 @@ module.exports = {
* @param {Function} callback - calback * @param {Function} callback - calback
* @return {Map} - solidity mapping location (e.g { "<mapping_slot>" : { "<mapping-key1>": preimageOf1 }, { "<mapping-key2>": preimageOf2 }, ... }) * @return {Map} - solidity mapping location (e.g { "<mapping_slot>" : { "<mapping-key1>": preimageOf1 }, { "<mapping-key2>": preimageOf2 }, ... })
*/ */
async function decodeMappingsKeys (storage, callback) { async function decodeMappingsKeys (web3, storage, callback) {
var ret = {} var ret = {}
for (var hashedLoc in storage) { for (var hashedLoc in storage) {
var preimage var preimage
try { try {
preimage = await getPreimage(storage[hashedLoc].key) preimage = await getPreimage(web3, storage[hashedLoc].key)
} catch (e) { } catch (e) {
} }
if (preimage) { if (preimage) {
@ -42,9 +40,9 @@ async function decodeMappingsKeys (storage, callback) {
* @param {String} key - key to retrieve the preimage of * @param {String} key - key to retrieve the preimage of
* @return {String} - preimage of the given key * @return {String} - preimage of the given key
*/ */
function getPreimage (key) { function getPreimage (web3, key) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
global.web3Debug.debug.preimage(key.indexOf('0x') === 0 ? key : '0x' + key, function (error, preimage) { web3.debug.preimage(key.indexOf('0x') === 0 ? key : '0x' + key, function (error, preimage) {
if (error) { if (error) {
resolve(null) resolve(null)
} else { } else {

@ -1,7 +1,6 @@
'use strict' 'use strict'
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var global = remixLib.global
var mappingPreimages = require('./mappingPreimages') var mappingPreimages = require('./mappingPreimages')
/** /**
@ -9,34 +8,37 @@ var mappingPreimages = require('./mappingPreimages')
* (TODO: one instance need to be shared over all the components) * (TODO: one instance need to be shared over all the components)
*/ */
class StorageResolver { class StorageResolver {
constructor () { constructor (options) {
this.storageByAddress = {} this.storageByAddress = {}
this.preimagesMappingByAddress = {} this.preimagesMappingByAddress = {}
this.maxSize = 100 this.maxSize = 100
this.web3 = options.web3
this.zeroSlot = '0x0000000000000000000000000000000000000000000000000000000000000000'
} }
/** /**
* returns the storage for the given context (address and vm trace index) * returns the storage for the given context (address and vm trace index)
* returns the range 0x0 => this.maxSize * returns the range 0x0 => this.maxSize
* *
* @param {Object} - tx - transaction * @param {Object} - tx - transaction
* @param {Int} - stepIndex - Index of the stop in the vm trace * @param {Int} - stepIndex - Index of the stop in the vm trace
* @param {String} - address - lookup address * @param {String} - address - lookup address
* @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value} * @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value}
*/ */
storageRange (tx, stepIndex, address, callback) { storageRange (tx, stepIndex, address, callback) {
storageRangeInternal(this, zeroSlot, tx, stepIndex, address, callback) this.storageRangeInternal(this, this.zeroSlot, tx, stepIndex, address, callback)
} }
/** /**
* compute the mappgings type locations for the current address (cached for a debugging session) * compute the mappgings type locations for the current address (cached for a debugging session)
* note: that only retrieve the first 100 items. * note: that only retrieve the first 100 items.
* *
* @param {String} address - contract address * @param {String} address - contract address
* @param {Object} address - storage * @param {Object} address - storage
* @return {Function} - callback * @return {Function} - callback
*/ */
initialPreimagesMappings (tx, stepIndex, address, callback) { initialPreimagesMappings (tx, stepIndex, address, callback) {
const self = this
if (this.preimagesMappingByAddress[address]) { if (this.preimagesMappingByAddress[address]) {
return callback(null, this.preimagesMappingByAddress[address]) return callback(null, this.preimagesMappingByAddress[address])
} }
@ -44,7 +46,7 @@ class StorageResolver {
if (error) { if (error) {
return callback(error) return callback(error)
} }
mappingPreimages.decodeMappingsKeys(storage, (error, mappings) => { mappingPreimages.decodeMappingsKeys(self.web3, storage, (error, mappings) => {
if (error) { if (error) {
callback(error) callback(error)
} else { } else {
@ -56,16 +58,16 @@ class StorageResolver {
} }
/** /**
* return a slot value for the given context (address and vm trace index) * return a slot value for the given context (address and vm trace index)
* *
* @param {String} - slot - slot key * @param {String} - slot - slot key
* @param {Object} - tx - transaction * @param {Object} - tx - transaction
* @param {Int} - stepIndex - Index of the stop in the vm trace * @param {Int} - stepIndex - Index of the stop in the vm trace
* @param {String} - address - lookup address * @param {String} - address - lookup address
* @param {Function} - callback - {key, hashedKey, value} - * @param {Function} - callback - {key, hashedKey, value} -
*/ */
storageSlot (slot, tx, stepIndex, address, callback) { storageSlot (slot, tx, stepIndex, address, callback) {
storageRangeInternal(this, slot, tx, stepIndex, address, function (error, storage) { this.storageRangeInternal(this, slot, tx, stepIndex, address, function (error, storage) {
if (error) { if (error) {
callback(error) callback(error)
} else { } else {
@ -75,91 +77,89 @@ class StorageResolver {
} }
/** /**
* return True if the storage at @arg address is complete * return True if the storage at @arg address is complete
* *
* @param {String} address - contract address * @param {String} address - contract address
* @return {Bool} - return True if the storage at @arg address is complete * @return {Bool} - return True if the storage at @arg address is complete
*/ */
isComplete (address) { isComplete (address) {
return this.storageByAddress[address] && this.storageByAddress[address].complete return this.storageByAddress[address] && this.storageByAddress[address].complete
} }
}
/** /**
* retrieve the storage and ensure at least @arg slot is cached. * retrieve the storage and ensure at least @arg slot is cached.
* - If @arg slot is already cached, the storage will be returned from the cache * - If @arg slot is already cached, the storage will be returned from the cache
* even if the next 1000 items are not in the cache. * even if the next 1000 items are not in the cache.
* - If @arg slot is not cached, the corresponding value will be resolved and the next 1000 slots. * - If @arg slot is not cached, the corresponding value will be resolved and the next 1000 slots.
*/ */
function storageRangeInternal (self, slotKey, tx, stepIndex, address, callback) { storageRangeInternal (self, slotKey, tx, stepIndex, address, callback) {
var cached = fromCache(self, address) var cached = this.fromCache(self, address)
if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000... if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000...
return callback(null, cached.storage) return callback(null, cached.storage)
}
storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, nextKey) => {
if (error) {
return callback(error)
} }
if (!storage[slotKey] && slotKey !== zeroSlot) { // we don't cache the zero slot (could lead to inconsistency) this.storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, nextKey) => {
storage[slotKey] = { if (error) {
key: slotKey, return callback(error)
value: zeroSlot
} }
} if (!storage[slotKey] && slotKey !== self.zeroSlot) { // we don't cache the zero slot (could lead to inconsistency)
toCache(self, address, storage) storage[slotKey] = {
if (slotKey === zeroSlot && !nextKey) { // only working if keys are sorted !! key: slotKey,
self.storageByAddress[address].complete = true value: self.zeroSlot
} }
callback(null, storage) }
}) self.toCache(self, address, storage)
} if (slotKey === self.zeroSlot && !nextKey) { // only working if keys are sorted !!
self.storageByAddress[address].complete = true
var zeroSlot = '0x0000000000000000000000000000000000000000000000000000000000000000' }
callback(null, storage)
})
}
/** /**
* retrieve the storage from the cache. if @arg slot is defined, return only the desired slot, if not return the entire known storage * retrieve the storage from the cache. if @arg slot is defined, return only the desired slot, if not return the entire known storage
* *
* @param {String} address - contract address * @param {String} address - contract address
* @return {String} - either the entire known storage or a single value * @return {String} - either the entire known storage or a single value
*/ */
function fromCache (self, address) { fromCache (self, address) {
if (!self.storageByAddress[address]) { if (!self.storageByAddress[address]) {
return null return null
}
return self.storageByAddress[address]
} }
return self.storageByAddress[address]
}
/** /**
* store the result of `storageRangeAtInternal` * store the result of `storageRangeAtInternal`
* *
* @param {String} address - contract address * @param {String} address - contract address
* @param {Object} storage - result of `storageRangeAtInternal`, contains {key, hashedKey, value} * @param {Object} storage - result of `storageRangeAtInternal`, contains {key, hashedKey, value}
*/ */
function toCache (self, address, storage) { toCache (self, address, storage) {
if (!self.storageByAddress[address]) { if (!self.storageByAddress[address]) {
self.storageByAddress[address] = {} self.storageByAddress[address] = {}
}
self.storageByAddress[address].storage = Object.assign(self.storageByAddress[address].storage || {}, storage)
} }
self.storageByAddress[address].storage = Object.assign(self.storageByAddress[address].storage || {}, storage)
}
function storageRangeWeb3Call (tx, address, start, maxSize, callback) { storageRangeWeb3Call (tx, address, start, maxSize, callback) {
if (traceHelper.isContractCreation(address)) { if (traceHelper.isContractCreation(address)) {
callback(null, {}, null) callback(null, {}, null)
} else { } else {
global.web3Debug.debug.storageRangeAt( this.web3.debug.storageRangeAt(
tx.blockHash, tx.transactionIndex === undefined ? tx.hash : tx.transactionIndex, tx.blockHash, tx.transactionIndex === undefined ? tx.hash : tx.transactionIndex,
address, address,
start, start,
maxSize, maxSize,
(error, result) => { (error, result) => {
if (error) { if (error) {
callback(error) callback(error)
} else if (result.storage) { } else if (result.storage) {
callback(null, result.storage, result.nextKey) callback(null, result.storage, result.nextKey)
} else { } else {
callback('the storage has not been provided') callback('the storage has not been provided')
} }
}) })
}
} }
} }

@ -12,6 +12,7 @@ class StorageViewer {
constructor (_context, _storageResolver, _traceManager) { constructor (_context, _storageResolver, _traceManager) {
this.context = _context this.context = _context
this.storageResolver = _storageResolver this.storageResolver = _storageResolver
this.web3 = this.storageResolver.web3
this.initialMappingsLocationPromise = null this.initialMappingsLocationPromise = null
this.currentMappingsLocationPromise = null this.currentMappingsLocationPromise = null
_traceManager.accumulateStorageChanges(this.context.stepIndex, this.context.address, {}, (error, storageChanges) => { _traceManager.accumulateStorageChanges(this.context.stepIndex, this.context.address, {}, (error, storageChanges) => {
@ -117,7 +118,7 @@ class StorageViewer {
if (this.mappingsLocationChanges) { if (this.mappingsLocationChanges) {
return callback(null, this.mappingsLocationChanges) return callback(null, this.mappingsLocationChanges)
} }
mappingPreimages.decodeMappingsKeys(storageChanges, (error, mappings) => { mappingPreimages.decodeMappingsKeys(this.web3, storageChanges, (error, mappings) => {
if (!error) { if (!error) {
this.mappingsLocationChanges = mappings this.mappingsLocationChanges = mappings
return callback(null, this.mappingsLocationChanges) return callback(null, this.mappingsLocationChanges)

@ -6,14 +6,14 @@ var TraceStepManager = require('./traceStepManager')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var util = remixLib.util var util = remixLib.util
var global = remixLib.global
function TraceManager () { function TraceManager (options) {
this.web3 = options.web3
this.isLoading = false this.isLoading = false
this.trace = null this.trace = null
this.traceCache = new TraceCache() this.traceCache = new TraceCache()
this.traceAnalyser = new TraceAnalyser(this.traceCache) this.traceAnalyser = new TraceAnalyser(this.traceCache)
this.traceRetriever = new TraceRetriever() this.traceRetriever = new TraceRetriever({web3: this.web3})
this.traceStepManager = new TraceStepManager(this.traceAnalyser) this.traceStepManager = new TraceStepManager(this.traceAnalyser)
this.tx this.tx
} }
@ -22,7 +22,7 @@ function TraceManager () {
TraceManager.prototype.resolveTrace = function (tx, callback) { TraceManager.prototype.resolveTrace = function (tx, callback) {
this.tx = tx this.tx = tx
this.init() this.init()
if (!global.web3) callback('web3 not loaded', false) if (!this.web3) callback('web3 not loaded', false)
this.isLoading = true this.isLoading = true
var self = this var self = this
this.traceRetriever.getTrace(tx.hash, function (error, result) { this.traceRetriever.getTrace(tx.hash, function (error, result) {

@ -1,8 +1,7 @@
'use strict' 'use strict'
var remixLib = require('remix-lib')
var global = remixLib.global
function TraceRetriever () { function TraceRetriever (options) {
this.web3 = options.web3
} }
TraceRetriever.prototype.getTrace = function (txHash, callback) { TraceRetriever.prototype.getTrace = function (txHash, callback) {
@ -12,7 +11,7 @@ TraceRetriever.prototype.getTrace = function (txHash, callback) {
disableStack: false, disableStack: false,
fullStorage: false fullStorage: false
} }
global.web3Debug.debug.traceTransaction(txHash, options, function (error, result) { this.web3.debug.traceTransaction(txHash, options, function (error, result) {
callback(error, result) callback(error, result)
}) })
} }

@ -5,7 +5,8 @@ var Web3Providers = remixLib.vm.Web3Providers
var TraceManager = require('../src/trace/traceManager') var TraceManager = require('../src/trace/traceManager')
var CodeManager = require('../src/code/codeManager') var CodeManager = require('../src/code/codeManager')
var web3Test = require('./resources/testWeb3') var web3Test = require('./resources/testWeb3')
var global = remixLib.global
let web3 = null
tape('CodeManager', function (t) { tape('CodeManager', function (t) {
var codeManager var codeManager
@ -17,12 +18,12 @@ tape('CodeManager', function (t) {
console.log(mes) console.log(mes)
t.fail(mes) t.fail(mes)
} else { } else {
global.web3 = obj web3 = obj
var traceManager = new TraceManager() var traceManager = new TraceManager({web3: web3})
codeManager = new CodeManager(traceManager) codeManager = new CodeManager(traceManager)
var contractCode = global.web3.eth.getCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5') var contractCode = web3.eth.getCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary
var tx = global.web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51') var tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
traceManager.resolveTrace(tx, function (error, result) { traceManager.resolveTrace(tx, function (error, result) {
if (error) { if (error) {
t.fail(' - traceManager.resolveTrace - failed ' + result) t.fail(' - traceManager.resolveTrace - failed ' + result)
@ -63,7 +64,7 @@ function continueTesting (t, codeManager) {
} }
} }
}) })
var tx = global.web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51') var tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
codeManager.resolveStep(0, tx) codeManager.resolveStep(0, tx)
codeManager.resolveStep(70, tx) codeManager.resolveStep(70, tx)
}) })

@ -3,9 +3,10 @@ var TraceManager = require('../src/trace/traceManager')
var tape = require('tape') var tape = require('tape')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var Web3Providers = remixLib.vm.Web3Providers var Web3Providers = remixLib.vm.Web3Providers
var global = remixLib.global
var web3Test = require('./resources/testWeb3') var web3Test = require('./resources/testWeb3')
let web3 = null
tape('TraceManager', function (t) { tape('TraceManager', function (t) {
var traceManager var traceManager
@ -18,16 +19,15 @@ tape('TraceManager', function (t) {
console.log(mes) console.log(mes)
st.fail(mes) st.fail(mes)
} else { } else {
global.web3 = obj web3 = obj
global.web3Debug = obj traceManager = new TraceManager({web3: web3})
traceManager = new TraceManager()
st.end() st.end()
} }
}) })
}) })
t.test('TraceManager.resolveTrace', function (st) { t.test('TraceManager.resolveTrace', function (st) {
var tx = global.web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51') var tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
traceManager.resolveTrace(tx, function (error, result) { traceManager.resolveTrace(tx, function (error, result) {
if (error) { if (error) {
st.fail(' - traceManager.resolveTrace - failed ' + result) st.fail(' - traceManager.resolveTrace - failed ' + result)

@ -4,7 +4,6 @@ var TraceManager = remixCore.trace.TraceManager
var StorageViewer = remixCore.storage.StorageViewer var StorageViewer = remixCore.storage.StorageViewer
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var global = remixLib.global
var init = remixLib.init var init = remixLib.init
var executionContext = remixLib.execution.executionContext var executionContext = remixLib.execution.executionContext
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
@ -35,6 +34,8 @@ function Ethdebugger (opts) {
this.opts = opts || {} this.opts = opts || {}
if (!this.opts.compilationResult) this.opts.compilationResult = () => { return null } if (!this.opts.compilationResult) this.opts.compilationResult = () => { return null }
this.web3 = opts.web3
this.event = new EventManager() this.event = new EventManager()
this.tx this.tx
@ -43,7 +44,16 @@ function Ethdebugger (opts) {
this.addProvider('DUMMYWEB3', new DummyProvider()) this.addProvider('DUMMYWEB3', new DummyProvider())
this.switchProvider('DUMMYWEB3') this.switchProvider('DUMMYWEB3')
this.traceManager = new TraceManager() this.traceManager = new TraceManager({web3: this.web3})
this.codeManager = new CodeManager(this.traceManager)
this.solidityProxy = new SolidityProxy(this.traceManager, this.codeManager)
this.storageResolver = null
this.callTree = new InternalCallTree(this.event, this.traceManager, this.solidityProxy, this.codeManager, { includeLocalVariables: true })
}
Ethdebugger.prototype.setManagers = function () {
this.traceManager = new TraceManager({web3: this.web3})
this.codeManager = new CodeManager(this.traceManager) this.codeManager = new CodeManager(this.traceManager)
this.solidityProxy = new SolidityProxy(this.traceManager, this.codeManager) this.solidityProxy = new SolidityProxy(this.traceManager, this.codeManager)
this.storageResolver = null this.storageResolver = null
@ -152,7 +162,7 @@ Ethdebugger.prototype.storageViewAt = function (step, address) {
} }
/* set env */ /* set env */
Ethdebugger.prototype.web3 = function () { Ethdebugger.prototype.web3 = function () {
return global.web3 return this.web3
} }
Ethdebugger.prototype.addProvider = function (type, obj) { Ethdebugger.prototype.addProvider = function (type, obj) {
@ -166,14 +176,19 @@ Ethdebugger.prototype.switchProvider = function (type) {
if (error) { if (error) {
console.log('provider ' + type + ' not defined') console.log('provider ' + type + ' not defined')
} else { } else {
global.web3 = obj self.web3 = obj
self.setManagers()
// self.traceManager.web3 = self.web3
executionContext.detectNetwork((error, network) => { executionContext.detectNetwork((error, network) => {
if (error || !network) { if (error || !network) {
global.web3Debug = obj self.web3Debug = obj
self.web3 = obj
} else { } else {
var webDebugNode = init.web3DebugNode(network.name) var webDebugNode = init.web3DebugNode(network.name)
global.web3Debug = !webDebugNode ? obj : webDebugNode self.web3Debug = !webDebugNode ? obj : webDebugNode
self.web3 = !webDebugNode ? obj : webDebugNode
} }
self.setManagers()
}) })
self.event.trigger('providerChanged', [type]) self.event.trigger('providerChanged', [type])
} }
@ -214,7 +229,7 @@ Ethdebugger.prototype.debug = function (tx) {
if (self.breakpointManager && self.breakpointManager.hasBreakpoint()) { if (self.breakpointManager && self.breakpointManager.hasBreakpoint()) {
self.breakpointManager.jumpNextBreakpoint(false) self.breakpointManager.jumpNextBreakpoint(false)
} }
self.storageResolver = new StorageResolver() self.storageResolver = new StorageResolver({web3: self.traceManager.web3})
} else { } else {
self.statusMessage = error ? error.message : 'Trace not loaded' self.statusMessage = error ? error.message : 'Trace not loaded'
} }

@ -51,8 +51,7 @@ function initVM (st, privateKey) {
console.log(mes) console.log(mes)
st.fail(mes) st.fail(mes)
} else { } else {
remixLib.global.web3 = obj vm.web3 = obj
remixLib.global.web3Debug = obj
} }
}) })
return vm return vm

@ -18,9 +18,7 @@ Provides:
init: init, init: init,
util: util, util: util,
AstWalker: AstWalker, AstWalker: AstWalker,
global: global,
ui: { ui: {
styleGuide: styleGuide styleGuide: styleGuide
} }
}
} }

@ -11,7 +11,6 @@ var Web3Providers = require('./src/web3Provider/web3Providers')
var DummyProvider = require('./src/web3Provider/dummyProvider') var DummyProvider = require('./src/web3Provider/dummyProvider')
var Web3VMProvider = require('./src/web3Provider/web3VmProvider') var Web3VMProvider = require('./src/web3Provider/web3VmProvider')
var AstWalker = require('./src/astWalker') var AstWalker = require('./src/astWalker')
var global = require('./src/global')
var Storage = require('./src/storage') var Storage = require('./src/storage')
var EventsDecoder = require('./src/execution/eventsDecoder') var EventsDecoder = require('./src/execution/eventsDecoder')
@ -50,7 +49,6 @@ function modules () {
init: init, init: init,
util: util, util: util,
AstWalker: AstWalker, AstWalker: AstWalker,
global: global,
execution: { execution: {
EventsDecoder: EventsDecoder, EventsDecoder: EventsDecoder,
txExecution: txExecution, txExecution: txExecution,

@ -1,4 +0,0 @@
module.exports = {
web3: null,
web3Debug: null // this node should support the debug endpoint
}

@ -6,7 +6,6 @@ var vmCall = require('../vmCall')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var global = remixLib.global
var SolidityProxy = require('../../../src/decoder/solidityProxy') var SolidityProxy = require('../../../src/decoder/solidityProxy')
var InternalCallTree = require('../../../src/decoder/internalCallTree') var InternalCallTree = require('../../../src/decoder/internalCallTree')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
@ -17,12 +16,12 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
global.web3.getTransaction(txHash, function (error, tx) { vm.web3.eth.getTransaction(txHash, function (error, tx) {
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
tx.to = traceHelper.contractCreationToken('0') tx.to = traceHelper.contractCreationToken('0')
var traceManager = new TraceManager() var traceManager = new TraceManager({web3: vm.web3})
var codeManager = new CodeManager(traceManager) var codeManager = new CodeManager(traceManager)
codeManager.clear() codeManager.clear()
var solidityProxy = new SolidityProxy(traceManager, codeManager) var solidityProxy = new SolidityProxy(traceManager, codeManager)

@ -5,7 +5,6 @@ var CodeManager = remixCore.code.CodeManager
var vmCall = require('../vmCall') var vmCall = require('../vmCall')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var global = remixLib.global
var SolidityProxy = require('../../../src/decoder/solidityProxy') var SolidityProxy = require('../../../src/decoder/solidityProxy')
var InternalCallTree = require('../../../src/decoder/internalCallTree') var InternalCallTree = require('../../../src/decoder/internalCallTree')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
@ -16,12 +15,12 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
global.web3.getTransaction(txHash, function (error, tx) { vm.web3.eth.getTransaction(txHash, function (error, tx) {
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
tx.to = traceHelper.contractCreationToken('0') tx.to = traceHelper.contractCreationToken('0')
var traceManager = new TraceManager() var traceManager = new TraceManager({web3: vm.web3})
var codeManager = new CodeManager(traceManager) var codeManager = new CodeManager(traceManager)
codeManager.clear() codeManager.clear()
var solidityProxy = new SolidityProxy(traceManager, codeManager) var solidityProxy = new SolidityProxy(traceManager, codeManager)

@ -5,7 +5,6 @@ var CodeManager = remixCore.code.CodeManager
var vmCall = require('../vmCall') var vmCall = require('../vmCall')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var global = remixLib.global
var SolidityProxy = require('../../../src/decoder/solidityProxy') var SolidityProxy = require('../../../src/decoder/solidityProxy')
var InternalCallTree = require('../../../src/decoder/internalCallTree') var InternalCallTree = require('../../../src/decoder/internalCallTree')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
@ -16,12 +15,12 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
global.web3.getTransaction(txHash, function (error, tx) { vm.web3.eth.getTransaction(txHash, function (error, tx) {
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
tx.to = traceHelper.contractCreationToken('0') tx.to = traceHelper.contractCreationToken('0')
var traceManager = new TraceManager() var traceManager = new TraceManager({web3: vm.web3})
var codeManager = new CodeManager(traceManager) var codeManager = new CodeManager(traceManager)
codeManager.clear() codeManager.clear()
var solidityProxy = new SolidityProxy(traceManager, codeManager) var solidityProxy = new SolidityProxy(traceManager, codeManager)

@ -5,7 +5,6 @@ var CodeManager = remixCore.code.CodeManager
var vmCall = require('../vmCall') var vmCall = require('../vmCall')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var global = remixLib.global
var SolidityProxy = require('../../../src/decoder/solidityProxy') var SolidityProxy = require('../../../src/decoder/solidityProxy')
var InternalCallTree = require('../../../src/decoder/internalCallTree') var InternalCallTree = require('../../../src/decoder/internalCallTree')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
@ -16,12 +15,12 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
global.web3.getTransaction(txHash, function (error, tx) { vm.web3.eth.getTransaction(txHash, function (error, tx) {
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
tx.to = traceHelper.contractCreationToken('0') tx.to = traceHelper.contractCreationToken('0')
var traceManager = new TraceManager() var traceManager = new TraceManager({web3: vm.web3})
var codeManager = new CodeManager(traceManager) var codeManager = new CodeManager(traceManager)
codeManager.clear() codeManager.clear()
var solidityProxy = new SolidityProxy(traceManager, codeManager) var solidityProxy = new SolidityProxy(traceManager, codeManager)

@ -15,7 +15,7 @@ module.exports = function testMappingStorage (st, cb) {
console.log(error) console.log(error)
st.end(error) st.end(error)
} else { } else {
remixLib.global.web3.eth.getTransaction(txHash, (error, tx) => { vm.web3.eth.getTransaction(txHash, (error, tx) => {
if (error) { if (error) {
console.log(error) console.log(error)
st.end(error) st.end(error)
@ -35,13 +35,13 @@ function testMapping (st, vm, privateKey, contractAddress, output, cb) {
st.end(error) st.end(error)
} else { } else {
console.log(txHash) console.log(txHash)
remixLib.global.web3.eth.getTransaction(txHash, (error, tx) => { vm.web3.eth.getTransaction(txHash, (error, tx) => {
if (error) { if (error) {
console.log(error) console.log(error)
st.end(error) st.end(error)
} else { } else {
var TraceManager = require('remix-core').trace.TraceManager var TraceManager = require('remix-core').trace.TraceManager
var traceManager = new TraceManager() var traceManager = new TraceManager({web3: vm.web3})
traceManager.resolveTrace(tx, () => { traceManager.resolveTrace(tx, () => {
var StorageResolver = require('remix-core').storage.StorageResolver var StorageResolver = require('remix-core').storage.StorageResolver
var StorageViewer = require('remix-core').storage.StorageViewer var StorageViewer = require('remix-core').storage.StorageViewer
@ -49,7 +49,7 @@ function testMapping (st, vm, privateKey, contractAddress, output, cb) {
stepIndex: 213, stepIndex: 213,
tx: tx, tx: tx,
address: contractAddress address: contractAddress
}, new StorageResolver(), traceManager) }, new StorageResolver({web3: vm.web3}), traceManager)
var stateVars = stateDecoder.extractStateVariables('SimpleMappingState', output.sources) var stateVars = stateDecoder.extractStateVariables('SimpleMappingState', output.sources)
stateDecoder.decodeState(stateVars, storageViewer).then((result) => { stateDecoder.decodeState(stateVars, storageViewer).then((result) => {
console.log('ok', JSON.stringify(result)) console.log('ok', JSON.stringify(result))

@ -51,8 +51,7 @@ function initVM (st, privateKey) {
console.log(mes) console.log(mes)
st.fail(mes) st.fail(mes)
} else { } else {
remixLib.global.web3 = obj vm.web3 = obj
remixLib.global.web3Debug = obj
} }
}) })
return vm return vm

Loading…
Cancel
Save