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) {
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)
......
......@@ -690,14 +690,15 @@ UniversalDApp.prototype.runTx = function (args, cb) {
function (callback) {
tx.gasLimit = 3000000
// NOTE: getGasLimit should be async
if (self.getGasLimit) {
try {
tx.gasLimit = self.getGasLimit()
self.getGasLimit(function (err, ret) {
if (err) {
return callback(err)
}
tx.gasLimit = ret
callback()
} catch (e) {
callback(e)
}
})
} else {
callback()
}
......@@ -706,24 +707,30 @@ UniversalDApp.prototype.runTx = function (args, cb) {
function (callback) {
tx.value = 0
// NOTE: getValue should be async
if (self.getValue) {
try {
tx.value = self.getValue()
self.getValue(function (err, ret) {
if (err) {
return callback(err)
}
tx.value = ret
callback()
} catch (e) {
callback(e)
}
})
} else {
callback()
}
},
// query address
function (callback) {
// NOTE: getAddress should be async
if (self.getAddress) {
tx.from = self.getAddress()
callback()
self.getAddress(function (err, ret) {
if (err) {
return callback(err)
}
tx.from = ret
callback()
})
} else {
self.getAccounts(function (err, ret) {
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