From 31c1a5f09a6c7a2f046d013665c263ae46501de3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 18 Apr 2017 16:16:11 +0200 Subject: [PATCH] move storageRanges to the viewer --- src/storage/storageResolver.js | 19 +++++++------------ src/storage/storageViewer.js | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/storage/storageResolver.js b/src/storage/storageResolver.js index d4ecd04222..4d1521f055 100644 --- a/src/storage/storageResolver.js +++ b/src/storage/storageResolver.js @@ -14,12 +14,11 @@ class StorageResolver { * * @param {Object} - tx - transaction * @param {Int} - stepIndex - Index of the stop in the vm trace - * @param {Object} - storageChanges - contains storage changes by hashde key * @param {String} - address - lookup address * @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value} */ - storageRange (tx, stepIndex, storageChanges, address, callback) { - storageRangeInternal(this, zeroSlot, tx, stepIndex, true, storageChanges, address, callback) + storageRange (tx, stepIndex, address, callback) { + storageRangeInternal(this, zeroSlot, tx, stepIndex, address, callback) } /** @@ -28,12 +27,11 @@ class StorageResolver { * @param {String} - slot - slot key * @param {Object} - tx - transaction * @param {Int} - stepIndex - Index of the stop in the vm trace - * @param {Object} - storageChanges - contains storage changes by hashde key * @param {String} - address - lookup address * @param {Function} - callback - {key, hashedKey, value} - */ - storageSlot (slot, tx, stepIndex, storageChanges, address, callback) { - storageRangeInternal(this, slot, tx, stepIndex, false, storageChanges, address, function (error, storage) { + storageSlot (slot, tx, stepIndex, address, callback) { + storageRangeInternal(this, slot, tx, stepIndex, address, function (error, storage) { if (error) { callback(error) } else { @@ -59,13 +57,10 @@ class StorageResolver { * even if the next 1000 items are not in the cache. * - If @arg slot is not cached, the corresponding value will be resolved and the next 1000 slots. */ -function storageRangeInternal (self, slotKey, tx, stepIndex, fullStorage, storageChanges, address, callback) { - if (!fullStorage && storageChanges[slotKey]) { // don't need the full storage just returning the value from the storageChanges - return callback(null, storageChanges) - } +function storageRangeInternal (self, slotKey, tx, stepIndex, address, callback) { var cached = fromCache(self, address) if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000... - return callback(null, Object.assign({}, cached.storage, storageChanges)) + return callback(null, cached.storage) } storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, complete) => { if (error) { @@ -81,7 +76,7 @@ function storageRangeInternal (self, slotKey, tx, stepIndex, fullStorage, storag if (slotKey === zeroSlot && Object.keys(storage).length < self.maxSize) { // only working if keys are sorted !! self.storageByAddress[address].complete = true } - callback(null, Object.assign(storage, storageChanges)) + callback(null, storage) }) } diff --git a/src/storage/storageViewer.js b/src/storage/storageViewer.js index 1252276d38..472ce20603 100644 --- a/src/storage/storageViewer.js +++ b/src/storage/storageViewer.js @@ -21,7 +21,13 @@ class StorageViewer { * @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value} */ storageRange (callback) { - this.storageResolver.storageRange(this.context.tx, this.context.stepIndex, this.storageChanges, this.context.address, 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)) + } + }) } /** @@ -31,11 +37,14 @@ class StorageViewer { */ storageSlot (slot, callback) { var hashed = helper.sha3_256(slot) - this.storageResolver.storageSlot(hashed, this.context.tx, this.context.stepIndex, this.storageChanges, this.context.address, (error, result) => { + if (this.storageChanges[hashed]) { + return callback(null, this.storageChanges[hashed]) + } + this.storageResolver.storageSlot(hashed, this.context.tx, this.context.stepIndex, this.context.address, (error, storage) => { if (error) { callback(error) } else { - callback(null, result) + callback(null, storage[hashed] !== undefined ? storage[hashed] : null) } }) }