change to getStorageAt => resolveStorage

pull/7/head
yann300 8 years ago
parent 1c4e2d3b27
commit 9004162563
  1. 18
      src/trace/traceCache.js
  2. 27
      src/trace/traceManager.js
  3. 29
      src/trace/traceRetriever.js

@ -1,4 +1,6 @@
'use strict' 'use strict'
var helper = require('../helpers/util')
function TraceCache () { function TraceCache () {
this.init() this.init()
} }
@ -84,23 +86,29 @@ TraceCache.prototype.pushStoreChanges = function (index, address, key, value) {
this.sstore[index] = { this.sstore[index] = {
'address': address, 'address': address,
'key': key, 'key': key,
'value': value 'value': value,
'hashedKey': helper.sha3(key)
} }
this.storageChanges.push(index) this.storageChanges.push(index)
} }
TraceCache.prototype.rebuildStorage = function (address, storage, index) { TraceCache.prototype.resolveStorage = function (index, address, storage) {
var ret = Object.assign({}, storage)
for (var k in this.storageChanges) { for (var k in this.storageChanges) {
var changesIndex = this.storageChanges[k] var changesIndex = this.storageChanges[k]
if (changesIndex > index) { if (changesIndex > index) {
return storage return ret
} }
var sstore = this.sstore[changesIndex] var sstore = this.sstore[changesIndex]
if (sstore.address === address && sstore.key) { if (sstore.address === address && sstore.key) {
storage[sstore.key] = sstore.value ret[sstore.hashedKey] = {
hashedKey: sstore.hashedKey,
key: sstore.key,
value: sstore.value
}
} }
} }
return storage return ret
} }
module.exports = TraceCache module.exports = TraceCache

@ -74,30 +74,9 @@ TraceManager.prototype.getLength = function (callback) {
} }
} }
TraceManager.prototype.getStorageAt = function (stepIndex, tx, callback, address) { TraceManager.prototype.resolveStorage = function (index, address, storageOrigin, callback) {
var check = this.checkRequestedStep(stepIndex) var storage = this.traceCache.resolveStorage(index, address, storageOrigin)
if (check) { callback(null, storage)
return callback(check, null)
}
if (!address) {
var stoChange = util.findLowerBoundValue(stepIndex, this.traceCache.storageChanges)
if (stoChange === null) return callback('no storage found', null)
address = this.traceCache.sstore[stoChange].address
}
var self = this
if (this.traceRetriever.debugStorageAtAvailable()) {
this.traceRetriever.getStorage(tx, address, function (error, result) {
if (error) {
// TODO throws proper error when debug_storageRangeAt will be available
console.log(error)
result = {}
}
var storage = self.traceCache.rebuildStorage(address, result, stepIndex)
callback(null, storage)
})
} else {
callback(null, this.trace[stoChange].storage)
}
} }
TraceManager.prototype.getAddresses = function (callback) { TraceManager.prototype.getAddresses = function (callback) {

@ -1,5 +1,4 @@
'use strict' 'use strict'
var traceHelper = require('../helpers/traceHelper')
var util = require('../helpers/global') var util = require('../helpers/global')
function TraceRetriever () { function TraceRetriever () {
@ -17,32 +16,4 @@ TraceRetriever.prototype.getTrace = function (txHash, callback) {
}) })
} }
TraceRetriever.prototype.getStorage = function (tx, address, callback) {
if (traceHelper.isContractCreation(address)) {
callback(null, {})
} else {
if (util.web3.debug.storageRangeAt) {
var end = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
var maxSize = 10000
// The VM gives only a tx hash
// TODO: get rid of that and use the range parameters
util.web3.debug.storageRangeAt(tx.blockHash, tx.transactionIndex === undefined ? tx.hash : tx.transactionIndex, address, '0x0', '0x' + end, maxSize, function (error, result) {
if (error) {
callback(error)
} else if (result.storage) {
callback(null, result.storage)
} else {
callback('storage has not been provided')
}
})
} else {
callback('no storageRangeAt endpoint found')
}
}
}
TraceRetriever.prototype.debugStorageAtAvailable = function () {
return true
}
module.exports = TraceRetriever module.exports = TraceRetriever

Loading…
Cancel
Save