refactor storageRange and initialMappingsLocation

pull/62/head
Iuri Matias 5 years ago committed by aniket-engg
parent e411be3eda
commit d8c64f75b8
  1. 25
      libs/remix-debug/src/storage/storageResolver.js
  2. 20
      libs/remix-debug/src/storage/storageViewer.js

@ -25,10 +25,8 @@ class StorageResolver {
* @param {String} - address - lookup address
* @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value}
*/
storageRange (tx, stepIndex, address, callback) {
this.storageRangeInternal(this, this.zeroSlot, tx, stepIndex, address).then((result) => {
callback(null, result)
}).catch(callback)
storageRange (tx, stepIndex, address) {
return this.storageRangeInternal(this, this.zeroSlot, tx, stepIndex, address)
}
/**
@ -41,17 +39,16 @@ class StorageResolver {
* @param {Array} corrections - used in case the calculated sha3 has been modifyed before SSTORE (notably used for struct in mapping).
* @return {Function} - callback
*/
initialPreimagesMappings (tx, stepIndex, address, corrections, callback) {
if (this.preimagesMappingByAddress[address]) {
return callback(null, this.preimagesMappingByAddress[address])
}
this.storageRange(tx, stepIndex, address, (error, storage) => {
if (error) {
return callback(error)
initialPreimagesMappings (tx, stepIndex, address, corrections) {
return new Promise((resolve, reject) => {
if (this.preimagesMappingByAddress[address]) {
return resolve(this.preimagesMappingByAddress[address])
}
const mappings = mappingPreimages.decodeMappingsKeys(this.web3, storage, corrections)
this.preimagesMappingByAddress[address] = mappings
callback(null, mappings)
this.storageRange(tx, stepIndex, address).then((storage) => {
const mappings = mappingPreimages.decodeMappingsKeys(this.web3, storage, corrections)
this.preimagesMappingByAddress[address] = mappings
resolve(mappings)
}).catch(reject)
})
}

@ -31,13 +31,9 @@ class StorageViewer {
* @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value}
*/
storageRange (callback) {
this.storageResolver.storageRange(this.context.tx, this.context.stepIndex, this.context.address, (error, storage) => {
if (error) {
callback(error)
} else {
callback(null, Object.assign({}, storage, this.storageChanges))
}
})
this.storageResolver.storageRange(this.context.tx, this.context.stepIndex, this.context.address).then((storage) => {
callback(null, Object.assign({}, storage, this.storageChanges))
}).catch(callback)
}
/**
@ -76,15 +72,7 @@ class StorageViewer {
*/
async initialMappingsLocation (corrections) {
if (!this.initialMappingsLocationPromise) {
this.initialMappingsLocationPromise = new Promise((resolve, reject) => {
this.storageResolver.initialPreimagesMappings(this.context.tx, this.context.stepIndex, this.context.address, corrections, (error, initialMappingsLocation) => {
if (error) {
reject(error)
} else {
resolve(initialMappingsLocation)
}
})
})
this.initialMappingsLocationPromise = this.storageResolver.initialPreimagesMappings(this.context.tx, this.context.stepIndex, this.context.address, corrections)
}
return this.initialMappingsLocationPromise
}

Loading…
Cancel
Save