diff --git a/src/trace/traceRetriever.js b/src/trace/traceRetriever.js index 2dba22cc5b..9e74975580 100644 --- a/src/trace/traceRetriever.js +++ b/src/trace/traceRetriever.js @@ -21,9 +21,16 @@ TraceRetriever.prototype.getStorage = function (tx, address, callback) { if (traceHelper.isContractCreation(address)) { callback(null, {}) } else { - util.web3.debug.storageAt(null, tx.hash, address, function (error, result) { - callback(error, result) - }) + if (util.web3.debug.storageRangeAt) { + var maxLength = 100000 + // 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' + (maxLength - 1).toString(16), maxLength, function (error, result) { + callback(error, result.storage) + }) + } else { + callback('no storageRangeAt endpoint found') + } } } diff --git a/src/util/web3Admin.js b/src/util/web3Admin.js index e0d98da6f4..e324e5e631 100644 --- a/src/util/web3Admin.js +++ b/src/util/web3Admin.js @@ -1,6 +1,9 @@ 'use strict' module.exports = { extend: function (web3) { + if (!web3._extend) { + return + } // DEBUG var methods = [] if (!(web3.debug && web3.debug.traceTransaction)) { @@ -12,12 +15,12 @@ module.exports = { })) } - if (!(web3.debug && web3.debug.storageAt)) { + if (!(web3.debug && web3.debug.storageRangeAt)) { methods.push(new web3._extend.Method({ - name: 'storageAt', - call: 'debug_storageAt', - inputFormatter: [null, null, null], - params: 3 + name: 'storageRangeAt', + call: 'debug_storageRangeAt', + inputFormatter: [null, null, null, null, null, null], + params: 6 })) } if (methods.length > 0) { diff --git a/src/web3Provider/dummyProvider.js b/src/web3Provider/dummyProvider.js index 57738c6438..5a898b0600 100644 --- a/src/web3Provider/dummyProvider.js +++ b/src/web3Provider/dummyProvider.js @@ -7,7 +7,7 @@ function dummyProvider () { this.eth.getTransactionFromBlock = function (blockNumber, txIndex, cb) { return self.getTransactionFromBlock(blockNumber, txIndex, cb) } this.eth.getBlockNumber = function (cb) { return self.getBlockNumber(cb) } this.debug.traceTransaction = function (hash, options, cb) { return self.traceTransaction(hash, options, cb) } - this.debug.storageAt = function (blockNumber, txIndex, address, cb) { return self.storageAt(blockNumber, txIndex, address, cb) } + this.debug.storageRangeAt = function (blockNumber, txIndex, address, start, end, maxLength, cb) { return self.storageRangeAt(blockNumber, txIndex, address, start, end, maxLength, cb) } this.providers = { 'HttpProvider': function (url) {} } this.currentProvider = {'host': ''} } @@ -25,7 +25,7 @@ dummyProvider.prototype.traceTransaction = function (txHash, options, cb) { return {} } -dummyProvider.prototype.storageAt = function (blockNumber, txIndex, address, cb) { cb(null, {}) } +dummyProvider.prototype.storageRangeAt = function (blockNumber, txIndex, address, start, end, maxLength, cb) { cb(null, {}) } dummyProvider.prototype.getBlockNumber = function (cb) { cb(null, '') } diff --git a/src/web3Provider/web3VmProvider.js b/src/web3Provider/web3VmProvider.js index e640a03842..c84d6e2fe3 100644 --- a/src/web3Provider/web3VmProvider.js +++ b/src/web3Provider/web3VmProvider.js @@ -17,7 +17,7 @@ function web3VmProvider () { this.eth.getTransactionFromBlock = function (blockNumber, txIndex, cb) { return self.getTransactionFromBlock(blockNumber, txIndex, cb) } this.eth.getBlockNumber = function (cb) { return self.getBlockNumber(cb) } this.debug.traceTransaction = function (hash, options, cb) { return self.traceTransaction(hash, options, cb) } - this.debug.storageAt = function (blockNumber, txIndex, address, cb) { return self.storageAt(blockNumber, txIndex, address, cb) } + this.debug.storageRangeAt = function (blockNumber, txIndex, address, start, end, maxLength, cb) { return self.storageRangeAt(blockNumber, txIndex, address, start, end, maxLength, cb) } this.providers = { 'HttpProvider': function (url) {} } this.currentProvider = {'host': 'vm provider'} this.storageCache = {} @@ -127,10 +127,14 @@ web3VmProvider.prototype.traceTransaction = function (txHash, options, cb) { } } -web3VmProvider.prototype.storageAt = function (blockNumber, txIndex, address, cb) { // txIndex is the hash in the case of the VM +web3VmProvider.prototype.storageRangeAt = function (blockNumber, txIndex, address, start, end, maxLength, cb) { // txIndex is the hash in the case of the VM + // we don't use the range params here if (this.storageCache[txIndex] && this.storageCache[txIndex][address]) { var storage = this.storageCache[txIndex][address] - return cb(null, JSON.parse(JSON.stringify(storage))) // copy creation... + return cb(null, { + storage: JSON.parse(JSON.stringify(storage)), // copy + complete: true + }) } else { cb('unable to retrieve storage ' + txIndex + ' ' + address) }