use ES6 class

pull/1/head
yann300 8 years ago
parent 4d79298d86
commit 8cc2a861e6
  1. 47
      src/app/execution-context.js

@ -21,30 +21,37 @@ if (typeof window.web3 !== 'undefined') {
/* /*
extend vm state manager and instanciate VM extend vm state manager and instanciate VM
*/ */
var stateManager = new StateManager({})
stateManager.keyHashes = {}
var base = stateManager.putContractStorage
stateManager.putContractStorage = function (address, key, value, cb) {
stateManager.keyHashes[ethUtil.sha3(key)] = ethUtil.bufferToHex(key)
base.apply(stateManager, [address, key, value, cb])
}
stateManager.dumpStorage = function (address, cb) { class StateManagerCommonStorageDump extends StateManager {
stateManager._getStorageTrie(address, function (err, trie) { constructor (arg) {
if (err) { super(arg)
return cb(err) this.keyHashes = {}
} }
var storage = {}
var stream = trie.createReadStream() putContractStorage (address, key, value, cb) {
stream.on('data', function (val) { this.keyHashes[ethUtil.sha3(key)] = ethUtil.bufferToHex(key)
storage[stateManager.keyHashes[val.key]] = val.value.toString('hex') super.putContractStorage(address, key, value, cb)
}) }
stream.on('end', function () {
cb(storage) dumpStorage (address, cb) {
var self = this
this._getStorageTrie(address, function (err, trie) {
if (err) {
return cb(err)
}
var storage = {}
var stream = trie.createReadStream()
stream.on('data', function (val) {
storage[self.keyHashes[val.key]] = val.value.toString('hex')
})
stream.on('end', function () {
cb(storage)
})
}) })
}) }
} }
var stateManager = new StateManagerCommonStorageDump({})
var vm = new EthJSVM({ var vm = new EthJSVM({
enableHomestead: true, enableHomestead: true,
activatePrecompiles: true activatePrecompiles: true

Loading…
Cancel
Save