Commit d5e39845 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Ensure runTx always returns details about the transaction and not the tx hash in…

Ensure runTx always returns details about the transaction and not the tx hash in web3 mode (i.e. move tryTillResponse into runTx)
parent c9f4197f
...@@ -347,7 +347,7 @@ UniversalDApp.prototype.getCallButton = function (args) { ...@@ -347,7 +347,7 @@ UniversalDApp.prototype.getCallButton = function (args) {
gas = result.gasUsed.toString(10); gas = result.gasUsed.toString(10);
$gasUsed.html('<strong>Transaction cost:</strong> ' + gas + ' gas. ' + caveat); $gasUsed.html('<strong>Transaction cost:</strong> ' + gas + ' gas. ' + caveat);
} }
if (vmResult.gasUsed) { if (vmResult && vmResult.gasUsed) {
var $callGasUsed = $('<div class="gasUsed">'); var $callGasUsed = $('<div class="gasUsed">');
gas = vmResult.gasUsed.toString(10); gas = vmResult.gasUsed.toString(10);
$callGasUsed.append('<strong>Execution cost:</strong> ' + gas + ' gas.'); $callGasUsed.append('<strong>Execution cost:</strong> ' + gas + ' gas.');
...@@ -439,13 +439,15 @@ UniversalDApp.prototype.getCallButton = function (args) { ...@@ -439,13 +439,15 @@ UniversalDApp.prototype.getCallButton = function (args) {
self.runTx(data, args, function (err, result) { self.runTx(data, args, function (err, result) {
if (err) { if (err) {
replaceOutput($result, $('<span/>').text(err).addClass('error')); replaceOutput($result, $('<span/>').text(err).addClass('error'));
// VM only
} else if (self.options.vm && result.vm.exception && result.vm.exceptionError) { } else if (self.options.vm && result.vm.exception && result.vm.exceptionError) {
replaceOutput($result, $('<span/>').text('VM Exception: ' + result.vm.exceptionError).addClass('error')); replaceOutput($result, $('<span/>').text('VM Exception: ' + result.vm.exceptionError).addClass('error'));
// VM only
} else if (self.options.vm && result.vm.return === undefined) { } else if (self.options.vm && result.vm.return === undefined) {
replaceOutput($result, $('<span/>').text('Exception during execution.').addClass('error')); replaceOutput($result, $('<span/>').text('Exception during execution.').addClass('error'));
} else if (self.options.vm && isConstructor) { } else if (isConstructor) {
replaceOutput($result, getGasUsedOutput(result, result.vm)); replaceOutput($result, getGasUsedOutput(result, result.vm));
args.appendFunctions(result.createdAddress); args.appendFunctions(self.options.vm ? result.createdAddress : result.contractAddress);
} else if (self.options.vm) { } else if (self.options.vm) {
var outputObj = '0x' + result.vm.return.toString('hex'); var outputObj = '0x' + result.vm.return.toString('hex');
clearOutput($result); clearOutput($result);
...@@ -483,19 +485,10 @@ UniversalDApp.prototype.getCallButton = function (args) { ...@@ -483,19 +485,10 @@ UniversalDApp.prototype.getCallButton = function (args) {
} else if (args.abi.constant && !isConstructor) { } else if (args.abi.constant && !isConstructor) {
replaceOutput($result, getReturnOutput(result)); replaceOutput($result, getReturnOutput(result));
} else { } else {
tryTillResponse(self.web3, result, function (err, result) {
if (err) {
replaceOutput($result, $('<span/>').text(err).addClass('error'));
} else if (isConstructor) {
$result.html('');
args.appendFunctions(result.contractAddress);
} else {
clearOutput($result); clearOutput($result);
$result.append(getReturnOutput(result)).append(getGasUsedOutput(result)); $result.append(getReturnOutput(result)).append(getGasUsedOutput(result));
} }
}); });
}
});
}; };
var button = $('<button />') var button = $('<button />')
...@@ -566,16 +559,9 @@ UniversalDApp.prototype.deployLibrary = function (contractName, cb) { ...@@ -566,16 +559,9 @@ UniversalDApp.prototype.deployLibrary = function (contractName, cb) {
if (err) { if (err) {
return cb(err); return cb(err);
} }
if (self.options.vm) { var address = self.options.vm ? result.createdAddress : result.contractAddress;
self.getContractByName(contractName).address = result.createdAddress; self.getContractByName(contractName).address = address;
cb(err, result.createdAddress); cb(err, address);
} else {
tryTillResponse(self.web3, result, function (err, finalResult) {
if (err) return cb(err);
self.getContractByName(contractName).address = finalResult.contractAddress;
cb(null, finalResult.contractAddress);
});
}
}); });
} }
}; };
...@@ -618,12 +604,15 @@ UniversalDApp.prototype.runTx = function (data, args, cb) { ...@@ -618,12 +604,15 @@ UniversalDApp.prototype.runTx = function (data, args, cb) {
this.web3.eth.call(tx, cb); this.web3.eth.call(tx, cb);
} else { } else {
this.web3.eth.estimateGas(tx, function (err, resp) { this.web3.eth.estimateGas(tx, function (err, resp) {
tx.gas = resp; if (err) {
if (!err) { return cb(err, resp);
self.web3.eth.sendTransaction(tx, cb);
} else {
cb(err, resp);
} }
tx.gas = resp;
self.web3.eth.sendTransaction(tx, function (err, resp) {
tryTillResponse(self.web3, resp, cb);
});
}); });
} }
} else { } else {
......
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