Merge pull request #341 from ethereum/fixweb3SendTx

Fix send tx through web3
pull/1/head
yann300 8 years ago committed by GitHub
commit f65bd7fccf
  1. 11
      src/app/txRunner.js
  2. 26
      src/universal-dapp.js

@ -4,7 +4,7 @@ var EthJSBlock = require('ethereumjs-block')
var ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN
function TxRunner (executionContext, opts) {
function TxRunner (executionContext, vmaccounts, opts) {
this.executionContext = executionContext
this.web3 = executionContext.web3()
this.vm = executionContext.vm()
@ -16,6 +16,7 @@ function TxRunner (executionContext, opts) {
}
this.running = false
this.pendingTxs = []
this.vmaccounts = vmaccounts
}
TxRunner.prototype.rawRun = function (args, cb) {
@ -83,15 +84,19 @@ TxRunner.prototype.execute = function () {
}
} else {
try {
var account = self.vmaccounts[from]
if (!account) {
return cb('Invalid account selected')
}
tx = new EthJSTX({
nonce: new BN(from.nonce++),
nonce: new BN(account.nonce++),
gasPrice: new BN(1),
gasLimit: new BN(gasLimit, 10),
to: to,
value: new BN(value, 10),
data: new Buffer(data.slice(2), 'hex')
})
tx.sign(from.privateKey)
tx.sign(account.privateKey)
var block = new EthJSBlock({
header: {
// FIXME: support coinbase, difficulty and gasLimit

@ -33,18 +33,14 @@ function UniversalDApp (executionContext, options, txdebugger) {
self.executionContext.event.register('contextChanged', this, function (context) {
self.reset(self.contracts)
})
self.txRunner = new TxRunner(executionContext, {
self.txRunner = new TxRunner(executionContext, {}, {
queueTxs: true,
personalMode: true
personalMode: this.personalMode
})
}
UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGasLimit, renderer) {
this.$el.empty()
this.txRunner = new TxRunner(this.executionContext, {
queueTxs: true,
personalMode: true
})
this.contracts = contracts
this.getAddress = getAddress
this.getValue = getValue
@ -58,6 +54,10 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa
this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea')
this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce')
}
this.txRunner = new TxRunner(this.executionContext, this.accounts, {
queueTxs: true,
personalMode: this.personalMode
})
}
UniversalDApp.prototype.newAccount = function (password) {
@ -549,6 +549,10 @@ UniversalDApp.prototype.getCallButton = function (args) {
var decoded
self.runTx({ to: args.address, data: data, useCall: args.abi.constant && !isConstructor }, function (err, txResult) {
if (!txResult) {
replaceOutput($result, $('<span/>').text('callback contain no result ' + err).addClass('error'))
return
}
var result = txResult.result
if (err) {
replaceOutput($result, $('<span/>').text(err).addClass('error'))
@ -681,7 +685,6 @@ UniversalDApp.prototype.runTx = function (args, cb) {
data: args.data,
useCall: args.useCall
}
var accounts = this.accounts
async.waterfall([
// query gas limit
function (callback) {
@ -725,7 +728,8 @@ UniversalDApp.prototype.runTx = function (args, cb) {
return callback(err)
}
tx.from = accounts[ret]
tx.from = ret
callback()
})
} else {
@ -738,10 +742,12 @@ UniversalDApp.prototype.runTx = function (args, cb) {
return callback('No accounts available')
}
tx.from = accounts[ret[0]]
if (self.executionContext.isVM() && !self.accounts[tx.from]) {
if (self.executionContext.isVM() && !self.accounts[ret[0]]) {
return callback('Invalid account selected')
}
tx.from = ret[0]
callback()
})
}

Loading…
Cancel
Save