refactor storageRange and initialMappingsLocation

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

@ -25,10 +25,8 @@ class StorageResolver {
* @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) {
this.storageRangeInternal(this, this.zeroSlot, tx, stepIndex, address).then((result) => { return this.storageRangeInternal(this, this.zeroSlot, tx, stepIndex, address)
callback(null, result)
}).catch(callback)
} }
/** /**
@ -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). * @param {Array} corrections - used in case the calculated sha3 has been modifyed before SSTORE (notably used for struct in mapping).
* @return {Function} - callback * @return {Function} - callback
*/ */
initialPreimagesMappings (tx, stepIndex, address, corrections, callback) { initialPreimagesMappings (tx, stepIndex, address, corrections) {
return new Promise((resolve, reject) => {
if (this.preimagesMappingByAddress[address]) { if (this.preimagesMappingByAddress[address]) {
return callback(null, this.preimagesMappingByAddress[address]) return resolve(this.preimagesMappingByAddress[address])
}
this.storageRange(tx, stepIndex, address, (error, storage) => {
if (error) {
return callback(error)
} }
this.storageRange(tx, stepIndex, address).then((storage) => {
const mappings = mappingPreimages.decodeMappingsKeys(this.web3, storage, corrections) const mappings = mappingPreimages.decodeMappingsKeys(this.web3, storage, corrections)
this.preimagesMappingByAddress[address] = mappings this.preimagesMappingByAddress[address] = mappings
callback(null, mappings) resolve(mappings)
}).catch(reject)
}) })
} }

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

Loading…
Cancel
Save