return a promise if mappings alrady requested

pull/7/head
yann300 8 years ago
parent 075fa4ee59
commit 4013d3528d
  1. 48
      src/storage/storageViewer.js

@ -11,6 +11,7 @@ class StorageViewer {
constructor (_context, _storageResolver, _traceManager) { constructor (_context, _storageResolver, _traceManager) {
this.context = _context this.context = _context
this.storageResolver = _storageResolver this.storageResolver = _storageResolver
this.completeMapingsLocationPromise = null
_traceManager.accumulateStorageChanges(this.context.stepIndex, this.context.address, {}, (error, storageChanges) => { _traceManager.accumulateStorageChanges(this.context.stepIndex, this.context.address, {}, (error, storageChanges) => {
if (!error) { if (!error) {
this.storageChanges = storageChanges this.storageChanges = storageChanges
@ -71,30 +72,33 @@ class StorageViewer {
* @param {Function} callback * @param {Function} callback
*/ */
async mappingsLocation () { async mappingsLocation () {
return new Promise((resolve, reject) => { if (!this.completeMapingsLocationPromise) {
if (this.completeMappingsLocation) { this.completeMapingsLocationPromise = new Promise((resolve, reject) => {
return resolve(this.completeMappingsLocation) if (this.completeMappingsLocation) {
} return this.completeMappingsLocation
this.storageResolver.initialPreimagesMappings(this.context.tx, this.context.stepIndex, this.context.address, (error, initialMappingsLocation) => {
if (error) {
reject(error)
} else {
this.extractMappingsLocationChanges(this.storageChanges, (error, mappingsLocationChanges) => {
if (error) {
return reject(error)
}
this.completeMappingsLocation = Object.assign({}, initialMappingsLocation)
for (var key in mappingsLocationChanges) {
if (!initialMappingsLocation[key]) {
initialMappingsLocation[key] = {}
}
this.completeMappingsLocation[key] = Object.assign({}, initialMappingsLocation[key], mappingsLocationChanges[key])
}
resolve(this.completeMappingsLocation)
})
} }
this.storageResolver.initialPreimagesMappings(this.context.tx, this.context.stepIndex, this.context.address, (error, initialMappingsLocation) => {
if (error) {
reject(error)
} else {
this.extractMappingsLocationChanges(this.storageChanges, (error, mappingsLocationChanges) => {
if (error) {
return reject(error)
}
this.completeMappingsLocation = Object.assign({}, initialMappingsLocation)
for (var key in mappingsLocationChanges) {
if (!initialMappingsLocation[key]) {
initialMappingsLocation[key] = {}
}
this.completeMappingsLocation[key] = Object.assign({}, initialMappingsLocation[key], mappingsLocationChanges[key])
}
resolve(this.completeMappingsLocation)
})
}
})
}) })
}) }
return this.completeMapingsLocationPromise
} }
/** /**

Loading…
Cancel
Save