call && sendTransaction

This commit is contained in:
Marek Kotewicz 2015-04-21 20:06:44 +02:00
parent f84a68cb73
commit d411492649
7 changed files with 98 additions and 53 deletions

45
dist/web3-light.js vendored
View File

@ -2607,6 +2607,24 @@ var SolidityFunction = function (json, address) {
this._address = address;
};
/**
* Should be used to create payload from arguments
*
* @method toPayload
* @param {...} solidity function params
* @param {Object} optional payload options
*/
SolidityFunction.prototype.toPayload = function () {
var args = Array.prototype.slice.call(arguments);
var options = {};
if (utils.isObject(args[args.length -1])) {
options = args.pop();
}
options.to = this._address;
options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
return options;
};
/**
* Should be used to get function signature
*
@ -2624,8 +2642,10 @@ SolidityFunction.prototype.signature = function () {
* @param {Object} options
* @return {String} output bytes
*/
SolidityFunction.prototype.call = function (options) {
return web3.eth.call(options);
SolidityFunction.prototype.call = function () {
var payload = this.toPayload.apply(this, Array.prototype.slice.call(arguments));
var output = web3.eth.call(payload);
return coder.decodeParams(this._outputTypes, output);
};
/**
@ -2634,8 +2654,9 @@ SolidityFunction.prototype.call = function (options) {
* @method sendTransaction
* @param {Object} options
*/
SolidityFunction.prototype.sendTransaction = function (options) {
web3.eth.sendTransaction(options);
SolidityFunction.prototype.sendTransaction = function () {
var payload = this.toPayload.apply(this, Array.prototype.slice.call(arguments));
web3.eth.sendTransaction(payload);
};
/**
@ -2664,23 +2685,15 @@ SolidityFunction.prototype.typeName = function () {
* @method execute
*/
SolidityFunction.prototype.execute = function () {
var args = Array.prototype.slice.call(arguments);
var options = {};
if (utils.isObject(args[args.length -1])) {
options = args.pop();
}
options.to = this._address;
options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
var transaction = !this._constant;
// send transaction
if (transaction) {
return this.sendTransaction(options);
return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
}
// call
var output = this.call(options);
return coder.decodeParams(this._outputTypes, output);
return this.call.apply(this, Array.prototype.slice.call(arguments));
};
/**
@ -2691,11 +2704,13 @@ SolidityFunction.prototype.execute = function () {
*/
SolidityFunction.prototype.attachToContract = function (contract) {
var execute = this.execute.bind(this);
execute.call = this.call.bind(this);
execute.sendTransaction = this.sendTransaction.bind(this);
var displayName = this.displayName();
if (!contract[displayName]) {
contract[displayName] = execute;
}
contract[displayName][this.typeName()] = this.execute.bind(this);
contract[displayName][this.typeName()] = execute; // circular!!!!
};
module.exports = SolidityFunction;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

45
dist/web3.js vendored
View File

@ -2607,6 +2607,24 @@ var SolidityFunction = function (json, address) {
this._address = address;
};
/**
* Should be used to create payload from arguments
*
* @method toPayload
* @param {...} solidity function params
* @param {Object} optional payload options
*/
SolidityFunction.prototype.toPayload = function () {
var args = Array.prototype.slice.call(arguments);
var options = {};
if (utils.isObject(args[args.length -1])) {
options = args.pop();
}
options.to = this._address;
options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
return options;
};
/**
* Should be used to get function signature
*
@ -2624,8 +2642,10 @@ SolidityFunction.prototype.signature = function () {
* @param {Object} options
* @return {String} output bytes
*/
SolidityFunction.prototype.call = function (options) {
return web3.eth.call(options);
SolidityFunction.prototype.call = function () {
var payload = this.toPayload.apply(this, Array.prototype.slice.call(arguments));
var output = web3.eth.call(payload);
return coder.decodeParams(this._outputTypes, output);
};
/**
@ -2634,8 +2654,9 @@ SolidityFunction.prototype.call = function (options) {
* @method sendTransaction
* @param {Object} options
*/
SolidityFunction.prototype.sendTransaction = function (options) {
web3.eth.sendTransaction(options);
SolidityFunction.prototype.sendTransaction = function () {
var payload = this.toPayload.apply(this, Array.prototype.slice.call(arguments));
web3.eth.sendTransaction(payload);
};
/**
@ -2664,23 +2685,15 @@ SolidityFunction.prototype.typeName = function () {
* @method execute
*/
SolidityFunction.prototype.execute = function () {
var args = Array.prototype.slice.call(arguments);
var options = {};
if (utils.isObject(args[args.length -1])) {
options = args.pop();
}
options.to = this._address;
options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
var transaction = !this._constant;
// send transaction
if (transaction) {
return this.sendTransaction(options);
return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
}
// call
var output = this.call(options);
return coder.decodeParams(this._outputTypes, output);
return this.call.apply(this, Array.prototype.slice.call(arguments));
};
/**
@ -2691,11 +2704,13 @@ SolidityFunction.prototype.execute = function () {
*/
SolidityFunction.prototype.attachToContract = function (contract) {
var execute = this.execute.bind(this);
execute.call = this.call.bind(this);
execute.sendTransaction = this.sendTransaction.bind(this);
var displayName = this.displayName();
if (!contract[displayName]) {
contract[displayName] = execute;
}
contract[displayName][this.typeName()] = this.execute.bind(this);
contract[displayName][this.typeName()] = execute; // circular!!!!
};
module.exports = SolidityFunction;

4
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

4
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -39,6 +39,24 @@ var SolidityFunction = function (json, address) {
this._address = address;
};
/**
* Should be used to create payload from arguments
*
* @method toPayload
* @param {...} solidity function params
* @param {Object} optional payload options
*/
SolidityFunction.prototype.toPayload = function () {
var args = Array.prototype.slice.call(arguments);
var options = {};
if (utils.isObject(args[args.length -1])) {
options = args.pop();
}
options.to = this._address;
options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
return options;
};
/**
* Should be used to get function signature
*
@ -56,8 +74,10 @@ SolidityFunction.prototype.signature = function () {
* @param {Object} options
* @return {String} output bytes
*/
SolidityFunction.prototype.call = function (options) {
return web3.eth.call(options);
SolidityFunction.prototype.call = function () {
var payload = this.toPayload.apply(this, Array.prototype.slice.call(arguments));
var output = web3.eth.call(payload);
return coder.decodeParams(this._outputTypes, output);
};
/**
@ -66,8 +86,9 @@ SolidityFunction.prototype.call = function (options) {
* @method sendTransaction
* @param {Object} options
*/
SolidityFunction.prototype.sendTransaction = function (options) {
web3.eth.sendTransaction(options);
SolidityFunction.prototype.sendTransaction = function () {
var payload = this.toPayload.apply(this, Array.prototype.slice.call(arguments));
web3.eth.sendTransaction(payload);
};
/**
@ -96,23 +117,15 @@ SolidityFunction.prototype.typeName = function () {
* @method execute
*/
SolidityFunction.prototype.execute = function () {
var args = Array.prototype.slice.call(arguments);
var options = {};
if (utils.isObject(args[args.length -1])) {
options = args.pop();
}
options.to = this._address;
options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
var transaction = !this._constant;
// send transaction
if (transaction) {
return this.sendTransaction(options);
return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
}
// call
var output = this.call(options);
return coder.decodeParams(this._outputTypes, output);
return this.call.apply(this, Array.prototype.slice.call(arguments));
};
/**
@ -123,11 +136,13 @@ SolidityFunction.prototype.execute = function () {
*/
SolidityFunction.prototype.attachToContract = function (contract) {
var execute = this.execute.bind(this);
execute.call = this.call.bind(this);
execute.sendTransaction = this.sendTransaction.bind(this);
var displayName = this.displayName();
if (!contract[displayName]) {
contract[displayName] = execute;
}
contract[displayName][this.typeName()] = this.execute.bind(this);
contract[displayName][this.typeName()] = execute; // circular!!!!
};
module.exports = SolidityFunction;