refactor extractStateVariablesAt

pull/5370/head
Iuri Matias 5 years ago
parent e612a901a6
commit d8be9b3749
  1. 38
      libs/remix-debug/src/solidity-decoder/solidityProxy.js

@ -40,20 +40,14 @@ class SolidityProxy {
* @param {Function} cb - callback returns (error, contractName) * @param {Function} cb - callback returns (error, contractName)
*/ */
async contractNameAt (vmTraceIndex) { async contractNameAt (vmTraceIndex) {
return new Promise(async (resolve, reject) => { const address = this.traceManager.getCurrentCalledAddressAt(vmTraceIndex)
try { if (this.cache.contractNameByAddress[address]) {
const address = this.traceManager.getCurrentCalledAddressAt(vmTraceIndex) return this.cache.contractNameByAddress[address]
if (this.cache.contractNameByAddress[address]) { }
return resolve(this.cache.contractNameByAddress[address]) const code = await this.codeManager.getCode(address)
} const contractName = contractNameFromCode(this.contracts, code.bytecode, address)
const code = await this.codeManager.getCode(address) this.cache.contractNameByAddress[address] = contractName
const contractName = contractNameFromCode(this.contracts, code.bytecode, address) return contractName
this.cache.contractNameByAddress[address] = contractName
resolve(contractName)
} catch (error) {
reject(error)
}
})
} }
/** /**
@ -91,15 +85,9 @@ class SolidityProxy {
* @param {Int} vmTraceIndex - index in the vm trave where to resolve the state variables * @param {Int} vmTraceIndex - index in the vm trave where to resolve the state variables
* @return {Object} - returns state variables of @args vmTraceIndex * @return {Object} - returns state variables of @args vmTraceIndex
*/ */
extractStateVariablesAt (vmtraceIndex) { async extractStateVariablesAt (vmtraceIndex) {
return new Promise((resolve, reject) => { const contractName = await this.contractNameAt(vmtraceIndex)
this.contractNameAt(vmtraceIndex, (error, contractName) => { return this.extractStateVariables(contractName)
if (error) {
return reject(error)
}
return resolve(this.extractStateVariables(contractName))
})
})
} }
/** /**
@ -112,10 +100,8 @@ class SolidityProxy {
const file = this.fileNameFromIndex(sourceLocation.file) const file = this.fileNameFromIndex(sourceLocation.file)
if (this.sources[file]) { if (this.sources[file]) {
return this.sources[file].legacyAST return this.sources[file].legacyAST
} else {
// console.log('AST not found for file id ' + sourceLocation.file)
return null
} }
return null
} }
/** /**

Loading…
Cancel
Save