Commit 00f41bf2 authored by Alex Beregszaszi's avatar Alex Beregszaszi

UDapp: decode constant responses in web3 mode

parent e7b581de
...@@ -447,23 +447,7 @@ UniversalDApp.prototype.getCallButton = function (args) { ...@@ -447,23 +447,7 @@ UniversalDApp.prototype.getCallButton = function (args) {
} }
} }
self.runTx(data, args, function (err, result) { var decodeResponse = function (response) {
if (err) {
replaceOutput($result, $('<span/>').text(err).addClass('error'));
// VM only
} else if (self.options.vm && result.vm.exception && result.vm.exceptionError) {
replaceOutput($result, $('<span/>').text('VM Exception: ' + result.vm.exceptionError).addClass('error'));
// VM only
} else if (self.options.vm && result.vm.return === undefined) {
replaceOutput($result, $('<span/>').text('Exception during execution.').addClass('error'));
} else if (isConstructor) {
replaceOutput($result, getGasUsedOutput(result, result.vm));
args.appendFunctions(self.options.vm ? result.createdAddress : result.contractAddress);
} else if (self.options.vm) {
var outputObj = '0x' + result.vm.return.toString('hex');
clearOutput($result);
$result.append(getReturnOutput(outputObj)).append(getGasUsedOutput(result, result.vm));
// Only decode if there supposed to be fields // Only decode if there supposed to be fields
if (args.abi.outputs.length > 0) { if (args.abi.outputs.length > 0) {
try { try {
...@@ -475,7 +459,7 @@ UniversalDApp.prototype.getCallButton = function (args) { ...@@ -475,7 +459,7 @@ UniversalDApp.prototype.getCallButton = function (args) {
} }
// decode data // decode data
var decodedObj = ethJSABI.rawDecode(outputTypes, result.vm.return); var decodedObj = ethJSABI.rawDecode(outputTypes, response);
// format decoded data // format decoded data
decodedObj = ethJSABI.stringify(outputTypes, decodedObj); decodedObj = ethJSABI.stringify(outputTypes, decodedObj);
...@@ -488,13 +472,43 @@ UniversalDApp.prototype.getCallButton = function (args) { ...@@ -488,13 +472,43 @@ UniversalDApp.prototype.getCallButton = function (args) {
} }
} }
$result.append(getDecodedOutput(decodedObj)); return getDecodedOutput(decodedObj);
} catch (e) { } catch (e) {
$result.append(getDecodedOutput('Failed to decode output: ' + e)); return getDecodedOutput('Failed to decode output: ' + e);
} }
} }
};
var decoded;
self.runTx(data, args, function (err, result) {
if (err) {
replaceOutput($result, $('<span/>').text(err).addClass('error'));
// VM only
} else if (self.options.vm && result.vm.exception && result.vm.exceptionError) {
replaceOutput($result, $('<span/>').text('VM Exception: ' + result.vm.exceptionError).addClass('error'));
// VM only
} else if (self.options.vm && result.vm.return === undefined) {
replaceOutput($result, $('<span/>').text('Exception during execution.').addClass('error'));
} else if (isConstructor) {
replaceOutput($result, getGasUsedOutput(result, result.vm));
args.appendFunctions(self.options.vm ? result.createdAddress : result.contractAddress);
} else if (self.options.vm) {
var outputObj = '0x' + result.vm.return.toString('hex');
clearOutput($result);
$result.append(getReturnOutput(outputObj)).append(getGasUsedOutput(result, result.vm));
decoded = decodeResponse(result.vm.return);
if (decoded) {
$result.append(decoded);
}
} else if (args.abi.constant && !isConstructor) { } else if (args.abi.constant && !isConstructor) {
replaceOutput($result, getReturnOutput(result)); clearOutput($result);
$result.append(getReturnOutput(result)).append(getGasUsedOutput({}));
decoded = decodeResponse(ethJSUtil.toBuffer(result));
if (decoded) {
$result.append(decoded);
}
} else { } else {
clearOutput($result); clearOutput($result);
$result.append(getReturnOutput(result)).append(getGasUsedOutput(result)); $result.append(getReturnOutput(result)).append(getGasUsedOutput(result));
......
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