Merge pull request #287 from ethereum/runtx-split

Split runTx (and make settings async)
pull/1/head
yann300 8 years ago committed by GitHub
commit 21d1a5db2d
  1. 1
      package.json
  2. 18
      src/app/renderer.js
  3. 105
      src/universal-dapp.js

@ -17,6 +17,7 @@
"test": "node test/index.js"
},
"devDependencies": {
"async": "^2.1.2",
"babel-cli": "^6.16.0",
"babel-plugin-transform-es2015-block-scoping": "^6.15.0",
"babel-plugin-transform-es2015-template-literals": "^6.8.0",

@ -113,14 +113,22 @@ Renderer.prototype.contracts = function (data, source) {
return source.sources[currentFile]
}
var getAddress = function () { return $('#txorigin').val() }
var getAddress = function (cb) {
cb(null, $('#txorigin').val())
}
var getValue = function () {
var comp = $('#value').val().split(' ')
return self.executionContext.web3().toWei(comp[0], comp.slice(1).join(' '))
var getValue = function (cb) {
try {
var comp = $('#value').val().split(' ')
cb(null, self.executionContext.web3().toWei(comp[0], comp.slice(1).join(' ')))
} catch (e) {
cb(e)
}
}
var getGasLimit = function () { return $('#gasLimit').val() }
var getGasLimit = function (cb) {
cb(null, $('#gasLimit').val())
}
this.udapp.reset(udappContracts, getAddress, getValue, getGasLimit, renderOutputModifier)

@ -9,6 +9,7 @@ var EthJSBlock = require('ethereumjs-block')
var BN = ethJSUtil.BN
var EventManager = require('./lib/eventManager')
var crypto = require('crypto')
var async = require('async')
/*
trigger debugRequested
@ -679,34 +680,94 @@ function tryTillResponse (web3, txhash, done) {
UniversalDApp.prototype.runTx = function (args, cb) {
var self = this
var to = args.to
var data = args.data
if (data.slice(0, 2) !== '0x') {
data = '0x' + data
var tx = {
to: args.to,
data: args.data
}
var gasLimit = 3000000
if (self.getGasLimit) {
try {
gasLimit = self.getGasLimit()
} catch (e) {
return cb(e)
}
}
async.waterfall([
// query gas limit
function (callback) {
tx.gasLimit = 3000000
var value = 0
if (self.getValue) {
try {
value = self.getValue()
} catch (e) {
return cb(e)
if (self.getGasLimit) {
self.getGasLimit(function (err, ret) {
if (err) {
return callback(err)
}
tx.gasLimit = ret
callback()
})
} else {
callback()
}
},
// query value
function (callback) {
tx.value = 0
if (self.getValue) {
self.getValue(function (err, ret) {
if (err) {
return callback(err)
}
tx.value = ret
callback()
})
} else {
callback()
}
},
// query address
function (callback) {
if (self.getAddress) {
self.getAddress(function (err, ret) {
if (err) {
return callback(err)
}
tx.from = ret
callback()
})
} else {
self.getAccounts(function (err, ret) {
if (err) {
return callback(err)
}
if (ret.length === 0) {
return callback('No accounts available')
}
tx.from = ret[0]
callback()
})
}
},
// run transaction
function (callback) {
self.rawRunTx(tx, callback)
}
], cb)
}
UniversalDApp.prototype.rawRunTx = function (args, cb) {
var self = this
var from = args.from
var to = args.to
var data = args.data
if (data.slice(0, 2) !== '0x') {
data = '0x' + data
}
var value = args.value
var gasLimit = args.gasLimit
var tx
if (!self.executionContext.isVM()) {
tx = {
from: self.getAddress ? self.getAddress() : self.web3.eth.accounts[0],
from: from,
to: to,
data: data,
value: value
@ -739,8 +800,10 @@ UniversalDApp.prototype.runTx = function (args, cb) {
}
} else {
try {
var address = self.getAddress ? self.getAddress() : Object.keys(self.accounts)[0]
var account = self.accounts[address]
var account = self.accounts[from]
if (!account) {
return cb('Invalid account selected')
}
tx = new EthJSTX({
nonce: new BN(account.nonce++),
gasPrice: new BN(1),

Loading…
Cancel
Save