mirror of https://github.com/status-im/web3.js.git
Merge branch 'async-contract-calls' of https://github.com/niran/web3.js into contract_overhaul
This commit is contained in:
commit
6afb1f9a56
|
@ -67,21 +67,47 @@ SolidityFunction.prototype.signature = function () {
|
||||||
return web3.sha3(web3.fromAscii(this._name)).slice(2, 10);
|
return web3.sha3(web3.fromAscii(this._name)).slice(2, 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to call function
|
SolidityFunction.prototype.unpackOutput = function (output) {
|
||||||
*
|
if (output == null) {
|
||||||
* @method call
|
return;
|
||||||
* @param {Object} options
|
}
|
||||||
* @return {String} output bytes
|
|
||||||
*/
|
|
||||||
SolidityFunction.prototype.call = function () {
|
|
||||||
var payload = this.toPayload.apply(this, Array.prototype.slice.call(arguments));
|
|
||||||
var output = web3.eth.call(payload);
|
|
||||||
output = output.length >= 2 ? output.slice(2) : output;
|
output = output.length >= 2 ? output.slice(2) : output;
|
||||||
var result = coder.decodeParams(this._outputTypes, output);
|
var result = coder.decodeParams(this._outputTypes, output);
|
||||||
return result.length === 1 ? result[0] : result;
|
return result.length === 1 ? result[0] : result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls a contract function.
|
||||||
|
*
|
||||||
|
* @method call
|
||||||
|
* @param {...Object} Contract function arguments
|
||||||
|
* @param {function} If the last argument is a function, the contract function
|
||||||
|
* call will be asynchronous, and the callback will be passed the
|
||||||
|
* error and result.
|
||||||
|
* @return {String} output bytes
|
||||||
|
*/
|
||||||
|
SolidityFunction.prototype.call = function () {
|
||||||
|
var this_ = this;
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
var callback;
|
||||||
|
if (typeof(args[args.length - 1]) === 'function') {
|
||||||
|
callback = args.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = this.toPayload.apply(this, args);
|
||||||
|
|
||||||
|
if (typeof(callback) === 'undefined') {
|
||||||
|
var output = web3.eth.call(payload, callback);
|
||||||
|
return this.unpackOutput(output);
|
||||||
|
} else {
|
||||||
|
web3.eth.call(payload, function (error, output) {
|
||||||
|
callback(error, this_.unpackOutput(output));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used to sendTransaction to solidity function
|
* Should be used to sendTransaction to solidity function
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue