Commit 1b8a723d authored by Alex Beregszaszi's avatar Alex Beregszaszi

Use async.waterfall in runTx

parent 7ff0654b
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"test": "node test/index.js" "test": "node test/index.js"
}, },
"devDependencies": { "devDependencies": {
"async": "^2.1.2",
"babel-cli": "^6.16.0", "babel-cli": "^6.16.0",
"babel-plugin-transform-es2015-block-scoping": "^6.15.0", "babel-plugin-transform-es2015-block-scoping": "^6.15.0",
"babel-plugin-transform-es2015-template-literals": "^6.8.0", "babel-plugin-transform-es2015-template-literals": "^6.8.0",
......
...@@ -9,6 +9,7 @@ var EthJSBlock = require('ethereumjs-block') ...@@ -9,6 +9,7 @@ var EthJSBlock = require('ethereumjs-block')
var BN = ethJSUtil.BN var BN = ethJSUtil.BN
var EventManager = require('./lib/eventManager') var EventManager = require('./lib/eventManager')
var crypto = require('crypto') var crypto = require('crypto')
var async = require('async')
/* /*
trigger debugRequested trigger debugRequested
...@@ -679,41 +680,61 @@ function tryTillResponse (web3, txhash, done) { ...@@ -679,41 +680,61 @@ function tryTillResponse (web3, txhash, done) {
UniversalDApp.prototype.runTx = function (args, cb) { UniversalDApp.prototype.runTx = function (args, cb) {
var self = this var self = this
var tx = {
var gasLimit = 3000000 to: args.to,
if (self.getGasLimit) { data: args.data
try {
gasLimit = self.getGasLimit()
} catch (e) {
return cb(e)
}
} }
var value = 0 async.waterfall([
if (self.getValue) { // query gas limit
try { function (callback) {
value = self.getValue() tx.gasLimit = 3000000
} catch (e) {
return cb(e)
}
}
var from // NOTE: getGasLimit should be async
if (self.getAddress) { if (self.getGasLimit) {
from = self.getAddress() try {
} else if (self.executionContext.isVM()) { tx.gasLimit = self.getGasLimit()
from = Object.keys(self.accounts)[0] callback()
} else { } catch (e) {
from = self.web3.eth.accounts[0] callback(e)
} }
} else {
callback()
}
},
// query value
function (callback) {
tx.value = 0
return this.rawRunTx({ // NOTE: getValue should be async
from: args.from, if (self.getValue) {
to: args.to, try {
data: args.data, tx.value = self.getValue()
value: value, callback()
gasLimit: gasLimit } catch (e) {
}, cb) callback(e)
}
} else {
callback()
}
},
// query address
function (callback) {
// NOTE: getAddress should be async
if (self.getAddress) {
tx.from = self.getAddress()
} else if (self.executionContext.isVM()) {
tx.from = Object.keys(self.accounts)[0]
} else {
tx.from = self.web3.eth.accounts[0]
}
callback()
},
// run transaction
function (callback) {
self.rawRunTx(tx, callback)
}
], cb)
} }
UniversalDApp.prototype.rawRunTx = function (args, cb) { UniversalDApp.prototype.rawRunTx = function (args, cb) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment