run tx synced way if javascript vm

pull/1/head
yann300 7 years ago
parent b7b09951e3
commit be1093af1f
  1. 12
      src/app/execution/txRunner.js
  2. 2
      src/universal-dapp.js

@ -6,14 +6,16 @@ var BN = ethJSUtil.BN
var executionContext = require('../../execution-context') var executionContext = require('../../execution-context')
function TxRunner (vmaccounts, opts) { function TxRunner (vmaccounts, opts) {
this.queueTxs = opts.queueTxs
this.personalMode = opts.personalMode this.personalMode = opts.personalMode
this.blockNumber = 0 this.blockNumber = 0
this.runAsync = true
if (executionContext.isVM()) { if (executionContext.isVM()) {
this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block.
this.runAsync = false
} }
this.pendingTxs = {} this.pendingTxs = {}
this.vmaccounts = vmaccounts this.vmaccounts = vmaccounts
this.queusTxs = []
} }
TxRunner.prototype.rawRun = function (args, cb) { TxRunner.prototype.rawRun = function (args, cb) {
@ -147,11 +149,19 @@ function tryTillResponse (txhash, done) {
} }
function run (self, tx, stamp, callback) { function run (self, tx, stamp, callback) {
if (!self.runAsync && Object.keys(self.pendingTxs).length) {
self.queusTxs.push({ tx, stamp, callback })
} else {
self.pendingTxs[stamp] = tx self.pendingTxs[stamp] = tx
self.execute(tx, (error, result) => { self.execute(tx, (error, result) => {
delete self.pendingTxs[stamp] delete self.pendingTxs[stamp]
callback(error, result) callback(error, result)
if (Object.keys(self.pendingTxs).length) {
var next = self.pendingTxs.pop()
run(self, next.tx, next.stamp, next.callback)
}
}) })
}
} }
module.exports = TxRunner module.exports = TxRunner

@ -172,7 +172,6 @@ function UniversalDApp (opts = {}) {
self.reset(self.contracts) self.reset(self.contracts)
}) })
self.txRunner = new TxRunner({}, { self.txRunner = new TxRunner({}, {
queueTxs: true,
personalMode: this.personalMode personalMode: this.personalMode
}) })
} }
@ -193,7 +192,6 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) {
executionContext.vm().stateManager.cache.flush(function () {}) executionContext.vm().stateManager.cache.flush(function () {})
} }
this.txRunner = new TxRunner(this.accounts, { this.txRunner = new TxRunner(this.accounts, {
queueTxs: true,
personalMode: this.personalMode personalMode: this.personalMode
}) })
} }

Loading…
Cancel
Save