Commit 14258792 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Make getValue/getGasLimit/getAddress async

parent 3974f9aa
...@@ -113,14 +113,22 @@ Renderer.prototype.contracts = function (data, source) { ...@@ -113,14 +113,22 @@ Renderer.prototype.contracts = function (data, source) {
return source.sources[currentFile] return source.sources[currentFile]
} }
var getAddress = function () { return $('#txorigin').val() } var getAddress = function (cb) {
cb(null, $('#txorigin').val())
}
var getValue = function () { var getValue = function (cb) {
try {
var comp = $('#value').val().split(' ') var comp = $('#value').val().split(' ')
return self.executionContext.web3().toWei(comp[0], comp.slice(1).join(' ')) 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) this.udapp.reset(udappContracts, getAddress, getValue, getGasLimit, renderOutputModifier)
......
...@@ -690,14 +690,15 @@ UniversalDApp.prototype.runTx = function (args, cb) { ...@@ -690,14 +690,15 @@ UniversalDApp.prototype.runTx = function (args, cb) {
function (callback) { function (callback) {
tx.gasLimit = 3000000 tx.gasLimit = 3000000
// NOTE: getGasLimit should be async
if (self.getGasLimit) { if (self.getGasLimit) {
try { self.getGasLimit(function (err, ret) {
tx.gasLimit = self.getGasLimit() if (err) {
callback() return callback(err)
} catch (e) {
callback(e)
} }
tx.gasLimit = ret
callback()
})
} else { } else {
callback() callback()
} }
...@@ -706,24 +707,30 @@ UniversalDApp.prototype.runTx = function (args, cb) { ...@@ -706,24 +707,30 @@ UniversalDApp.prototype.runTx = function (args, cb) {
function (callback) { function (callback) {
tx.value = 0 tx.value = 0
// NOTE: getValue should be async
if (self.getValue) { if (self.getValue) {
try { self.getValue(function (err, ret) {
tx.value = self.getValue() if (err) {
callback() return callback(err)
} catch (e) {
callback(e)
} }
tx.value = ret
callback()
})
} else { } else {
callback() callback()
} }
}, },
// query address // query address
function (callback) { function (callback) {
// NOTE: getAddress should be async
if (self.getAddress) { if (self.getAddress) {
tx.from = self.getAddress() self.getAddress(function (err, ret) {
if (err) {
return callback(err)
}
tx.from = ret
callback() callback()
})
} else { } else {
self.getAccounts(function (err, ret) { self.getAccounts(function (err, ret) {
if (err) { if (err) {
......
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