track last known transaction for an address

pull/7/head
Iuri Matias 5 years ago
parent c3f24090bd
commit a1d4be80ce
  1. 9
      remix-lib/src/web3Provider/web3VmProvider.js

@ -29,6 +29,7 @@ function web3VmProvider () {
this.providers = { 'HttpProvider': function (url) {} } this.providers = { 'HttpProvider': function (url) {} }
this.currentProvider = {'host': 'vm provider'} this.currentProvider = {'host': 'vm provider'}
this.storageCache = {} this.storageCache = {}
this.lastProcessedStorageTxHash = {}
this.sha3Preimages = {} this.sha3Preimages = {}
// util // util
this.sha3 = function () { return self.web3.sha3.apply(self.web3, arguments) } this.sha3 = function () { return self.web3.sha3.apply(self.web3, arguments) }
@ -92,6 +93,7 @@ web3VmProvider.prototype.txWillProcess = function (self, data) {
const account = ethutil.toBuffer(tx.to) const account = ethutil.toBuffer(tx.to)
self.vm.stateManager.dumpStorage(account, function (storage) { self.vm.stateManager.dumpStorage(account, function (storage) {
self.storageCache[self.processingHash][tx.to] = storage self.storageCache[self.processingHash][tx.to] = storage
self.lastProcessedStorageTxHash[tx.to] = self.processingHash
}) })
} }
this.processingIndex = 0 this.processingIndex = 0
@ -171,12 +173,14 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
if (step.op === 'CREATE') { if (step.op === 'CREATE') {
this.processingAddress = traceHelper.contractCreationToken(this.processingIndex) this.processingAddress = traceHelper.contractCreationToken(this.processingIndex)
this.storageCache[this.processingHash][this.processingAddress] = {} this.storageCache[this.processingHash][this.processingAddress] = {}
this.lastProcessedStorageTxHash[this.processingAddress] = this.processingHash
} else { } else {
this.processingAddress = uiutil.normalizeHexAddress(step.stack[step.stack.length - 2]) this.processingAddress = uiutil.normalizeHexAddress(step.stack[step.stack.length - 2])
if (!self.storageCache[self.processingHash][this.processingAddress]) { if (!self.storageCache[self.processingHash][this.processingAddress]) {
const account = ethutil.toBuffer(this.processingAddress) const account = ethutil.toBuffer(this.processingAddress)
self.vm.stateManager.dumpStorage(account, function (storage) { self.vm.stateManager.dumpStorage(account, function (storage) {
self.storageCache[self.processingHash][self.processingAddress] = storage self.storageCache[self.processingHash][self.processingAddress] = storage
self.lastProcessedStorageTxHash[self.processingAddress] = self.processingHash
}) })
} }
} }
@ -217,6 +221,11 @@ web3VmProvider.prototype.traceTransaction = function (txHash, options, cb) {
web3VmProvider.prototype.storageRangeAt = function (blockNumber, txIndex, address, start, maxLength, cb) { // txIndex is the hash in the case of the VM web3VmProvider.prototype.storageRangeAt = function (blockNumber, txIndex, address, start, maxLength, cb) { // txIndex is the hash in the case of the VM
// we don't use the range params here // we don't use the range params here
if (txIndex === 'latest') {
txIndex = this.lastProcessedStorageTxHash[address]
}
if (this.storageCache[txIndex] && this.storageCache[txIndex][address]) { if (this.storageCache[txIndex] && this.storageCache[txIndex][address]) {
var storage = this.storageCache[txIndex][address] var storage = this.storageCache[txIndex][address]
return cb(null, { return cb(null, {

Loading…
Cancel
Save