refactor getCode

pull/63/head
Iuri Matias 5 years ago
parent 78b93513ea
commit 9c77e3d2f1
  1. 16
      libs/remix-debug/src/solidity-decoder/solidityProxy.js
  2. 18
      libs/remix-lib/src/code/codeManager.js
  3. 18
      libs/remix-lib/src/sourceLocationTracker.js

@ -39,21 +39,17 @@ class SolidityProxy {
* @param {Int} vmTraceIndex - index in the vm trave where to resolve the executed contract name
* @param {Function} cb - callback returns (error, contractName)
*/
contractNameAt (vmTraceIndex) {
return new Promise((resolve, reject) => {
async contractNameAt (vmTraceIndex) {
return new Promise(async (resolve, reject) => {
try {
const address = this.traceManager.getCurrentCalledAddressAt(vmTraceIndex)
if (this.cache.contractNameByAddress[address]) {
return resolve(this.cache.contractNameByAddress[address])
}
this.codeManager.getCode(address, (error, code) => {
if (error) {
return reject(error)
}
const contractName = contractNameFromCode(this.contracts, code.bytecode, address)
this.cache.contractNameByAddress[address] = contractName
resolve(contractName)
})
const code = await this.codeManager.getCode(address)
const contractName = contractNameFromCode(this.contracts, code.bytecode, address)
this.cache.contractNameByAddress[address] = contractName
resolve(contractName)
} catch (error) {
reject(error)
}

@ -53,19 +53,18 @@ CodeManager.prototype.resolveStep = function (stepIndex, tx) {
* @param {String} address - address of the contract to get the code from
* @param {Function} cb - callback function, return the bytecode
*/
CodeManager.prototype.getCode = function (address, cb) {
CodeManager.prototype.getCode = async function (address) {
if (!traceHelper.isContractCreation(address)) {
return this.codeResolver.resolveCode(address).then((code) => {
cb(null, code)
})
const code = await this.codeResolver.resolveCode(address)
return code
}
var codes = this.codeResolver.getExecutingCodeFromCache(address)
if (codes) {
return cb(null, codes)
return codes
}
const hexCode = this.traceManager.getContractCreationCode(address)
codes = this.codeResolver.cacheExecutingCode(address, hexCode)
cb(null, codes)
return codes
}
/**
@ -120,11 +119,10 @@ CodeManager.prototype.getFunctionFromPC = function (address, pc, sourceMap, ast)
}
function retrieveCodeAndTrigger (codeMananger, address, stepIndex, tx) {
codeMananger.getCode(address, (error, result) => {
if (error) {
return console.log(error)
}
codeMananger.getCode(address).then((result) => {
retrieveIndexAndTrigger(codeMananger, address, stepIndex, result.instructions)
}).catch((error) => {
return console.log(error)
})
}

@ -78,19 +78,15 @@ function extractSourceMap (self, codeManager, address, contracts) {
return new Promise((resolve, reject) => {
if (self.sourceMapByAddress[address]) return resolve(self.sourceMapByAddress[address])
codeManager.getCode(address, (error, result) => {
if (!error) {
const sourceMap = getSourceMap(address, result.bytecode, contracts)
if (sourceMap) {
if (!helper.isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap
resolve(sourceMap)
} else {
reject('no sourcemap associated with the code ' + address)
}
codeManager.getCode(address).then((result) => {
const sourceMap = getSourceMap(address, result.bytecode, contracts)
if (sourceMap) {
if (!helper.isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap
resolve(sourceMap)
} else {
reject(error)
reject('no sourcemap associated with the code ' + address)
}
})
}).catch(reject)
})
}

Loading…
Cancel
Save