fixed contract.js

This commit is contained in:
Marek Kotewicz 2015-01-22 15:18:21 +01:00
parent 0202b05a5d
commit e45db42e94
4 changed files with 43 additions and 39 deletions

38
dist/ethereum.js vendored
View File

@ -456,12 +456,24 @@ var abi = require('./abi');
* @returns contract object * @returns contract object
*/ */
var contract = function contract (address, desc) { var contract = function (address, desc) {
var inputParser = abi.inputParser(desc); var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc); var outputParser = abi.outputParser(desc);
var result = {}; var result = {};
result.call = function (options) {
result._isTransact = false;
result._options = options;
return result;
};
result.transact = function (options) {
result._isTransact = true;
result._options = options;
return result;
};
desc.forEach(function (method) { desc.forEach(function (method) {
var displayName = abi.methodDisplayName(method.name); var displayName = abi.methodDisplayName(method.name);
@ -472,12 +484,12 @@ var contract = function contract (address, desc) {
var signature = abi.methodSignature(method.name); var signature = abi.methodSignature(method.name);
var parsed = inputParser[displayName][typeName].apply(null, params); var parsed = inputParser[displayName][typeName].apply(null, params);
var options = contract._options || {}; var options = result._options || {};
options.to = address; options.to = address;
options.data = signature + parsed; options.data = signature + parsed;
var output = ""; var output = "";
if (contract._isTransact) { if (result._isTransact) {
// it's used byt natspec.js // it's used byt natspec.js
// TODO: figure out better way to solve this // TODO: figure out better way to solve this
web3._currentContractAbi = desc; web3._currentContractAbi = desc;
@ -488,6 +500,10 @@ var contract = function contract (address, desc) {
output = web3.eth.call(options); output = web3.eth.call(options);
} }
// reset
result._options = {};
result._isTransact = false;
return outputParser[displayName][typeName](output); return outputParser[displayName][typeName](output);
}; };
@ -498,24 +514,10 @@ var contract = function contract (address, desc) {
result[displayName][typeName] = impl; result[displayName][typeName] = impl;
}); });
return result; return result;
}; };
var transact = function (options) {
contract._isTransact = true;
contract._options = options;
return contract;
};
var call = function (options) {
contract._isTransact = false;
contract._options = options;
return contract;
};
contract.transact = transact;
contract.call = call;
module.exports = contract; module.exports = contract;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -45,12 +45,24 @@ var abi = require('./abi');
* @returns contract object * @returns contract object
*/ */
var contract = function contract (address, desc) { var contract = function (address, desc) {
var inputParser = abi.inputParser(desc); var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc); var outputParser = abi.outputParser(desc);
var result = {}; var result = {};
result.call = function (options) {
result._isTransact = false;
result._options = options;
return result;
};
result.transact = function (options) {
result._isTransact = true;
result._options = options;
return result;
};
desc.forEach(function (method) { desc.forEach(function (method) {
var displayName = abi.methodDisplayName(method.name); var displayName = abi.methodDisplayName(method.name);
@ -61,12 +73,12 @@ var contract = function contract (address, desc) {
var signature = abi.methodSignature(method.name); var signature = abi.methodSignature(method.name);
var parsed = inputParser[displayName][typeName].apply(null, params); var parsed = inputParser[displayName][typeName].apply(null, params);
var options = contract._options || {}; var options = result._options || {};
options.to = address; options.to = address;
options.data = signature + parsed; options.data = signature + parsed;
var output = ""; var output = "";
if (contract._isTransact) { if (result._isTransact) {
// it's used byt natspec.js // it's used byt natspec.js
// TODO: figure out better way to solve this // TODO: figure out better way to solve this
web3._currentContractAbi = desc; web3._currentContractAbi = desc;
@ -77,6 +89,10 @@ var contract = function contract (address, desc) {
output = web3.eth.call(options); output = web3.eth.call(options);
} }
// reset
result._options = {};
result._isTransact = false;
return outputParser[displayName][typeName](output); return outputParser[displayName][typeName](output);
}; };
@ -87,23 +103,9 @@ var contract = function contract (address, desc) {
result[displayName][typeName] = impl; result[displayName][typeName] = impl;
}); });
return result; return result;
}; };
var transact = function (options) {
contract._isTransact = true;
contract._options = options;
return contract;
};
var call = function (options) {
contract._isTransact = false;
contract._options = options;
return contract;
};
contract.transact = transact;
contract.call = call;
module.exports = contract; module.exports = contract;