move storageRanges to the viewer

pull/7/head
yann300 8 years ago
parent 427801ec55
commit 31c1a5f09a
  1. 19
      src/storage/storageResolver.js
  2. 15
      src/storage/storageViewer.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)
})
}

@ -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)
}
})
}

Loading…
Cancel
Save