|
|
|
@ -26,7 +26,9 @@ class StorageResolver { |
|
|
|
|
* @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value} |
|
|
|
|
*/ |
|
|
|
|
storageRange (tx, stepIndex, address, callback) { |
|
|
|
|
this.storageRangeInternal(this, this.zeroSlot, tx, stepIndex, address, callback) |
|
|
|
|
this.storageRangeInternal(this, this.zeroSlot, tx, stepIndex, address).then((result) => { |
|
|
|
|
callback(null, result) |
|
|
|
|
}).catch(callback) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -63,13 +65,9 @@ class StorageResolver { |
|
|
|
|
* @param {Function} - callback - {key, hashedKey, value} - |
|
|
|
|
*/ |
|
|
|
|
storageSlot (slot, tx, stepIndex, address, callback) { |
|
|
|
|
this.storageRangeInternal(this, slot, tx, stepIndex, address, (error, storage) => { |
|
|
|
|
if (error) { |
|
|
|
|
callback(error) |
|
|
|
|
} else { |
|
|
|
|
callback(null, storage[slot] !== undefined ? storage[slot] : null) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
this.storageRangeInternal(this, slot, tx, stepIndex, address).then((storage) => { |
|
|
|
|
callback(null, storage[slot] !== undefined ? storage[slot] : null) |
|
|
|
|
}).catch(callback) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -88,26 +86,28 @@ 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. |
|
|
|
|
*/ |
|
|
|
|
storageRangeInternal (self, slotKey, tx, stepIndex, address, callback) { |
|
|
|
|
var cached = this.fromCache(self, address) |
|
|
|
|
if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000...
|
|
|
|
|
return callback(null, cached.storage) |
|
|
|
|
} |
|
|
|
|
this.storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, nextKey) => { |
|
|
|
|
if (error) { |
|
|
|
|
return callback(error) |
|
|
|
|
storageRangeInternal (self, slotKey, tx, stepIndex, address) { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
var cached = this.fromCache(self, address) |
|
|
|
|
if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000...
|
|
|
|
|
return resolve(cached.storage) |
|
|
|
|
} |
|
|
|
|
if (!storage[slotKey] && slotKey !== self.zeroSlot) { // we don't cache the zero slot (could lead to inconsistency)
|
|
|
|
|
storage[slotKey] = { |
|
|
|
|
key: slotKey, |
|
|
|
|
value: self.zeroSlot |
|
|
|
|
this.storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, nextKey) => { |
|
|
|
|
if (error) { |
|
|
|
|
return reject(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
self.toCache(self, address, storage) |
|
|
|
|
if (slotKey === self.zeroSlot && !nextKey) { // only working if keys are sorted !!
|
|
|
|
|
self.storageByAddress[address].complete = true |
|
|
|
|
} |
|
|
|
|
callback(null, storage) |
|
|
|
|
if (!storage[slotKey] && slotKey !== self.zeroSlot) { // we don't cache the zero slot (could lead to inconsistency)
|
|
|
|
|
storage[slotKey] = { |
|
|
|
|
key: slotKey, |
|
|
|
|
value: self.zeroSlot |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
self.toCache(self, address, storage) |
|
|
|
|
if (slotKey === self.zeroSlot && !nextKey) { // only working if keys are sorted !!
|
|
|
|
|
self.storageByAddress[address].complete = true |
|
|
|
|
} |
|
|
|
|
return resolve(storage) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|