few methods moved to utils

This commit is contained in:
Marek Kotewicz
2015-01-31 15:22:05 +01:00
parent a8a2e3231c
commit b20e972bec
9 changed files with 154 additions and 154 deletions

View File

@ -22,8 +22,18 @@
var web3 = require('./web3');
var abi = require('./abi');
var utils = require('./utils');
var eventImpl = require('./event');
var exportNatspecGlobals = function (vars) {
// it's used byt natspec.js
// TODO: figure out better way to solve this
web3._currentContractAbi = vars.abi;
web3._currentContractAddress = vars.address;
web3._currentContractMethodName = vars.method;
web3._currentContractMethodParams = vars.params;
};
var addFunctionRelatedPropertiesToContract = function (contract) {
contract.call = function (options) {
@ -53,14 +63,14 @@ var addFunctionsToContract = function (contract, desc, address) {
var outputParser = abi.outputParser(desc);
// create contract functions
abi.filterFunctions(desc).forEach(function (method) {
utils.filterFunctions(desc).forEach(function (method) {
var displayName = abi.methodDisplayName(method.name);
var typeName = abi.methodTypeName(method.name);
var displayName = utils.extractDisplayName(method.name);
var typeName = utils.extractTypeName(method.name);
var impl = function () {
var params = Array.prototype.slice.call(arguments);
var signature = abi.methodSignature(method.name);
var signature = abi.signatureFromAscii(method.name);
var parsed = inputParser[displayName][typeName].apply(null, params);
var options = contract._options || {};
@ -75,12 +85,13 @@ var addFunctionsToContract = function (contract, desc, address) {
contract._isTransact = null;
if (isTransact) {
// it's used byt natspec.js
// TODO: figure out better way to solve this
web3._currentContractAbi = desc;
web3._currentContractAddress = address;
web3._currentContractMethodName = method.name;
web3._currentContractMethodParams = params;
exportNatspecGlobals({
abi: desc,
address: address,
method: method.name,
params: params
});
// transactions do not have any output, cause we do not know, when they will be processed
web3.eth.transact(options);
@ -112,8 +123,8 @@ var addEventRelatedPropertiesToContract = function (contract, desc, address) {
Object.defineProperty(contract, 'topic', {
get: function() {
return abi.filterEvents(desc).map(function (e) {
return abi.methodSignature(e.name);
return utils.filterEvents(desc).map(function (e) {
return abi.signatureFromAscii(e.name);
});
}
});
@ -122,11 +133,11 @@ var addEventRelatedPropertiesToContract = function (contract, desc, address) {
var addEventsToContract = function (contract, desc, address) {
// create contract events
abi.filterEvents(desc).forEach(function (e) {
utils.filterEvents(desc).forEach(function (e) {
var impl = function () {
var params = Array.prototype.slice.call(arguments);
var signature = abi.methodSignature(e.name);
var signature = abi.signatureFromAscii(e.name);
var event = eventImpl(address, signature, e);
var o = event.apply(null, params);
return web3.eth.watch(o);
@ -135,18 +146,8 @@ var addEventsToContract = function (contract, desc, address) {
// this property should be used by eth.filter to check if object is an event
impl._isEvent = true;
// TODO: we can remove address && topic properties, they are not used anymore since we introduced _isEvent
impl.address = address;
Object.defineProperty(impl, 'topic', {
get: function() {
return [abi.methodSignature(e.name)];
}
});
// TODO: rename these methods, cause they are used not only for methods
var displayName = abi.methodDisplayName(e.name);
var typeName = abi.methodTypeName(e.name);
var displayName = utils.extractDisplayName(e.name);
var typeName = utils.extractTypeName(e.name);
if (contract[displayName] === undefined) {
contract[displayName] = impl;